summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-06-17 17:11:40 (GMT)
committerGuido van Rossum <guido@python.org>1996-06-17 17:11:40 (GMT)
commit84a00a80a26c4a7d7b7056a01ada32cb611bbc76 (patch)
tree35c944911eb0dae329aa24d790f407107dbcdc64 /Lib
parent4e15599daac23ecb38abb5de69cf01a89a32b107 (diff)
downloadcpython-84a00a80a26c4a7d7b7056a01ada32cb611bbc76.zip
cpython-84a00a80a26c4a7d7b7056a01ada32cb611bbc76.tar.gz
cpython-84a00a80a26c4a7d7b7056a01ada32cb611bbc76.tar.bz2
Change defn of splitnport() to only accept valid digit strings.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 45f3e99..a8228eb 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -598,18 +598,17 @@ def splitport(host):
# Split host and port, returning numeric port.
# Return given default port if no ':' found; defaults to -1.
-# Return numerical port if digits are found after ':'.
-# Return None if ':' but no digits.
-_nportprog = regex.compile('^\(.*\):\([^0-9]*\([0-9]*\).*\)$')
+# Return numerical port if a valid number are found after ':'.
+# Return None if ':' but not a valid number.
+_nportprog = regex.compile('^\(.*\):\(.*\)$')
def splitnport(host, defport=-1):
if _nportprog.match(host) >= 0:
- host, port = _nportprog.group(1, 3)
- nport = None
- if port:
- try:
- nport = string.atoi(port)
- except string.atoi_error:
- pass
+ host, port = _nportprog.group(1, 2)
+ try:
+ if not port: raise string.atoi_error, "no digits"
+ nport = string.atoi(port)
+ except string.atoi_error:
+ nport = None
return host, nport
return host, defport