Change defn of splitnport() to only accept valid digit strings.
This commit is contained in:
parent
4e15599daa
commit
84a00a80a2
|
@ -598,18 +598,17 @@ def splitport(host):
|
||||||
|
|
||||||
# Split host and port, returning numeric port.
|
# Split host and port, returning numeric port.
|
||||||
# Return given default port if no ':' found; defaults to -1.
|
# Return given default port if no ':' found; defaults to -1.
|
||||||
# Return numerical port if digits are found after ':'.
|
# Return numerical port if a valid number are found after ':'.
|
||||||
# Return None if ':' but no digits.
|
# Return None if ':' but not a valid number.
|
||||||
_nportprog = regex.compile('^\(.*\):\([^0-9]*\([0-9]*\).*\)$')
|
_nportprog = regex.compile('^\(.*\):\(.*\)$')
|
||||||
def splitnport(host, defport=-1):
|
def splitnport(host, defport=-1):
|
||||||
if _nportprog.match(host) >= 0:
|
if _nportprog.match(host) >= 0:
|
||||||
host, port = _nportprog.group(1, 3)
|
host, port = _nportprog.group(1, 2)
|
||||||
nport = None
|
try:
|
||||||
if port:
|
if not port: raise string.atoi_error, "no digits"
|
||||||
try:
|
nport = string.atoi(port)
|
||||||
nport = string.atoi(port)
|
except string.atoi_error:
|
||||||
except string.atoi_error:
|
nport = None
|
||||||
pass
|
|
||||||
return host, nport
|
return host, nport
|
||||||
return host, defport
|
return host, defport
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue