U
    ;ßôgzi  ã                
   @   sÂ  d Z ddlZddlZddlZddlZddlZddlmZ dZdZ	dZ
dZe
e ZdZee ¡ ƒZd	d
d„ edƒD ƒiZdd„ eD ƒZdLdd„ZdMdd„ZG dd„ de dd¡ƒZG dd„ de dd¡ƒZG dd„ deƒZG dd„ deƒZd d!„ Zd"d#„ Zd$d%„ ZdNd'd(„Zd)d*„ Zd+d,„ Z d-d.„ Z!d/d0„ Z"d1d2„ Z#d3d4„ Z$e %d5¡Z&e %d6¡Z'e %d7¡Z(ed8 Z)eZ*ed9 Z+ed: Z,ed: Z-d;d<„ Z.d=d>„ Z/d?d@„ Z0dAdB„ Z1dCdD„ Z2dEdF„ Z3dGdH„ Z4dOdJdK„Z5dS )PzÚRFC 3986 compliant, scheme-agnostic replacement for `urllib.parse`.

This module defines RFC 3986 compliant replacements for the most
commonly used functions of the Python Standard Library
:mod:`urllib.parse` module.

é    N)Ú	hexdigits)Ú
GEN_DELIMSÚRESERVEDÚ
SUB_DELIMSÚ
UNRESERVEDÚ	isabspathÚisabsuriÚ	isnetpathÚ	isrelpathÚ	issamedocÚisuriÚ
uricomposeÚ	uridecodeÚ	uridefragÚ	uriencodeÚurijoinÚurisplitÚ
uriunsplitz4.0.3z:/?#[]@z!$&'()*+,;=zBABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~ó    c                 C   s*   g | ]"}|t krt|gƒn
d |  ¡ ‘qS )z%%%02X)Ú_unreservedÚbytesÚencode)Ú.0Úi© r   ú5/tmp/pip-unpacked-wheel-zar3_3_l/uritools/__init__.pyÚ
<listcomp>B   s    r   é   c                 C   s.   i | ]&}t D ]}||  ¡ t || ¡“qqS r   )r   r   r   Úfromhex)r   ÚaÚbr   r   r   Ú
<dictcomp>G   s
      
 r!   Ú úutf-8Ústrictc                 C   sŽ   t | tƒs|  ||¡} t |tƒs*| d¡}zt| }W nD tk
rz   td dd… }|D ]}t|gƒ||< qZ|t|< Y nX d t|j| ƒ¡S )z(Encode a URI string or string component.Úasciir   N)Ú
isinstancer   r   Ú_encodedÚKeyErrorÚjoinÚmapÚ__getitem__)Ú	uristringÚsafeÚencodingÚerrorsÚencodedr   r   r   r   r   L   s    


r   c                 C   s¦   t | tƒs|  |pd|¡} |  d¡}|d g}|j}tj}|dd… D ]6}|||dd… d|dd…  ƒƒ ||dd… ƒ qF|dk	r˜d |¡ ||¡S d |¡S dS )z(Decode a URI string or string component.r%   ó   %r   é   Né   r   )	r&   r   r   ÚsplitÚappendÚ_decodedÚgetr)   Údecode)r,   r.   r/   ÚpartsÚresultr5   r8   Úsr   r   r   r   \   s    


"r   c                   @   s&   e Zd ZdZdZdd„ Zd
dd	„ZdS )ÚDefragResultz(Class to hold :func:`uridefrag` results.r   c                 C   s>   | j }|dkr| jS t|tƒr,| jd | S | jd | S dS )z>Return the recombined version of the original URI as a string.Nó   #ú#)ÚfragmentÚurir&   r   )Úselfr?   r   r   r   Úgeturir   s    
zDefragResult.geturiNr#   r$   c                 C   s"   | j }|dk	rt|||ƒS |S dS )z€Return the decoded fragment identifier, or `default` if the
        original URI did not contain a fragment component.

        N©r?   r   ©rA   Údefaultr.   r/   r?   r   r   r   Úgetfragment|   s    zDefragResult.getfragment)Nr#   r$   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__rB   rF   r   r   r   r   r<   m   s   
r<   zuri fragmentc                   @   sþ   e Zd ZdZdZedd„ ƒZedd„ ƒZedd„ ƒZd	d
„ Z	d8dd„Z
d9dd„Zd:dd„Zd;dd„Zd<dd„Zd=dd„Zd>dd„Zd?dd„Zd@dd „ZdAd!d"„Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ ZdBd0d1„Zd2d3„ Zed4d5„ ƒZed6d7„ ƒZdS )CÚSplitResultz,Base class to hold :func:`urisplit` results.r   c                 C   s4   | j }|d krd S | | j¡\}}}|r,|S d S d S ©N)Ú	authorityÚ
rpartitionÚAT)rA   rN   ÚuserinfoÚpresentÚ_r   r   r   rQ      s    zSplitResult.userinfoc                 C   sN   | j }|d krd S | | j¡\}}}| | j¡\}}}| | j¡rF|S |S d S rM   )rN   rO   rP   ÚCOLONÚlstripÚDIGITS)rA   rN   rS   ÚhostinfoÚhostÚportr   r   r   rX   š   s    zSplitResult.hostc                 C   s@   | j }|d krd S | | j¡\}}}|r8| | j¡s8|S d S d S rM   )rN   rO   rT   rU   rV   )rA   rN   rS   rR   rY   r   r   r   rY   ¦   s    zSplitResult.portc                 C   sŒ   | \}}}}}g }|dk	r*|  || jg¡ |dk	rF|  | j| j|g¡ | |¡ |dk	rh|  | j|g¡ |dk	r€|  | j|g¡ | j |¡S )z[Return the re-combined version of the original URI reference as a
        string.

        N)ÚextendrT   ÚSLASHr5   ÚQUESTÚHASHÚEMPTYr)   )rA   ÚschemerN   ÚpathÚqueryr?   r:   r   r   r   rB   ±   s    
zSplitResult.geturiNc                 C   s6   | j }|dkr|S t|tƒr*| d¡ ¡ S | ¡ S dS )z•Return the URI scheme in canonical (lowercase) form, or `default`
        if the original URI reference did not contain a scheme component.

        Nr%   )r_   r&   r   r8   Úlower)rA   rE   r_   r   r   r   Ú	getschemeÅ   s    
zSplitResult.getschemer#   r$   c                 C   sh   |dkrd}n,t |tjjƒs&tdƒ‚nt|ƒdkr:tdƒ‚|  |d ||¡|  |d |¡|  	|d ¡fS )	zvReturn the decoded userinfo, host and port subcomponents of the URI
        authority as a three-item tuple.

        N©NNNzInvalid default typeé   zInvalid default lengthr   r2   r3   )
r&   ÚcollectionsÚabcÚIterableÚ	TypeErrorÚlenÚ
ValueErrorÚgetuserinfoÚgethostÚgetport)rA   rE   r.   r/   r   r   r   ÚgetauthorityÒ   s    
ýzSplitResult.getauthorityc                 C   s"   | j }|dkr|S t|||ƒS dS )z¥Return the decoded userinfo subcomponent of the URI authority, or
        `default` if the original URI reference did not contain a
        userinfo field.

        N)rQ   r   )rA   rE   r.   r/   rQ   r   r   r   rl   å   s    zSplitResult.getuserinfoc                 C   sÂ   | j }|dks|s|dk	r|S | | j¡rH| | j¡rH|  |dd… ¡S | | j¡s`| | j¡rltd| ƒ‚z,t|tƒrŠt	 
| d¡¡W S t	 
|¡W S W n$ tk
r¼   t|d|ƒ ¡  Y S X dS )zÉReturn the decoded host subcomponent of the URI authority as a
        string or an :mod:`ipaddress` address object, or `default` if
        the original URI reference did not contain a host.

        Nr2   éÿÿÿÿzInvalid host %rr%   r#   )rX   Ú
startswithÚLBRACKETÚendswithÚRBRACKETÚ_SplitResult__parse_ip_literalrk   r&   r   Ú	ipaddressÚIPv4Addressr8   r   rb   )rA   rE   r/   rX   r   r   r   rm   ñ   s    
zSplitResult.gethostc                 C   s   | j }|rt|ƒS |S dS )z»Return the port subcomponent of the URI authority as an
        :class:`int`, or `default` if the original URI reference did
        not contain a port or if the port was empty.

        N)rY   Úint)rA   rE   rY   r   r   r   rn     s    zSplitResult.getportc                 C   s   |   | j¡}t|||ƒS )z'Return the normalized decoded URI path.)Ú!_SplitResult__remove_dot_segmentsr`   r   )rA   r.   r/   r`   r   r   r   Úgetpath  s    zSplitResult.getpathc                 C   s"   | j }|dkr|S t|||ƒS dS )z€Return the decoded query string, or `default` if the original URI
        reference did not contain a query component.

        N)ra   r   )rA   rE   r.   r/   ra   r   r   r   Úgetquery  s    zSplitResult.getqueryú&c                 C   s4   t  t¡}|  |||¡D ]\}}||  |¡ q|S )a  Split the query component into individual `name=value` pairs
        separated by `sep` and return a dictionary of query variables.
        The dictionary keys are the unique query variable names and
        the values are lists of values for each name.

        )rf   ÚdefaultdictÚlistÚgetquerylistr5   )rA   Úsepr.   r/   ÚdictÚnameÚvaluer   r   r   Úgetquerydict#  s    
zSplitResult.getquerydictc           	         s´   ˆ j s
g S t|tˆ j ƒƒr(ˆ j  |¡}n0t|tƒrFˆ j  | d¡¡}nˆ j  | d¡¡}g }‡ fdd„|D ƒD ]@}t|d ||ƒ}|d rœt|d ||ƒ}nd}| ||f¡ qn|S )z—Split the query component into individual `name=value` pairs
        separated by `sep`, and return a list of `(name, value)`
        tuples.

        r%   c                    s   g | ]}|r|  ˆ j¡‘qS r   )Ú	partitionÚEQ)r   Úqs©rA   r   r   r   >  s      z,SplitResult.getquerylist.<locals>.<listcomp>r   r2   r3   N)	ra   r&   Útyper4   r   r8   r   r   r5   )	rA   r€   r.   r/   ZqslÚitemsr9   r‚   rƒ   r   rˆ   r   r   /  s    
zSplitResult.getquerylistc                 C   s"   | j }|dkr|S t|||ƒS dS )zŠReturn the decoded fragment identifier, or `default` if the
        original URI reference did not contain a fragment component.

        NrC   rD   r   r   r   rF   G  s    zSplitResult.getfragmentc                 C   s
   | j dk	S )z&Return :const:`True` if this is a URI.N©r_   rˆ   r   r   r   r   R  s    zSplitResult.isuric                 C   s   | j dk	o| jdkS )z0Return :const:`True` if this is an absolute URI.N)r_   r?   rˆ   r   r   r   r   V  s    zSplitResult.isabsuric                 C   s   | j dko| jdk	S )z9Return :const:`True` if this is a network-path reference.N)r_   rN   rˆ   r   r   r   r	   Z  s    zSplitResult.isnetpathc                 C   s"   | j dko | jdko | j | j¡S )z;Return :const:`True` if this is an absolute-path reference.N©r_   rN   r`   rq   r[   rˆ   r   r   r   r   ^  s
    
ÿýzSplitResult.isabspathc                 C   s$   | j dko"| jdko"| j | j¡ S )z:Return :const:`True` if this is a relative-path reference.NrŒ   rˆ   r   r   r   r
   f  s
    
ÿýzSplitResult.isrelpathc                 C   s&   | j dko$| jdko$| j o$| jdkS )z:Return :const:`True` if this is a same-document reference.N)r_   rN   r`   ra   rˆ   r   r   r   r   n  s    
ÿþüzSplitResult.issamedocFc                 C   sÔ   | j  |¡ ¡ \}}}}}|dk	r<|s0|| jkr<|  |¡}n„|dk	rV| j}|  |¡}nj|s€| j}| j}| j}|dkrz| jn|}n@| | j	¡r¤| j}| j}|  |¡}n| j}| j}|  |  
|¡¡}t| ƒ|||||ƒS )zwTransform a URI reference relative to `self` into a
        :class:`SplitResult` representing its target URI.

        N)ÚREÚmatchÚgroupsr_   ry   rN   r`   ra   rq   r[   Ú_SplitResult__merger‰   )rA   Úrefr$   r_   rN   r`   ra   r?   r   r   r   Ú	transformw  s&    zSplitResult.transformc                 C   sB   | j d k	r| js| j| S | j | j¡}|d  |d |f¡S d S )Nr2   r   )rN   r`   r[   rO   r)   )rA   r`   r9   r   r   r   Z__merge“  s    
zSplitResult.__mergec                 C   sØ   g }|  | j¡D ]f}|| jkr"qq|| jkr8| |¡ qt|ƒdkrP|d sPqq|rl|d | jkrl| ¡  q| |¡ q| | j¡d | j| jfkr | | j¡ |rÌt|ƒdkrÌ|d | jkrÌ| 	d| j¡ | j 
|¡S )Nr2   r   rp   r3   )r4   r[   ÚDOTÚDOTDOTr5   rj   ÚpoprO   r^   Úinsertr)   )Úclsr`   Zpsegr;   r   r   r   Z__remove_dot_segments›  s     


z!SplitResult.__remove_dot_segmentsc                 C   s0   t |tƒr| d¡}| d¡r&tdƒ‚t |¡S )Nr%   Úvzaddress mechanism not supported)r&   r   r8   rq   rk   rv   ÚIPv6Address)r—   Úaddressr   r   r   Z__parse_ip_literal±  s
    


zSplitResult.__parse_ip_literal)N)Nr#   r$   )Nr#   r$   )Nr$   )N)r#   r$   )Nr#   r$   )r|   r#   r$   )r|   r#   r$   )Nr#   r$   )F)rG   rH   rI   rJ   rK   ÚpropertyrQ   rX   rY   rB   rc   ro   rl   rm   rn   rz   r{   r„   r   rF   r   r   r	   r   r
   r   r’   r   Úclassmethodry   ru   r   r   r   r   rL   ˆ   s>   














	

rL   z$scheme authority path query fragmentc                   @   sF   e Zd ZdZejdejdZd\ZZ	Z
ZZZZd\ZZd\ZZdZdS )	ÚSplitResultBytesr   sü   
    (?:([A-Za-z][A-Za-z0-9+.-]*):)?  # scheme (RFC 3986 3.1)
    (?://([^/?#]*))?                 # authority
    ([^?#]*)                         # path
    (?:\?([^#]*))?                   # query
    (?:\#(.*))?                      # fragment
    ©Úflags)ó   :ó   /ó   ?r=   ó   [ó   ]ó   @)ó   .s   ..)r   ó   =ó
   0123456789N©rG   rH   rI   rK   ÚreÚcompileÚVERBOSEr   rT   r[   r\   r]   rr   rt   rP   r“   r”   r^   r†   rV   r   r   r   r   r   É  s   ør   c                   @   sF   e Zd ZdZejdejdZd\ZZ	Z
ZZZZd\ZZd\ZZdZdS )	ÚSplitResultStringr   zü
    (?:([A-Za-z][A-Za-z0-9+.-]*):)?  # scheme (RFC 3986 3.1)
    (?://([^/?#]*))?                 # authority
    ([^?#]*)                         # path
    (?:\?([^#]*))?                   # query
    (?:\#(.*))?                      # fragment
    rž   )ú:ú/ú?r>   ú[ú]ú@)Ú.z..)r"   ú=Ú
0123456789Nr©   r   r   r   r   r­   ë  s   ør­   c                 C   s>   t | tƒr|  d¡}n
|  d¡}t|d |d r8|d ndƒS )zBRemove an existing fragment component from a URI reference string.r=   r>   r   r2   r3   N)r&   r   r…   r<   )r,   r9   r   r   r   r     s    

r   c                 C   s(   t | tƒrt}nt}||j | ¡ ¡ Ž S )z¹Split a well-formed URI reference string into a tuple with five
    components corresponding to a URI's general structure::

      <scheme>://<authority>/<path>?<query>#<fragment>

    )r&   r   r   r­   r   rŽ   r   )r,   r:   r   r   r   r     s    
r   c                 C   s6   | \}}}}}t |tƒrt}nt}||||||ƒ ¡ S )zdCombine the elements of a five-item iterable into a URI reference's
    string representation.

    )r&   r   r   r­   rB   )r9   r_   rN   r`   ra   r?   r:   r   r   r   r   $  s
    
r   Fc                 C   s`   t | t|ƒƒr"t| ƒ ||¡ ¡ S t | tƒrDt|  ¡ ƒ ||¡ ¡ S t| ƒ | ¡ |¡ ¡ S dS )zRConvert a URI reference relative to a base URI to its target URI
    string.

    N)r&   r‰   r   r’   rB   r   r8   )Úbaser‘   r$   r   r   r   r   1  s
    
r   c                 C   s   t | ƒ ¡ S )z-Return :const:`True` if `uristring` is a URI.)r   r   ©r,   r   r   r   r   >  s    r   c                 C   s   t | ƒ ¡ S )z7Return :const:`True` if `uristring` is an absolute URI.)r   r   r¸   r   r   r   r   C  s    r   c                 C   s   t | ƒ ¡ S )z@Return :const:`True` if `uristring` is a network-path reference.)r   r	   r¸   r   r   r   r	   H  s    r	   c                 C   s   t | ƒ ¡ S )zBReturn :const:`True` if `uristring` is an absolute-path reference.)r   r   r¸   r   r   r   r   M  s    r   c                 C   s   t | ƒ ¡ S )zAReturn :const:`True` if `uristring` is a relative-path reference.)r   r
   r¸   r   r   r   r
   R  s    r
   c                 C   s   t | ƒ ¡ S )zAReturn :const:`True` if `uristring` is a same-document reference.)r   r   r¸   r   r   r   r   W  s    r   s   ^[A-Za-z][A-Za-z0-9+.-]*$s   ^(?:(.*)@)?(.*?)(?::([0-9]*))?$z^(?:(.*)@)?(.*?)(?::([0-9]*))?$r®   z:@/z:@/?c                 C   s   t  | ¡r|  ¡ S tdƒ‚d S )NzInvalid scheme component)Ú
_SCHEME_RErŽ   rb   rk   r‹   r   r   r   Ú_schemem  s    
rº   c                 C   s  g }| d k	r(|  t| t|ƒ¡ |  d¡ t|tjƒrN|  d|j ¡  d ¡ nTt|tjƒrl|  |j ¡ ¡ n6t|t	ƒr†|  t
|ƒ¡ n|d k	r¢|  t
| d¡ƒ¡ t|tjƒrÆ|  tt|ƒ ¡ ƒ¡ n4t|t	ƒrà|  t|ƒ¡ n|d k	rú|  t| ¡ ƒ¡ |r
d |¡S d S )Nr¥   r£   r¤   r#   r   )r5   r   Ú_SAFE_USERINFOr&   rv   r™   Ú
compressedr   rw   r   Ú_hostÚnumbersÚNumberÚ_portÚstrr)   )rQ   rX   rY   r.   rN   r   r   r   Ú
_authorityt  s&    


rÂ   c                 C   s0   |   d¡rtdƒ‚ndt | ¡j ¡  d S d S )Nr˜   zAddress mechanism not supportedr£   r¤   )rq   rk   rv   r™   r¼   r   )rš   r   r   r   Ú_ip_literalŽ  s    

rÃ   c                 C   sb   |   d¡r(|  d¡r(t| dd…  ¡ ƒS zt|  d¡ƒW S  tk
r\   t|  ¡ tdƒ Y S X d S )Nr£   r¤   r2   rp   r#   )rq   rs   rÃ   r8   rk   r   rb   Ú
_SAFE_HOST)rX   r   r   r   r½   •  s    r½   c                 C   s(   |   d¡rtdƒ‚n| r d|  S dS d S )Nr¨   zInvalid port subcomponentr    r   )rU   rk   )rY   r   r   r   rÀ   £  s
    

rÀ   c           	      C   s–   g }|j }t |d¡}| D ]j\}}t|||ƒ}|d kr@||ƒ qt|ttfƒrh||d t|||ƒ ƒ q||d tt|ƒ||ƒ ƒ q| d¡ |¡S )Nr"   r§   r%   )	r5   Ú_SAFE_QUERYÚreplacer   r&   r   rÁ   r   r)   )	rŠ   r€   r.   Ztermsr5   r-   Úkeyrƒ   r‚   r   r   r   Ú
_querylist¯  s    
rÈ   c                    sv   g }|   ¡ D ]\\‰ }t|ttfƒr2| ˆ |f¡ qt|tjjƒrZ| ‡ fdd„|D ƒ¡ q| ˆ |f¡ qt	|||ƒS )Nc                    s   g | ]}ˆ |f‘qS r   r   )r   r˜   ©rÇ   r   r   r   Ä  s     z_querydict.<locals>.<listcomp>)
rŠ   r&   r   rÁ   r5   rf   rg   rh   rZ   rÈ   )Úmappingr€   r.   rŠ   rƒ   r   rÉ   r   Ú
_querydict¾  s    rË   r|   c
           
      C   sð  t | tƒrt| ƒ} n| dk	r(t|  ¡ ƒ} |dkr6d}n`t |tƒrPt |¡ ¡ }nFt |tƒrjt |¡ ¡ }n,t |t	j
jƒs‚tdƒ‚nt|ƒdkr–tdƒ‚t|dk	r¤|n|d |dk	r¶|n|d |dk	rÈ|n|d |	ƒ}t|t|	ƒ}|dk	rþ|rþ| d	¡sþtd
ƒ‚|dkr| d¡rtdƒ‚| dkrX|dkrX| d	¡sXd| d	¡d krXd| }t |ttfƒrvt|t|	ƒ}nNt |t	j
jƒr”t|||	ƒ}n0t |t	j
jƒr²t|||	ƒ}n|dk	rÄtdƒ‚|dk	rÚt|t|	ƒ}t| ||||fƒ ¡ S )z>Compose a URI reference string from its individual components.Nrd   zInvalid authority typere   zInvalid authority lengthr   r2   r3   r¡   z%Invalid path with authority components   //z(Invalid path without authority componentr    s   ./zInvalid query type)r&   r   rº   r   Ú_AUTHORITY_RE_BYTESrŽ   r   rÁ   Ú_AUTHORITY_RE_STRrf   rg   rh   ri   rj   rk   rÂ   r   Ú
_SAFE_PATHrq   r…   rÅ   ÚMappingrË   rÈ   Ú_SAFE_FRAGMENTr   r8   )
r_   rN   r`   ra   r?   rQ   rX   rY   Zquerysepr.   r   r   r   r   Ê  sN    




ü 

r   )r"   r#   r$   )r#   r$   )F)
NNr"   NNNNNr|   r#   )6rJ   rf   Úcollections.abcrv   r¾   rª   Ústringr   Ú__all__Ú__version__r   r   r   r   Ú	frozensetr   r   Úranger'   r6   r   r   Ú
namedtupler<   rL   r   r­   r   r   r   r   r   r   r	   r   r
   r   r«   r¹   rÌ   rÍ   r»   rÄ   rÎ   rÅ   rÐ   rº   rÂ   rÃ   r½   rÀ   rÈ   rË   r   r   r   r   r   Ú<module>   sˆ   ÿ ÿÿÿ



ÿ  C""	



          ö