]> granicus.if.org Git - python/commitdiff
Search from the end of the host/port combination to find the colon which
authorSkip Montanaro <skip@pobox.com>
Tue, 14 Sep 2004 16:32:02 +0000 (16:32 +0000)
committerSkip Montanaro <skip@pobox.com>
Tue, 14 Sep 2004 16:32:02 +0000 (16:32 +0000)
separates ip address from the port to accommodate ipv6 addresses.

Lib/httplib.py
Lib/test/test_httplib.py

index a4102eac5f16805c144f452afdcb7ba27150b878..2f117d8d5d54744a158307bb0e3f2021eccb9f30 100644 (file)
@@ -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:])
index 5f252bb52f2ceafc8643d78d2b7ba12e7b6f7e6c..b49f71d2e33c0857cb634b9a6952465ceb72d29d 100644 (file)
@@ -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'