3

Z'ícÉ7ã	@sddlmZddlZddlmZddlmZddlmZddd	d
ddd
gZ	dKZ
ejdƒZejdƒZ
ejdejejBƒZdZdZdjeedZeedœZddddddddd g	Zd!Zd"d#jd$d%„eDƒƒd&Zd'ed(Zd)ed"ed*Zd+Zejd,ƒZejd-ed.ƒZejd-ed.ƒZejd-ed.ƒZ ejd-eddL…d.ƒZ!ejd/ed0ƒZ"d1eeefZ#eje#ejejBƒZ$e%d2ƒZ&e%d3ƒZ'e&e'Bd4hBZ(e(d5d6hBZ)e)d7hBZ*Z+Gd8d9„d9ed9e	ƒƒZ,d:d;„Z-dMd=d>„Z.d?d@„Z/dAdB„Z0dCdD„Z1dEdF„Z2dGdH„Z3dIdJ„Z4dS)Né)Úabsolute_importN)Ú
namedtupleé)ÚLocationParseError)ÚsixÚschemeÚauthÚhostÚportÚpathÚqueryÚfragmentÚhttpÚhttpsz%[a-fA-F0-9]{2}z^(?:[a-zA-Z][a-zA-Z0-9+-]*:|/)zS^(?:([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|]}|t‘qS©)Ú_subs)Ú.0Úxrrú3/tmp/pip-build-gk9425m9/urllib3/urllib3/util/url.pyú
<listcomp>6srú)z
(?:%25|%)(?:[z]|%[a-fA-F0-9]{2})+z\[z)?\]z!(?:[^\[\]%:/?#]|%[a-fA-F0-9]{2})*z!^(/[^?#]*)(?:\?([^#]*))?(?:#.*)?$ú^ú$ú(z)\]$z)^(%s|%s|%s)(?::0*?(|0|[1-9][0-9]{0,4}))?$zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-~z!$&'()*+,;=ú:ú@ú/ú?cs^eZdZdZfZd‡fdd„	Zedd„ƒZedd„ƒZed	d
„ƒZ	edd„ƒZ
d
d„Z‡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)Ú
startswithÚlowerÚsuperr Ú__new__)Úclsrrr	r
rrr
)Ú	__class__rrr$[s

zUrl.__new__cCs|jS)z@For backwards-compatibility with urlparse. We're nice like that.)r	)ÚselfrrrÚhostnamemszUrl.hostnamecCs&|jpd}|jdk	r"|d|j7}|S)z)Absolute path including the query string.rNr)rr)r'ÚurirrrÚrequest_urirs

zUrl.request_uricCs|jrd|j|jfS|jS)z(Network location including host and portz%s:%d)r
r	)r'rrrÚnetloc|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
rrr
Úurlrrrr/ƒs"zUrl.urlcCs|jS)N)r/)r'rrrÚ__str__«szUrl.__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)ÚsÚdelimsÚmin_idxÚ	min_delimÚdÚidxrrrÚsplit_first¯s


r@úutf-8c
CsÖ|dkr|Stj|ƒ}tjdd„|ƒ\}}|jddƒ}||jdƒk}tƒ}x€tdt|ƒƒD]n}|||d…}t	|ƒ}	|r‚|dks–|	d	kr |j
ƒ|kr ||7}qZ|jdt|	ƒd
d…jƒj
d
ƒjƒƒqZW|j
|ƒS)zfPercent-encodes a URI component without reapplying
    onto an already percent-encoded component.
    NcSs|jdƒjƒS)Nr)ÚgroupÚupper)ÚmatchrrrÚ<lambda>ßsz'_encode_invalid_chars.<locals>.<lambda>zutf-8Ú
surrogatepassó%rr8é€r)rÚensure_textÚ
PERCENT_REÚsubnÚencodeÚcountÚ	bytearrayÚrangeÚlenÚordÚdecodeÚextendrÚzfillrC)
Ú	componentÚ
allowed_charsÚencodingZpercent_encodingsZ	uri_bytesZis_percent_encodedZencoded_componentÚiZbyteZbyte_ordrrrÚ_encode_invalid_charsÒs"
,rYcCsŠ|jdƒ}g}x8|D]0}|dkr$qq|dkr8|j|ƒq|r|jƒqW|jdƒrl|s`|drl|jddƒ|jdƒr€|jdƒdj|ƒS)	NrÚ.z..rr,ú/.ú/..)r[r\)ÚsplitÚappendÚpopr!ÚinsertÚendswithÚjoin)rÚsegmentsÚoutputZsegmentrrrÚ_remove_path_dot_segmentsôs



recCsê|ræt|tjƒrtj|ƒ}|tkrætj|ƒ}|r¼tj|ƒ}|r²|j	dƒ\}}|||…}|j
dƒrx|dkrx|dd…}n|dd…}dt|tƒ}|d|…j
ƒ|||d…S|j
ƒSn*tj|ƒsætjdjdd„|jdƒDƒƒƒS|S)	Nr8z%25éú%ó.cSsg|]}t|ƒ‘qSr)Ú_idna_encode)rÚlabelrrrr,sz#_normalize_host.<locals>.<listcomp>rZ)Ú
isinstancerÚbinary_typeÚ
ensure_strÚNORMALIZABLE_SCHEMESÚ
IPV6_ADDRZ_RErDÚ
ZONE_ID_REÚsearchÚspanr!rYÚUNRESERVED_CHARSr"ÚIPV4_RErbr])r	rZis_ipv6rDÚstartÚendZzone_idrrrÚ_normalize_hosts(


 

rwcCs–|rˆtdd„|Dƒƒrˆyddl}Wn$tk
rFtjtdƒdƒYnXy|j|jƒdddS|jk
r†tjtd|ƒdƒYnX|jƒjdƒS)	NcSsg|]}t|ƒdk‘qS)rH)rQ)rrrrrr2sz _idna_encode.<locals>.<listcomp>rz-Unable to parse URL without the 'idna' moduleT)ÚstrictÚ
std3_rulesz#Name '%s' is not a valid IDNA labelÚascii)	ÚanyÚidnaÚImportErrorrÚ
raise_fromrrLr"Ú	IDNAError)Únamer|rrrri1s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_RErDÚgroupsrYÚ
PATH_CHARSÚQUERY_CHARS)ÚtargetrrrrrÚ_encode_targetCs

r†csÜ|s
tƒS|}tj|ƒs d|}ytj|ƒjƒ\}}}}}|dkpN|jƒtk}|r\|jƒ}|rª|jdƒ\}}	}
|pvd}t	j|
ƒjƒ\}}|rœ|rœt
|tƒ}|dkr´d}n
d
\}}}|dk	rät|ƒ}d|koÖdknsät
|ƒ‚t||ƒ}|r|rt|ƒ}t
|tƒ}|r"|r"t
|tƒ}|r8|r8t
|tƒ}Wn&ttfk
r`tjt
|ƒdƒSX|s†|dk	s||dk	r‚d}nd}t|tjƒrœtj‰ntj‰‡fdd„}
t|
|ƒ|
|ƒ|
|ƒ||
|ƒ|
|ƒ|
|ƒd	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.
    This parser is RFC 3986 and RFC 6874 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//Nrr,riÿÿcs|dkr|Sˆ|ƒS)Nr)r)Úensure_funcrrÚensure_type szparse_url.<locals>.ensure_type)rrr	r
rrr
)NNN)r Ú	SCHEME_RErqÚURI_RErDr‚r"rnÚ
rpartitionÚ
_HOST_PORT_RErYÚUSERINFO_CHARSÚintrrwrerƒr„ÚFRAGMENT_CHARSÚ
ValueErrorÚAttributeErrorrr~rkÚ	text_typerIrm)r/Z
source_urlrÚ	authorityrrr
Z
normalize_urirÚ_Ú	host_portr	r
rˆr)r‡rÚ	parse_urlMsb





r–cCst|ƒ}|jpd|j|jfS)z4
    Deprecated. Use :func:`parse_url` instead.
    r)r–rr(r
)r/ÚprrrÚget_host®sr˜)rrNéþÿÿÿ)rA)5Ú
__future__rÚreÚcollectionsrÚ
exceptionsrÚpackagesrÚ	url_attrsrnÚcompilerJr‰ÚUNICODEÚDOTALLrŠZIPV4_PATZHEX_PATÚformatZLS32_PATrZ_variationsZUNRESERVED_PATrbZIPV6_PATZZONE_ID_PATZIPV6_ADDRZ_PATZREG_NAME_PATrrtZIPV6_REroZBRACELESS_IPV6_ADDRZ_RErpZ_HOST_PORT_PATrŒÚsetrsZSUB_DELIM_CHARSrrƒr„rr r@rYrerwrir†r–r˜rrrrÚ<module>sn



]#
"
a