Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
urllib3's URL parser makes me sad :(
>>> def compare_parse(url):
... from urllib3.util.url import parse_url
... import urlparse
... print "urlparse:", repr(urlparse.urlparse(url))
... print "urllib3:", repr(parse_url(url))
...
>>> compare_parse("//foo:a@google.com/")
urlparse: ParseResult(scheme='', netloc='foo:a@google.com', path='/', params='', query='', fragment='')
urllib3: Url(scheme=None, auth=None, host=None, port=None, path='//foo:a@google.com/', query=None, fragment=None)
>>> compare_parse("//foo/http://a/")
urlparse: ParseResult(scheme='', netloc='foo', path='/http://a/', params='', query='', fragment='')
urllib3: Url(scheme='//foo/http', auth=None, host='a', port=None, path='/', query=None, fragment=None)
>>> compare_parse("////something.com/")
urlparse: ParseResult(scheme='', netloc='', path='//something.com/', params='', query='', fragment='')
urllib3: Url(scheme=None, auth=None, host=None, port=None, path='////something.com/', query=None, fragment=None)
>>> compare_parse("http:baz:80@foo:80//something.com/")
urlparse: ParseResult(scheme='http', netloc='', path='baz:80@foo:80//something.com/', params='', query='', fragment='')
urllib3: Url(scheme=None, auth='http:baz:80', host='foo', port=80, path='//something.com/', query=None, fragment=None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment