Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d38997

Browse files
author
Skip Montanaro
committed
add InvalidURL exception - raised if port is given but empty or non-numeric
1 parent 1ce0073 commit 9d38997

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/httplib.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,10 @@ def _set_hostport(self, host, port):
347347
if port is None:
348348
i = host.find(':')
349349
if i >= 0:
350-
port = int(host[i+1:])
350+
try:
351+
port = int(host[i+1:])
352+
except ValueError:
353+
raise InvalidURL, "nonnumeric port: '%s'"%host[i+1:]
351354
host = host[:i]
352355
else:
353356
port = self.default_port
@@ -808,6 +811,9 @@ class HTTPException(Exception):
808811
class NotConnected(HTTPException):
809812
pass
810813

814+
class InvalidURL(HTTPException):
815+
pass
816+
811817
class UnknownProtocol(HTTPException):
812818
def __init__(self, version):
813819
self.version = version

0 commit comments

Comments
 (0)