3 hf@sddlmZddlmZddlZddlmZddlmZddd d d d d gZ dZ ej dZ Gdddede Z ddZddZddZdS))absolute_import) namedtupleN)LocationParseError)quoteschemeauthhostportpathqueryfragmenthttphttpsz[- ]cs^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__)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 )selfrrrhostname%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 )rrrrnetloc4sz 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__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)sZdelimsZmin_idxZ min_delimdidxrrr split_firstgs   r3c Cs|s tStjdd|}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 |kr|jd d\} }|s| }|r|jst|y t|}Wnt k rt|YnXnd}n| r.|r.|}|sHt|||||||Sd|krb|jdd\}}d|kr||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|jS)N)rgroup)matchrrrszparse_url..Nz://r.rrr#r!r[]r") r!_contains_disallowed_url_pchar_resubsplitr3rsplitisdigitrint ValueError) r%rrr r r r r Zpath_ZdelimZ_hostrrr parse_urlsR    r@cCst|}|jpd|j|jfS)z4 Deprecated. Use :func:`parse_url` instead. r)r@rrr )r%prrrget_hostsrB)rrN)Z __future__r collectionsrre exceptionsrZpackages.six.moves.urllib.parserZ url_attrsrcompiler9rr3r@rBrrrrs     U!a