]> granicus.if.org Git - python/commitdiff
Change defn of splitnport() to only accept valid digit strings.
authorGuido van Rossum <guido@python.org>
Mon, 17 Jun 1996 17:11:40 +0000 (17:11 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 17 Jun 1996 17:11:40 +0000 (17:11 +0000)
Lib/urllib.py

index 45f3e9959ba5ac88b5f36e5d6e167e0fa7de3941..a8228ebfb4bab2fd8c78b993fde45fe2d10cc958 100644 (file)
@@ -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