Issue #20270: urllib and urlparse now support empty ports.
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 244cb05..ac5d797 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -1125,10 +1125,13 @@
global _portprog
if _portprog is None:
import re
- _portprog = re.compile('^(.*):([0-9]+)$')
+ _portprog = re.compile('^(.*):([0-9]*)$')
match = _portprog.match(host)
- if match: return match.group(1, 2)
+ if match:
+ host, port = match.groups()
+ if port:
+ return host, port
return host, None
_nportprog = None
@@ -1145,12 +1148,12 @@
match = _nportprog.match(host)
if match:
host, port = match.group(1, 2)
- try:
- if not port: raise ValueError, "no digits"
- nport = int(port)
- except ValueError:
- nport = None
- return host, nport
+ if port:
+ try:
+ nport = int(port)
+ except ValueError:
+ nport = None
+ return host, nport
return host, defport
_queryprog = None