diff options
| author | Martin v. Löwis <martin@v.loewis.de> | 2004-09-14 21:45:36 +0000 |
|---|---|---|
| committer | Martin v. Löwis <martin@v.loewis.de> | 2004-09-14 21:45:36 +0000 |
| commit | 74a249e1a9424c6055435a855916a580d443189f (patch) | |
| tree | 3c6066441df31db119f8cadb0f574f0c570a6692 | |
| parent | 82d0eecf427ca09f65cfa9a718adfd9e5e7275e8 (diff) | |
| download | cpython-git-74a249e1a9424c6055435a855916a580d443189f.tar.gz | |
Strip square brackets from IPv6 address.
| -rw-r--r-- | Lib/httplib.py | 2 | ||||
| -rw-r--r-- | Lib/test/test_httplib.py | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py index b7276af357..c88b172a36 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -534,6 +534,8 @@ class HTTPConnection: host = host[:i] else: port = self.default_port + if host[0] == '[' and host[-1] == ']': + host = host[1:-1] self.host = host self.port = port diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 046f4f871a..b0d73387e0 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -118,12 +118,17 @@ def _test(): else: print "Expect InvalidURL" - for hp in ("[fe80::207:e9ff:fe9b]:8000", "www.python.org:80", - "www.python.org", "[fe80::207:e9ff:fe9b]"): + for hp,h,p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", 8000), + ("www.python.org:80", "www.python.org", 80), + ("www.python.org", "www.python.org", 80), + ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80)): try: - h = httplib.HTTP(hp) + http = httplib.HTTP(hp) except httplib.InvalidURL: print "InvalidURL raised erroneously" + c = http._conn + if h != c.host: raise AssertionError, ("Host incorrectly parsed", h, c.host) + if p != c.port: raise AssertionError, ("Port incorrectly parsed", p, c.host) # test response with multiple message headers with the same field name. text = ('HTTP/1.1 200 OK\r\n' |
