3 »nNj�ã@sŠddlmZddlmZddlZddlmZddlmZddd d d d d gZ dZ ej dƒZ Gdd„dede ƒƒZ dd„Zdd„Zdd„ZdS)é)Úabsolute_import)Ú namedtupleNé)ÚLocationParseError)ÚquoteÚschemeÚauthÚhostÚportÚpathÚqueryÚfragmentÚhttpÚhttpsz[- ]cs^eZdZdZfZd‡fdd„ Zedd„ƒZedd„ƒZed d „ƒZ ed d „ƒZ d d„Z ‡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ú/)Ú startswithÚlowerÚNORMALIZABLE_SCHEMESÚsuperrÚ__new__)Úclsrrr r r r r )Ú __class__©ú/usr/lib/python3.6/url.pyrs z Url.__new__cCs|jS)z@For backwards-compatibility with urlparse. We're nice like that.)r )ÚselfrrrÚhostname%sz Url.hostnamecCs&|jpd}|jdk r"|d|j7}|S)z)Absolute path including the query string.rNú?)r r )rZurirrrÚ request_uri*s  zUrl.request_uricCs|jrd|j|jfS|jS)z(Network location including host and portz%s:%d)r r )rrrrÚnetloc4sz 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) rrrr r r r r Úurlrrrr%;s"    zUrl.urlcCs|jS)N)r%)rrrrÚ__str__csz Url.__str__)NNNNNNN) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__rÚpropertyrrrr%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)ÚsZdelimsZmin_idxZ min_delimÚdÚidxrrrÚ split_firstgs   r3c Cs�|s tƒStjdd„|ƒ}d}d}d}d}d}d}d}d|krN|jddƒ\}}t|dddgƒ\}}} | rp| |}d |krˆ|jd dƒ\}}|r°|d d kr°|jd dƒ\}}|d 7}d |k�r|jd dƒ\} }|sÒ| }|�r|jƒsèt|ƒ‚y t|ƒ}Wnt k �rt|ƒ‚YnXnd}n| �r.|�r.|}|�sHt|||||||ƒSd|k�rb|jddƒ\}}d|k�r||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', ...) cSs t|jƒƒS)N)rÚgroup)ÚmatchrrrÚ¤szparse_url..Nz://r.rrr#r!rú[ú]r") rÚ!_contains_disallowed_url_pchar_reÚsubÚsplitr3ÚrsplitÚisdigitrÚintÚ ValueError) r%rrr r r r r Zpath_ZdelimZ_hostrrrÚ parse_urlˆsR    r@cCst|ƒ}|jpd|j|jfS)z4 Deprecated. Use :func:`parse_url` instead. r)r@rrr )r%ÚprrrÚget_hostésrB)rrN)Z __future__rÚ collectionsrÚreÚ exceptionsrZpackages.six.moves.urllib.parserZ url_attrsrÚcompiler9rr3r@rBrrrrÚs     U!a