3 `=\W@slddlmZddlmZddlmZddddd d d gZdZGdddedeZddZ ddZ ddZ dS))absolute_import) namedtuple)LocationParseErrorschemeauthhostportpathqueryfragmenthttphttpsNcs^eZdZdZfZdfdd ZeddZeddZed d Z ed d Z d dZ Z S)Urlz Datastructure for representing an HTTP URL. Used as a return value for :func:`parse_url`. Both the scheme and host are normalized as they are both case-insensitive according to RFC 3986. Nc sV|r|jd rd|}|r$|j}|r8|tkr8|j}tt|j||||||||S)N/) startswithlowerNORMALIZABLE_SCHEMESsuperr__new__)clsrrrr r r r ) __class__i/private/var/folders/47/550316q90kl84vt_jn5ctz8chwmm0c/T/pip-install-yoigbb1v/urllib3/urllib3/util/url.pyrs z Url.__new__cCs|jS)z@For backwards-compatibility with urlparse. We're nice like that.)r)selfrrrhostname!sz Url.hostnamecCs&|jpd}|jdk r"|d|j7}|S)z)Absolute path including the query string.rN?)r r )rurirrr request_uri&s  zUrl.request_uricCs|jrd|j|jfS|jS)z(Network location including host and portz%s:%d)r r)rrrrnetloc0sz Url.netlocc Cs|\}}}}}}}d}|dk r*||d7}|dk r>||d7}|dk rN||7}|dk rf|dt|7}|dk rv||7}|dk r|d|7}|dk r|d|7}|S)a Convert self into a url This function should more or less round-trip with :func:`.parse_url`. The returned url may not be exactly the same as the url inputted to :func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls with a blank port will have : removed). Example: :: >>> U = parse_url('http://google.com/mail/') >>> U.url 'http://google.com/mail/' >>> Url('http', 'username:password', 'host.com', 80, ... '/path', 'query', 'fragment').url 'http://username:password@host.com:80/path?query#fragment' Nz://@:r#)str) rrrrr r r r urlrrrr%7s"    zUrl.urlcCs|jS)N)r%)rrrr__str___sz Url.__str__)NNNNNNN) __name__ __module__ __qualname____doc__ __slots__rpropertyrrrr%r& __classcell__rr)rrrs   (rcCszd}d}x8|D]0}|j|}|dkr&q|dks6||kr|}|}qW|dksR|dkr\|ddfS|d|||dd|fS)a Given a string and an iterable of delimiters, split on the first found delimiter. Return two split parts and the matched delimiter. If not found, then the first part is the full input string. Example:: >>> split_first('foo/bar?baz', '?/=') ('foo', 'bar?baz', '/') >>> split_first('foo/bar?baz', '123') ('foo/bar?baz', '', None) Scales linearly with number of delims. Not ideal for large number of delims. Nrr )find)sdelimsmin_idx min_delimdidxrrr split_firstcs   r6c Cs|s tSd}d}d}d}d}d}d}d|kr>|jdd\}}t|dddg\}}} | r`| |}d|krx|jdd\}}|r|dd kr|jd d\}}|d 7}d |kr |jd d\} }|s| }|r|jst|y t|}Wntk rt|YnXnd}n| r|r|}|s8t|||||||Sd|krR|jdd\}}d|krl|jdd\}}t|||||||S) a: Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is performed to parse incomplete urls. Fields not provided will be None. Partly backwards-compatible with :mod:`urlparse`. Example:: >>> parse_url('http://google.com/mail/') Url(scheme='http', host='google.com', port=None, path='/mail/', ...) >>> parse_url('google.com:80') Url(scheme=None, host='google.com', port=80, path=None, ...) >>> parse_url('/foo?bar') Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...) Nz://r.rrr#r!r[]r")rsplitr6rsplitisdigitrint ValueError) r%rrrr r r r path_delim_hostrrr parse_urlsP    rAcCst|}|jpd|j|jfS)z4 Deprecated. Use :func:`parse_url` instead. r )rArrr )r%prrrget_hostsrC)r rN) __future__r collectionsr exceptionsr url_attrsrrr6rArCrrrrs   U!]