From: Skip Montanaro Date: Sun, 24 Mar 2002 16:53:50 +0000 (+0000) Subject: add InvalidURL exception - raised if port is given but empty or non-numeric X-Git-Tag: v2.3c1~6363 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d38997e8c4d06ec5717276590a3f1c6a88d2bb7;p=python add InvalidURL exception - raised if port is given but empty or non-numeric --- diff --git a/Lib/httplib.py b/Lib/httplib.py index 4bad4638a4..ce819ebfbf 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -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