B
    Š@
dÉ7  ã            	   @   s  d dl mZ d dlZd dlmZ ddlmZ ddlmZ ddd	d
dddgZ	dZ
e d¡Ze d¡Ze dejejB ¡ZdZdZdjeedZeedœZdddddddddg	Zd Zd!d" d#d$„ eD ƒ¡ d% Zd&e d' Zd(e d! e d) Zd*Ze d+¡Ze d,e d- ¡Ze d,e d- ¡Ze d,e d- ¡Z e d,edd.…  d- ¡Z!e d/e d0 ¡Z"d1eeef Z#e e#ejejB ¡Z$e%d2ƒZ&e%d3ƒZ'e&e'B d4hB Z(e(d5d6hB Z)e)d7hB  Z*Z+G d8d9„ d9ed9e	ƒƒZ,d:d;„ Z-dKd=d>„Z.d?d@„ Z/dAdB„ Z0dCdD„ Z1dEdF„ Z2dGdH„ Z3dIdJ„ Z4dS )Lé    )Úabsolute_importN)Ú
namedtupleé   )ÚLocationParseError)ÚsixÚschemeÚauthÚhostÚportÚpathÚqueryÚfragment)ÚhttpÚhttpsNz%[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}))ÚhexZipv4)r   Zls32z(?:%(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(?:ú|c             C   s   g | ]}|t  ‘qS © )Ú_subs)Ú.0Úxr   r   ú5/tmp/pip-install-587nrtaf/urllib3/urllib3/util/url.pyú
<listcomp>6   s    r   ú)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!$&'()*+,;=ú:ú@ú/ú?c                   s^   e Zd ZdZdZd‡ fdd„	Zedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒ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.
    r   Nc          
      sD   |r|  d¡sd| }|d k	r&| ¡ }tt| ƒ | |||||||¡S )Nr   )Ú
startswithÚlowerÚsuperr!   Ú__new__)Úclsr   r   r	   r
   r   r   r   )Ú	__class__r   r   r%   [   s    

zUrl.__new__c             C   s   | j S )z@For backwards-compatibility with urlparse. We're nice like that.)r	   )Úselfr   r   r   Úhostnamem   s    zUrl.hostnamec             C   s&   | j pd}| jdk	r"|d| j 7 }|S )z)Absolute path including the query string.r   Nr    )r   r   )r(   Úurir   r   r   Úrequest_urir   s    

zUrl.request_uric             C   s   | j rd| j| j f S | jS )z(Network location including host and portz%s:%d)r
   r	   )r(   r   r   r   Únetloc|   s    z
Url.netlocc       	      C   s¢   | \}}}}}}}d}|dk	r*||d 7 }|dk	r>||d 7 }|dk	rN||7 }|dk	rf|dt |ƒ 7 }|dk	rv||7 }|dk	rŠ|d| 7 }|dk	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   r   r    ú#)Ústr)	r(   r   r   r	   r
   r   r   r   Úurlr   r   r   r0   ƒ   s"    zUrl.urlc             C   s   | j S )N)r0   )r(   r   r   r   Ú__str__«   s    zUrl.__str__)NNNNNNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r%   Úpropertyr)   r+   r,   r0   r1   Ú__classcell__r   r   )r'   r   r!   R   s         

(r!   c             C   sz   d}d}x8|D ]0}|   |¡}|dk r&q|dks6||k r|}|}qW |dksR|dk r\| ddfS | d|… | |d d… |fS )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.
    Nr   r-   é   )Úfind)ÚsÚdelimsÚmin_idxÚ	min_delimÚdÚidxr   r   r   Úsplit_first¯   s    


rA   úutf-8c       
      C   sÖ   | dkr| S t  | ¡} t dd„ | ¡\} }|  dd¡}|| d¡k}tƒ }x€tdt|ƒƒD ]n}|||d … }t	|ƒ}	|r‚|dks–|	d	k r | 
¡ |kr ||7 }qZ| dt|	ƒd
d…  ¡  d
¡ ¡  ¡ qZW | 
|¡S )zfPercent-encodes a URI component without reapplying
    onto an already percent-encoded component.
    Nc             S   s   |   d¡ ¡ S )Nr   )ÚgroupÚupper)Úmatchr   r   r   Ú<lambda>ß   ó    z'_encode_invalid_chars.<locals>.<lambda>zutf-8Úsurrogatepassó   %r   r9   é€   r   )r   Úensure_textÚ
PERCENT_REÚsubnÚencodeÚcountÚ	bytearrayÚrangeÚlenÚordÚdecodeÚextendr   ÚzfillrD   )
Ú	componentÚallowed_charsÚencodingZpercent_encodingsZ	uri_bytesZis_percent_encodedZencoded_componentÚiZbyteZbyte_ordr   r   r   Ú_encode_invalid_charsÒ   s"    
,r[   c             C   sˆ   |   d¡}g }x8|D ]0}|dkr$qq|dkr8| |¡ q|r| ¡  qW |  d¡rj|r^|d rj| dd¡ |  d¡r~| d¡ d |¡S )Nr   Ú.z..r   r-   )z/.z/..)ÚsplitÚappendÚpopr"   ÚinsertÚendswithÚjoin)r   ÚsegmentsÚoutputZsegmentr   r   r   Ú_remove_path_dot_segmentsô   s    



re   c             C   sê   | ræt | tjƒrt | ¡} |tkræt | ¡}|r¼t | ¡}|r²| 	d¡\}}| ||… }| 
d¡rx|dkrx|dd … }n|dd … }dt|tƒ }| d |…  ¡ | | |d …  S |  ¡ S n*t | ¡sæt d dd„ |  d¡D ƒ¡¡S | S )	Nr9   z%25é   ú%ó   .c             S   s   g | ]}t |ƒ‘qS r   )Ú_idna_encode)r   Úlabelr   r   r   r   ,  s    z#_normalize_host.<locals>.<listcomp>r\   )Ú
isinstancer   Úbinary_typeÚ
ensure_strÚNORMALIZABLE_SCHEMESÚIPV6_ADDRZ_RErE   Ú
ZONE_ID_REÚsearchÚspanr"   r[   ÚUNRESERVED_CHARSr#   ÚIPV4_RErb   r]   )r	   r   Zis_ipv6rE   ÚstartÚendZzone_idr   r   r   Ú_normalize_host  s(    


 

rw   c             C   s–   | rˆt dd„ | D ƒƒrˆydd l}W n$ tk
rF   t tdƒd ¡ Y nX y|j|  ¡ dddS  |jk
r†   t td|  ƒd ¡ Y nX |  ¡  d¡S )	Nc             S   s   g | ]}t |ƒd k‘qS )rJ   )rS   )r   r   r   r   r   r   2  s    z _idna_encode.<locals>.<listcomp>r   z-Unable to parse URL without the 'idna' moduleT)ÚstrictÚ
std3_rulesz#Name '%s' is not a valid IDNA labelÚascii)	ÚanyÚidnaÚImportErrorr   Ú
raise_fromr   rN   r#   Ú	IDNAError)Únamer|   r   r   r   ri   1  s    ri   c             C   s>   t  | ¡ ¡ \}}t|tƒ} t|tƒ}|dk	r:| d| 7 } | S )zHPercent-encodes a request target so that there are no invalid charactersNr    )Ú	TARGET_RErE   Úgroupsr[   Ú
PATH_CHARSÚQUERY_CHARS)Útargetr   r   r   r   r   Ú_encode_targetC  s    

r†   c          	      sÚ  | s
t ƒ S | }t | ¡s d|  } yt | ¡ ¡ \}}}}}|dkpN| ¡ tk}|r\| ¡ }|rª| d¡\}}	}
|pvd}t	 |
¡ ¡ \}}|rœ|rœt
|tƒ}|dkr´d}n
d\}}}|dk	rât|ƒ}d|  krØdksân t| ƒ‚t||ƒ}|r
|r
t|ƒ}t
|tƒ}|r |r t
|tƒ}|r6|r6t
|tƒ}W n& ttfk
r^   t t|ƒd¡S X |s„|dk	sz|dk	r€d}nd}t| tjƒrštj‰ ntj‰ ‡ fdd	„}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//Nr   r-   )NNNr   iÿÿ  c                s   | d kr| S ˆ | ƒS )Nr   )r   )Úensure_funcr   r   Úensure_type   s    zparse_url.<locals>.ensure_type)r   r   r	   r
   r   r   r   )r!   Ú	SCHEME_RErq   ÚURI_RErE   r‚   r#   rn   Ú
rpartitionÚ_HOST_PORT_REr[   ÚUSERINFO_CHARSÚintr   rw   re   rƒ   r„   ÚFRAGMENT_CHARSÚ
ValueErrorÚAttributeErrorr   r~   rk   Ú	text_typerK   rm   )r0   Z
source_urlr   Ú	authorityr   r   r   Znormalize_urir   Ú_Ú	host_portr	   r
   rˆ   r   )r‡   r   Ú	parse_urlM  sb    





r–   c             C   s   t | ƒ}|jpd|j|jfS )z4
    Deprecated. Use :func:`parse_url` instead.
    r   )r–   r   r)   r
   )r0   Úpr   r   r   Úget_host®  s    r˜   )rB   )5Ú
__future__r   ÚreÚcollectionsr   Ú
exceptionsr   Úpackagesr   Ú	url_attrsrn   ÚcompilerL   r‰   ÚUNICODEÚDOTALLrŠ   ZIPV4_PATZHEX_PATÚformatZLS32_PATr   Z_variationsZUNRESERVED_PATrb   ZIPV6_PATZZONE_ID_PATZIPV6_ADDRZ_PATZREG_NAME_PATr   rt   ZIPV6_REro   ZBRACELESS_IPV6_ADDRZ_RErp   Z_HOST_PORT_PATrŒ   Úsetrs   ZSUB_DELIM_CHARSr   rƒ   r„   r   r!   rA   r[   re   rw   ri   r†   r–   r˜   r   r   r   r   Ú<module>   sn   



]#
"
a