From: Skip Montanaro Date: Tue, 14 Sep 2004 16:32:02 +0000 (+0000) Subject: Search from the end of the host/port combination to find the colon which X-Git-Tag: v2.4b1~264 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=10e6e0e61a38d62979fb5270d2e19a235ba32bbe;p=python Search from the end of the host/port combination to find the colon which separates ip address from the port to accommodate ipv6 addresses. --- diff --git a/Lib/httplib.py b/Lib/httplib.py index a4102eac5f..2f117d8d5d 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -524,7 +524,7 @@ class HTTPConnection: def _set_hostport(self, host, port): if port is None: - i = host.find(':') + i = host.rfind(':') if i >= 0: try: port = int(host[i+1:]) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 5f252bb52f..b49f71d2e3 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -118,6 +118,13 @@ def _test(): else: print "Expect InvalidURL" + for hp in ("[fe80::207:e9ff:fe9b]:8000", "www.python.org:80", + "www.python.org"): + try: + h = httplib.HTTP(hp) + except httplib.InvalidURL: + print "InvalidURL raised erroneously" + # test response with multiple message headers with the same field name. text = ('HTTP/1.1 200 OK\r\n' 'Set-Cookie: Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"\r\n'