This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients orsenthil, serhiy.storchaka
Date 2014-01-15.12:26:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1389788785.56.0.178405230158.issue20270@psf.upfronthosting.co.za>
In-reply-to
Content
According to RFC 3986 the port subcomponent is defined as zero or more decimal digits delimited from the host by a single colon. I.e. 'python.org:' is valid (but not normalized) form. Empty port is equivalent to absent port.

>>> import urllib.parse
>>> p = urllib.parse.urlparse('http://python.org:')
>>> p.hostname
'python.org'
>>> p.port  # should return None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython-3.3/Lib/urllib/parse.py", line 156, in port
    port = int(port, 10)
ValueError: invalid literal for int() with base 10: ''
>>> urllib.parse.splitport('python.org:')  # should return ('python.org', None)
('python.org:', None)
>>> urllib.parse.splitnport('python.org:')  # should return ('python.org', -1)
('python.org', None)
>>> urllib.parse.splitnport('python.org:', 80)  # should return ('python.org', 80)
('python.org', None)

Proposed patch fixes this. It also adds tests for urllib.parse.splitport().
History
Date User Action Args
2014-01-15 12:26:25serhiy.storchakasetrecipients: + serhiy.storchaka, orsenthil
2014-01-15 12:26:25serhiy.storchakasetmessageid: <1389788785.56.0.178405230158.issue20270@psf.upfronthosting.co.za>
2014-01-15 12:26:25serhiy.storchakalinkissue20270 messages
2014-01-15 12:26:25serhiy.storchakacreate