]> granicus.if.org Git - python/commitdiff
add InvalidURL exception - raised if port is given but empty or non-numeric
authorSkip Montanaro <skip@pobox.com>
Sun, 24 Mar 2002 16:53:50 +0000 (16:53 +0000)
committerSkip Montanaro <skip@pobox.com>
Sun, 24 Mar 2002 16:53:50 +0000 (16:53 +0000)
Lib/httplib.py

index 4bad4638a44ac9c4a636175e2658c1ff1e0b4371..ce819ebfbfd0c9de6466121d3e1d73264e1498a6 100644 (file)
@@ -347,7 +347,10 @@ class HTTPConnection:
         if port is None:
             i = host.find(':')
             if i >= 0:
-                port = int(host[i+1:])
+                try:
+                    port = int(host[i+1:])
+                except ValueError:
+                    raise InvalidURL, "nonnumeric port: '%s'"%host[i+1:]
                 host = host[:i]
             else:
                 port = self.default_port
@@ -808,6 +811,9 @@ class HTTPException(Exception):
 class NotConnected(HTTPException):
     pass
 
+class InvalidURL(HTTPException):
+    pass
+
 class UnknownProtocol(HTTPException):
     def __init__(self, version):
         self.version = version