[issue33480] Improvement suggestions for urllib.parse.urlparser

R. David Murray report at bugs.python.org
Sun May 13 17:58:35 EDT 2018


R. David Murray <rdmurray at bitdance.com> added the comment:

These are actually reasonable requests, and in fact have been brought up before and implemented:

>>> x = urlparse('http://me:mypass@example.com:800/foo;key1=value1?key2=value2#key3=value3#key4=value4')
>>> x
ParseResult(scheme='http', netloc='me:mypass at example.com:800', path='/foo', params='key1=value1', query='key2=value2', fragment='key3=value3#key4=value4')
>>> x.hostname
'example.com'
>>> x.port
800
>>> x.username
'me'
>>> x.password
'mypass'
>>> x._asdict()
OrderedDict([('scheme', 'http'), ('netloc', 'me:mypass at example.com:800'), ('path', '/foo'), ('params', 'key1=value1'), ('query', 'key2=value2'), ('fragment', 'key3=value3#key4=value4')])


Now, what this doesn't get you is the "extra" fields that are not part of the base tuple.  The base tuple has the members it does for backward compatibility.  So, the thing to discuss on python-ideas would be an API for namedtuple that gets you the extra fields.

None versus the empty string is not something that can happen, for backward compatibility reasons, even if there was agreement that it was better.

I'm not entirely sure why dict(x) is not supported (but I suspect it is because x is "a tuple", again for backward compatibility reasons), so you might search the archives to find out why for sure, if you  are curious.

----------
nosy: +r.david.murray
resolution:  -> out of date
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33480>
_______________________________________


More information about the Python-bugs-list mailing list