3 fH^6 @sddlmZddlZddlmZddlmZddlmZddd d d d d gZ dKZ ej dZ ej dZ ej dejejBZdZdZdjeedZeedZddddddddd g Zd!Zd"d#jd$d%eDd&Zd'ed(Zd)ed"ed*Zd+Zej d,Zej d-ed.Zej d-ed.Zej d-ed.Z ej d-eddLd.Z!ej d/ed0Z"d1eeefZ#ej e#ejejBZ$e%d2Z&e%d3Z'e&e'Bd4hBZ(e(d5d6hBZ)e)d7hBZ*Z+Gd8d9d9ed9e Z,d:d;Z-dMd=d>Z.d?d@Z/dAdBZ0dCdDZ1dEdFZ2dGdHZ3dIdJZ4dS)N)absolute_importN) namedtuple)LocationParseError)sixschemeauthhostportpathqueryfragmenthttphttpsz%[a-fA-F0-9]{2}z^(?:[a-zA-Z][a-zA-Z0-9+-]*:|/)zQ^(?:([a-zA-Z][a-zA-Z0-9+.-]*):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?$z(?:[0-9]{1,3}\.){3}[0-9]{1,3}z[0-9A-Fa-f]{1,4}z(?:{hex}:{hex}|{ipv4}))hexZipv4)rZls32z(?:%(hex)s:){6}%(ls32)sz::(?:%(hex)s:){5}%(ls32)sz%(?:%(hex)s)?::(?:%(hex)s:){4}%(ls32)sz2(?:(?:%(hex)s:)?%(hex)s)?::(?:%(hex)s:){3}%(ls32)sz6(?:(?:%(hex)s:){0,2}%(hex)s)?::(?:%(hex)s:){2}%(ls32)sz/(?:(?:%(hex)s:){0,3}%(hex)s)?::%(hex)s:%(ls32)sz'(?:(?:%(hex)s:){0,4}%(hex)s)?::%(ls32)sz&(?:(?:%(hex)s:){0,5}%(hex)s)?::%(hex)sz(?:(?:%(hex)s:){0,6}%(hex)s)?::zDABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._!\-~z(?:|cCsg|] }|tqS)_subs).0xrr3/tmp/pip-build-ry83zzu8/urllib3/urllib3/util/url.py 6sr)z (?:%25|%)(?:[z]|%[a-fA-F0-9]{2})+z\[z)?\]z!(?:[^\[\]%:/?#]|%[a-fA-F0-9]{2})*z!^(/[^?#]*)(?:\?([^#]*))?(?:#.*)?$^$(z)\]$z(^(?:(.*)@)?(%s|%s|%s)(?::([0-9]{0,5}))?$zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-~z !$&'()*+,;=:@/?cs^eZdZdZfZdfdd ZeddZeddZed d Z ed d Z d dZ Z S)Urlz Data structure 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 sF|r|jd rd|}|dk r(|j}tt|j||||||||S)Nr) startswithlowersuperr __new__)clsrrr r r r r ) __class__rrr$[s  z Url.__new__cCs|jS)z@For backwards-compatibility with urlparse. We're nice like that.)r )selfrrrhostnamemsz Url.hostnamecCs&|jpd}|jdk r"|d|j7}|S)z)Absolute path including the query string.rNr)r r )r'urirrr request_urirs  zUrl.request_uricCs|jrd|j|jfS|jS)z(Network location including host and portz%s:%d)r r )r'rrrnetloc|sz 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://rrr#)str) r'rrr r r r r urlrrrr/s"    zUrl.urlcCs|jS)N)r/)r'rrr__str__sz Url.__str__)NNNNNNN) __name__ __module__ __qualname____doc__ __slots__r$propertyr(r*r+r/r0 __classcell__rr)r&rr Rs   (r cCszd}d}x8|D]0}|j|}|dkr&q|dks6||kr|}|}qW|dksR|dkr\|ddfS|d|||dd|fS)a .. deprecated:: 1.25 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_firsts   r@utf-8c Cs|dkr |Stj|}tjdd|\}}|jdd}||jdk}t}xtdt|D]n}|||d}t |} |r|dks| d kr|j |kr||7}qZ|j dt | d djj d jqZW|j |S) zfPercent-encodes a URI component without reapplying onto an already percent-encoded component. NcSs|jdjS)Nr)groupupper)matchrrrsz'_encode_invalid_chars..zutf-8 surrogatepass%rr8r)r ensure_text PERCENT_REsubnencodecount bytearrayrangelenorddecodeextendrzfillrC) component allowed_charsencodingZpercent_encodingsZ uri_bytesZis_percent_encodedZencoded_componentiZbyteZbyte_ordrrr_encode_invalid_charss"   ,rYcCs|jd}g}x8|D]0}|dkr$qq|dkr8|j|q|r|jqW|jdrl| s`|drl|jdd|jdr|jddj|S) Nr.z..rr,/./..)r[r\)splitappendpopr!insertendswithjoin)r segmentsoutputZsegmentrrr_remove_path_dot_segmentss       recCs|rt|tjrtj|}|tkrtj|}|rtj|}|r|j d\}}|||}|j drx|dkrx|dd}n |dd}dt |t }|d|j |||dS|j Sn*tj|stjdjdd|jdDS|S) Nr8z%25%.cSsg|] }t|qSr) _idna_encode)rlabelrrrr)sz#_normalize_host..rZ) isinstancer binary_type ensure_strNORMALIZABLE_SCHEMES IPV6_ADDRZ_RErD ZONE_ID_REsearchspanr!rYUNRESERVED_CHARSr"IPV4_RErbr])r rZis_ipv6rDstartendZzone_idrrr_normalize_hosts(         rwcCs|rtdd|Dry ddl}Wn$tk rFtjtddYnXy|j|jdddS|jk rtjtd|dYnX|jjdS) NcSsg|]}t|dkqS)rH)rQ)rrrrrr/sz _idna_encode..rz-Unable to parse URL without the 'idna' moduleT)strict std3_rulesz#Name '%s' is not a valid IDNA labelascii) anyidna ImportErrorr raise_fromrrLr" IDNAError)namer|rrrri.s  ricCs>tj|j\}}t|t}t|t}|dk r:|d|7}|S)zHPercent-encodes a request target so that there are no invalid charactersNr) TARGET_RErDgroupsrY PATH_CHARS QUERY_CHARS)targetr r rrr_encode_target@s    rc s|s tS|}tj|s d|}ytj|j\}}}}}|dkpN|jtk}|r\|j}|rtj|j\}} } |r|rt |t }| dkrd} n d \}} } | dk rt | } d| kodknst |t | |} |r|rt|}t |t}|r|rt |t}|r|rt |t}Wn&ttfk rFtjt |dSX|sl|dk sb|dk rhd}nd}t|tjrtjntjfdd} t| || || | | | || || |dS) a  Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is performed to parse incomplete urls. Fields not provided will be None. This parser is RFC 3986 compliant. The parser logic and helper functions are based heavily on work done in the ``rfc3986`` module. :param str url: URL to parse into a :class:`.Url` namedtuple. 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', ...) z//Nr,rics|dkr |S|S)Nr)r) ensure_funcrr ensure_typeszparse_url..ensure_type)rrr r r r r )NNN)r SCHEME_RErqURI_RErDrr"rnSUBAUTHORITY_RErYUSERINFO_CHARSintrrwrerrFRAGMENT_CHARS ValueErrorAttributeErrorrr~rk text_typerIrm) r/Z source_urlr authorityr r r Z normalize_urirr r rr)rr parse_urlJs^         rcCst|}|jpd|j|jfS)z4 Deprecated. Use :func:`parse_url` instead. r)rrr(r )r/prrrget_hostsr)rrN)rA)5 __future__rre collectionsr exceptionsrpackagesr url_attrsrncompilerJrUNICODEDOTALLrZIPV4_PATZHEX_PATformatZLS32_PATrZ _variationsZUNRESERVED_PATrbZIPV6_PATZ ZONE_ID_PATZIPV6_ADDRZ_PATZ REG_NAME_PATrrtZIPV6_REroZBRACELESS_IPV6_ADDRZ_RErpZSUBAUTHORITY_PATrsetrsZSUB_DELIM_CHARSrrrrr r@rYrerwrirrrrrrrsn          ]# " _