diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-18 16:31:41 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-01-18 16:31:41 (GMT) |
commit | 5d83d1a8141fa248356e4825857f166e4e65ec16 (patch) | |
tree | 91b9be2407ee79c3d7f422f77528ec38c495ffc8 /Lib/urllib/parse.py | |
parent | 2d1f0924691a214bbe6360233566b0c6241fbc47 (diff) | |
parent | ff97b08d0022392da23a25aa5ccb04e6a2966e8b (diff) | |
download | cpython-5d83d1a8141fa248356e4825857f166e4e65ec16.zip cpython-5d83d1a8141fa248356e4825857f166e4e65ec16.tar.gz cpython-5d83d1a8141fa248356e4825857f166e4e65ec16.tar.bz2 |
Issue #20270: urllib.urlparse now supports empty ports.
Diffstat (limited to 'Lib/urllib/parse.py')
-rw-r--r-- | Lib/urllib/parse.py | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/Lib/urllib/parse.py b/Lib/urllib/parse.py index 5328b9d..2ba3991 100644 --- a/Lib/urllib/parse.py +++ b/Lib/urllib/parse.py @@ -182,10 +182,10 @@ class _NetlocResultMixinStr(_NetlocResultMixinBase, _ResultMixinStr): _, have_open_br, bracketed = hostinfo.partition('[') if have_open_br: hostname, _, port = bracketed.partition(']') - _, have_port, port = port.partition(':') + _, _, port = port.partition(':') else: - hostname, have_port, port = hostinfo.partition(':') - if not have_port: + hostname, _, port = hostinfo.partition(':') + if not port: port = None return hostname, port @@ -212,10 +212,10 @@ class _NetlocResultMixinBytes(_NetlocResultMixinBase, _ResultMixinBytes): _, have_open_br, bracketed = hostinfo.partition(b'[') if have_open_br: hostname, _, port = bracketed.partition(b']') - _, have_port, port = port.partition(b':') + _, _, port = port.partition(b':') else: - hostname, have_port, port = hostinfo.partition(b':') - if not have_port: + hostname, _, port = hostinfo.partition(b':') + if not port: port = None return hostname, port @@ -898,10 +898,13 @@ def splitport(host): """splitport('host:port') --> 'host', 'port'.""" global _portprog if _portprog is None: - _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 @@ -917,12 +920,12 @@ def splitnport(host, defport=-1): 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 |