3
‡ŒðiÐ‹  ã               @   s  d Z ddlmZmZmZ ddlmZmZmZm	Z	m
Z
mZ ddlmZ ddlZddlZddlZdddd	d
ddddddddddgZdddddddddddd d!d"d#d$d%gZddddd&ddddddd'dd d!d(d"d$d%d#d)d*d+gZdd,dddddd d!d-d.dd"d#d/gZdd,d0d1d&ddd'd-d.g
Zdddddddd d!d-d.d"gZdd,ddd1ddddd'ddd"gZd2Zd3Zi Zd4d5„ Zd6Zd7Zd8d9„ Zeefd:d;„Zeefd<d=„Z d>d?„ Z!G d@dA„ dAe"ƒZ#G dBdC„ dCe"ƒZ$G dDdE„ dEe"ƒZ%G dFdG„ dGe%e#ƒZ&G dHdI„ dIe%e$ƒZ'ddJlm(Z( e(dKdLƒZ)e(dMdNƒZ*e(dOdPƒZ+e&Z,G dQdK„ dKe)e#ƒZ-G dRdM„ dMe*e&ƒZ.G dSdO„ dOe+e&ƒZ/G dTdU„ dUe)e$ƒZ0G dVdW„ dWe*e'ƒZ1G dXdY„ dYe+e'ƒZ2dZd[„ Z3e3ƒ  [3d”d]d„Z4d^d_„ Z5d•d`da„Z6d–dbd
„Z7dcd„ Z8ddd„ Z9d—ded„Z:dfd	„ Z;dgZ<edhdi„ e<D ƒƒZ=djd„ Z>ej?dkƒZ@d˜dnd„ZAd™dpd„ZBdšdqd„ZCd›drd„ZDeEedsƒƒZFeeFƒZGi ZHG dtdu„ duejIƒZJdœdwd„ZKd�dxd„ZLdždyd„ZMdŸdzd„ZNd{d|„ ZOd}d~„ ZPdaQdd€„ ZRdaSd�d‚„ ZTdaUdƒd„„ ZVdaWd…d†„ ZXdaYd‡dˆ„ ZZda[d¡dŠd‹„Z\da]dŒd�„ Z^da_dŽd�„ Z`d�d‘„ Zadabd’d“„ ZcdS )¢a¦  
Ported using Python-Future from the Python 3.3 standard library.

Parse (absolute and relative) URLs.

urlparse module is based upon the following RFC specifications.

RFC 3986 (STD66): "Uniform Resource Identifiers" by T. Berners-Lee, R. Fielding
and L.  Masinter, January 2005.

RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter
and L.Masinter, December 1999.

RFC 2396:  "Uniform Resource Identifiers (URI)": Generic Syntax by T.
Berners-Lee, R. Fielding, and L. Masinter, August 1998.

RFC 2368: "The mailto URL scheme", by P.Hoffman , L Masinter, J. Zawinski, July 1998.

RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, UC Irvine, June
1995.

RFC 1738: "Uniform Resource Locators (URL)" by T. Berners-Lee, L. Masinter, M.
McCahill, December 1994

RFC 3986 is considered the current standard and any future changes to
urlparse module should conform with it.  The urlparse module is
currently not entirely compliant with this RFC due to defacto
scenarios for parsing, and for backward compatibility purposes, some
parsing quirks from older RFCs are retained. The testcases in
test_urlparse.py provides a good indicator of parsing behavior.
é    )Úabsolute_importÚdivisionÚunicode_literals)ÚbytesÚchrÚdictÚintÚrangeÚstr)Úraise_with_tracebackNÚurlparseÚ
urlunparseÚurljoinÚ	urldefragÚurlsplitÚ
urlunsplitÚ	urlencodeÚparse_qsÚ	parse_qslÚquoteÚ
quote_plusÚquote_from_bytesÚunquoteÚunquote_plusÚunquote_to_bytesÚftpÚhttpÚgopherÚnntpÚimapÚwaisÚfileÚhttpsÚshttpÚmmsÚprosperoÚrtspÚrtspuÚ ÚsftpÚsvnzsvn+sshÚtelnetÚsnewsÚrsyncÚnfsÚgitzgit+sshÚhdlÚsipÚsipsÚtelÚmailtoÚnewszAabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-.é   c               C   s   t jƒ  tjƒ  dS )z,Clear the parse cache and the quoters cache.N)Ú_parse_cacheÚclearÚ_safe_quoters© r:   r:   ú?/tmp/pip-build-6m2fasei/future/future/backports/urllib/parse.pyÚclear_cacheN   s    r<   ÚasciiÚstrictc             C   s   | S )Nr:   )Úobjr:   r:   r;   Ú_noop]   s    r@   c             C   s   | j ||ƒS )N)Úencode)r?   ÚencodingÚerrorsr:   r:   r;   Ú_encode_result`   s    rD   c                s   t ‡ ‡fdd„| D ƒƒS )Nc             3   s"   | ]}|r|j ˆ ˆƒnd V  qdS )r(   N)Údecode)Ú.0Úx)rB   rC   r:   r;   ú	<genexpr>f   s    z_decode_args.<locals>.<genexpr>)Útuple)ÚargsrB   rC   r:   )rB   rC   r;   Ú_decode_argsd   s    rK   c              G   sZ   t | d tƒ}x.| dd … D ]}|rt |tƒ|krtdƒ‚qW |rL| tf S t| ƒtf S )Nr   é   z$Cannot mix str and non-str arguments)Ú
isinstancer
   Ú	TypeErrorr@   rK   rD   )rJ   Ú	str_inputÚargr:   r:   r;   Ú_coerce_argsh   s    
rQ   c               @   s   e Zd ZdZf Zddd„ZdS )Ú_ResultMixinStrz>Standard approach to encoding parsed results from str to bytesr=   r>   c                s   | j ‡ ‡fdd„| D ƒŽ S )Nc             3   s   | ]}|j ˆ ˆƒV  qd S )N)rA   )rF   rG   )rB   rC   r:   r;   rH   ~   s    z)_ResultMixinStr.encode.<locals>.<genexpr>)Ú_encoded_counterpart)ÚselfrB   rC   r:   )rB   rC   r;   rA   }   s    z_ResultMixinStr.encodeN)r=   r>   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__rA   r:   r:   r:   r;   rR   y   s   rR   c               @   s   e Zd ZdZf Zddd„ZdS )Ú_ResultMixinBytesz>Standard approach to decoding parsed results from bytes to strr=   r>   c                s   | j ‡ ‡fdd„| D ƒŽ S )Nc             3   s   | ]}|j ˆ ˆƒV  qd S )N)rE   )rF   rG   )rB   rC   r:   r;   rH   †   s    z+_ResultMixinBytes.decode.<locals>.<genexpr>)Ú_decoded_counterpart)rT   rB   rC   r:   )rB   rC   r;   rE   …   s    z_ResultMixinBytes.decodeN)r=   r>   )rU   rV   rW   rX   rY   rE   r:   r:   r:   r;   rZ   �   s   rZ   c               @   sD   e Zd ZdZf Zedd„ ƒZedd„ ƒZedd„ ƒZedd	„ ƒZ	d
S )Ú_NetlocResultMixinBasezHShared methods for the parsed result objects containing a netloc elementc             C   s
   | j d S )Nr   )Ú	_userinfo)rT   r:   r:   r;   Úusername�   s    z_NetlocResultMixinBase.usernamec             C   s
   | j d S )NrL   )r]   )rT   r:   r:   r;   Úpassword‘   s    z_NetlocResultMixinBase.passwordc             C   s(   | j d }|sd }n|d k	r$|jƒ }|S )Nr   )Ú	_hostinfoÚlower)rT   Úhostnamer:   r:   r;   rb   •   s    
z_NetlocResultMixinBase.hostnamec             C   s<   | j d }|d k	r8t|dƒ}d|  ko.dkn  s8d S |S )NrL   é
   r   iÿÿ  )r`   r   )rT   Úportr:   r:   r;   rd   ž   s    

z_NetlocResultMixinBase.portN)
rU   rV   rW   rX   rY   Úpropertyr^   r_   rb   rd   r:   r:   r:   r;   r\   ‰   s   	r\   c               @   s(   e Zd Zf Zedd„ ƒZedd„ ƒZdS )Ú_NetlocResultMixinStrc             C   sD   | j }|jdƒ\}}}|r4|jdƒ\}}}|s<d }nd  }}||fS )Nú@ú:)ÚnetlocÚ
rpartitionÚ	partition)rT   ri   ÚuserinfoÚ	have_infoÚhostinfor^   Úhave_passwordr_   r:   r:   r;   r]   ¬   s    z_NetlocResultMixinStr._userinfoc       	      C   sl   | j }|jdƒ\}}}|jdƒ\}}}|rL|jdƒ\}}}|jdƒ\}}}n|jdƒ\}}}|sdd }||fS )Nrg   ú[ú]rh   )ri   rj   rk   )	rT   ri   Ú_rn   Úhave_open_brÚ	bracketedrb   rd   Ú	have_portr:   r:   r;   r`   ¸   s    z_NetlocResultMixinStr._hostinfoN)rU   rV   rW   rY   re   r]   r`   r:   r:   r:   r;   rf   ©   s   rf   c               @   s(   e Zd Zf Zedd„ ƒZedd„ ƒZdS )Ú_NetlocResultMixinBytesc             C   sD   | j }|jdƒ\}}}|r4|jdƒ\}}}|s<d }nd  }}||fS )Nó   @ó   :)ri   rj   rk   )rT   ri   rl   rm   rn   r^   ro   r_   r:   r:   r;   r]   Ê   s    z!_NetlocResultMixinBytes._userinfoc       	      C   sl   | j }|jdƒ\}}}|jdƒ\}}}|rL|jdƒ\}}}|jdƒ\}}}n|jdƒ\}}}|sdd }||fS )Nrw   ó   [ó   ]rx   )ri   rj   rk   )	rT   ri   rr   rn   rs   rt   rb   rd   ru   r:   r:   r;   r`   Ö   s    z!_NetlocResultMixinBytes._hostinfoN)rU   rV   rW   rY   re   r]   r`   r:   r:   r:   r;   rv   Ç   s   rv   )Ú
namedtupleÚDefragResultzurl fragmentÚSplitResultz!scheme netloc path query fragmentÚParseResultz(scheme netloc path params query fragmentc               @   s   e Zd Zf Zdd„ ZdS )r|   c             C   s    | j r| jd | j  S | jS d S )Nú#)ÚfragmentÚurl)rT   r:   r:   r;   Úgeturló   s    zDefragResult.geturlN)rU   rV   rW   rY   r‚   r:   r:   r:   r;   r|   ñ   s   c               @   s   e Zd Zf Zdd„ ZdS )r}   c             C   s   t | ƒS )N)r   )rT   r:   r:   r;   r‚   û   s    zSplitResult.geturlN)rU   rV   rW   rY   r‚   r:   r:   r:   r;   r}   ù   s   c               @   s   e Zd Zf Zdd„ ZdS )r~   c             C   s   t | ƒS )N)r   )rT   r:   r:   r;   r‚      s    zParseResult.geturlN)rU   rV   rW   rY   r‚   r:   r:   r:   r;   r~   þ   s   c               @   s   e Zd Zf Zdd„ ZdS )ÚDefragResultBytesc             C   s    | j r| jd | j  S | jS d S )Nó   #)r€   r�   )rT   r:   r:   r;   r‚     s    zDefragResultBytes.geturlN)rU   rV   rW   rY   r‚   r:   r:   r:   r;   rƒ     s   rƒ   c               @   s   e Zd Zf Zdd„ ZdS )ÚSplitResultBytesc             C   s   t | ƒS )N)r   )rT   r:   r:   r;   r‚     s    zSplitResultBytes.geturlN)rU   rV   rW   rY   r‚   r:   r:   r:   r;   r…     s   r…   c               @   s   e Zd Zf Zdd„ ZdS )ÚParseResultBytesc             C   s   t | ƒS )N)r   )rT   r:   r:   r;   r‚     s    zParseResultBytes.geturlN)rU   rV   rW   rY   r‚   r:   r:   r:   r;   r†     s   r†   c              C   s8   t tfttfttff} x| D ]\}}||_||_qW d S )N)r|   rƒ   r}   r…   r~   r†   rS   r[   )Z_result_pairsZ_decodedZ_encodedr:   r:   r;   Ú_fix_result_transcoding  s    
r‡   Tc       
      C   sf   t | |ƒ\} }}t| ||ƒ}|\}}} }}|tkrHd| krHt| ƒ\} }nd}t||| |||ƒ}	||	ƒS )a#  Parse a URL into 6 components:
    <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
    Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
    Note that we don't break the components up in smaller bits
    (e.g. netloc is a single string) and we don't expand % escapes.ú;r(   )rQ   r   Úuses_paramsÚ_splitparamsr~   )
r�   ÚschemeÚallow_fragmentsÚ_coerce_resultÚsplitresultri   Úqueryr€   ÚparamsÚresultr:   r:   r;   r   $  s    c             C   sR   d| kr,| j d| jdƒƒ}|dk r6| dfS n
| j dƒ}| d |… | |d d … fS )Nú/rˆ   r   r(   rL   )ÚfindÚrfind)r�   Úir:   r:   r;   rŠ   4  s    

rŠ   c             C   sL   t | ƒ}x*dD ]"}| j||ƒ}|dkrt||ƒ}qW | ||… | |d … fS )Nz/?#r   )Úlenr“   Úmin)r�   ÚstartÚdelimÚcÚwdelimr:   r:   r;   Ú_splitnetloc=  s    
rœ   c             C   sX  t | |ƒ\} }}t|ƒ}| ||t| ƒt|ƒf}tj|dƒ}|rF||ƒS ttƒtkrXtƒ  d } }}| jdƒ}	|	dk�r®| d|	… dk�rH| d|	… j	ƒ }| |	d d… } | dd… dkrðt
| dƒ\}} d	|krØd
|ksèd
|krðd	|krðtdƒ‚|oúd| k�r| jddƒ\} }d| k�r(| jddƒ\} }t||| ||ƒ}
|
t|< ||
ƒS xd| d|	… D ]}|tk�rVP �qVW | |	d d… }| �s˜tdd„ |D ƒƒ�r®| d|	… j	ƒ | }} | dd… dk�rþt
| dƒ\}} d	|k�râd
|k�söd
|k�rþd	|k�rþtdƒ‚|�rd| k�r| jddƒ\} }d| k�r8| jddƒ\} }t||| ||ƒ}
|
t|< ||
ƒS )a  Parse a URL into 5 components:
    <scheme>://<netloc>/<path>?<query>#<fragment>
    Return a 5-tuple: (scheme, netloc, path, query, fragment).
    Note that we don't break the components up in smaller bits
    (e.g. netloc is a single string) and we don't expand % escapes.Nr(   rh   r   r   rL   é   z//rp   rq   zInvalid IPv6 URLr   ú?c             s   s   | ]}|d kV  qdS )Ú
0123456789Nr:   )rF   rš   r:   r:   r;   rH   l  s    zurlsplit.<locals>.<genexpr>)rQ   ÚboolÚtyper7   Úgetr–   ÚMAX_CACHE_SIZEr<   r“   ra   rœ   Ú
ValueErrorÚsplitr}   Úscheme_charsÚany)r�   r‹   rŒ   r�   ÚkeyÚcachedri   r�   r€   r•   Úvrš   Úrestr:   r:   r;   r   E  sX    




c             C   s<   t | Ž \}}}}}}}|r&d||f }|t|||||fƒƒS )zúPut a parsed URL back together again.  This may result in a
    slightly different, but equivalent URL, if the URL that was parsed
    originally had redundant delimiters, e.g. a ? with an empty query
    (the draft states that these are equivalent).z%s;%s)rQ   r   )Ú
componentsr‹   ri   r�   r�   r�   r€   r�   r:   r:   r;   r   }  s    c             C   s˜   t | Ž \}}}}}}|s4|r`|tkr`|dd… dkr`|rP|dd… dkrPd| }d|pXd | }|rp|d | }|r€|d | }|r�|d	 | }||ƒS )
ak  Combine the elements of a tuple as returned by urlsplit() into a
    complete URL as a string. The data argument can be any five-item iterable.
    This may result in a slightly different, but equivalent URL, if the URL that
    was parsed originally had unnecessary delimiters (for example, a ? with an
    empty query; the RFC states that these are equivalent).Nr�   z//rL   r’   r(   rh   rž   r   )rQ   Úuses_netloc)r¬   r‹   ri   r�   r�   r€   r�   r:   r:   r;   r   ˆ  s      c             C   s  | s|S |s| S t | |ƒ\} }}t| d|ƒ\}}}}}}	t|||ƒ\}
}}}}}|
|ks`|
tkrh||ƒS |
tkr�|rŒ|t|
|||||fƒƒS |}|dd… dkr¸|t|
|||||fƒƒS | rì| rì|}|}|sÔ|}|t|
|||||fƒƒS |jdƒdd… |jdƒ }|d	 dk�rd|d
< xd|k�r8|jdƒ �q W xfd}t|ƒd }xN||k �r˜|| dk�rŒ||d  dk�rŒ||d |d …= P |d }�qNW P �q<W |ddgk�rºd|d< n*t|ƒdk�rä|d dk�rädg|dd…< |t|
|dj|ƒ|||fƒƒS )zaJoin a base URL and a possibly relative URL to form an absolute
    interpretation of the latter.r(   NrL   r’   Ú.ú..r�   éÿÿÿÿr°   r°   )r(   r¯   r°   r°   éþÿÿÿ)	rQ   r   Úuses_relativer­   r   r¥   Úremover–   Újoin)Úbaser�   rŒ   r�   ÚbschemeÚbnetlocÚbpathÚbparamsÚbqueryÚ	bfragmentr‹   ri   Úpathr�   r�   r€   Úsegmentsr•   Únr:   r:   r;   r   ›  sZ    



c       	      C   sT   t | ƒ\} }d| kr>t| ƒ\}}}}}}t|||||dfƒ}nd}| }|t||ƒƒS )z¿Removes any existing fragment from URL.

    Returns a tuple of the defragmented URL and the fragment.  If
    the URL contained no fragments, the second element is the
    empty string.
    r   r(   )rQ   r   r   r|   )	r�   r�   Úsr¾   ÚpÚaÚqÚfragÚdefragr:   r:   r;   r   Ð  s    Ú0123456789ABCDEFabcdefc             c   s8   | ]0}t D ]&}|| jƒ tt|| d ƒgƒfV  q
qdS )é   N)Ú_hexdigrA   r   r   )rF   rÁ   Úbr:   r:   r;   rH   á  s   rH   c             C   sÊ   | s| j  tdƒS t| tƒr&| jdƒ} t| ƒ} | j dƒ}t|ƒdkrH| S |d g}|j}xb|dd… D ]R}y(|t|dd…  ƒ ||dd… ƒ W qf tk
r¶   |dƒ ||ƒ Y qfX qfW tdƒj	|ƒS )z,unquote_to_bytes('abc%20def') -> b'abc def'.ó    zutf-8ó   %rL   r   Nr�   )
r¥   r   rM   r
   rA   r–   ÚappendÚ
_hextobyteÚKeyErrorr´   )ÚstringÚbitsÚresrË   Úitemr:   r:   r;   r   ä  s&    



z([ -]+)úutf-8Úreplacec             C   s�   d| kr| j  | S |dkrd}|dkr*d}tj | ƒ}|d g}|j}x@tdt|ƒdƒD ],}|t|| ƒj||ƒƒ |||d  ƒ qVW dj|ƒS )	a–  Replace %xx escapes by their single-character equivalent. The optional
    encoding and errors parameters specify how to decode percent-encoded
    sequences into Unicode characters, as accepted by the bytes.decode()
    method.
    By default, percent-encoded sequences are decoded with UTF-8, and invalid
    sequences are replaced by a placeholder character.

    unquote('abc%20def') -> 'abc def'.
    ú%Nzutf-8rÓ   r   rL   r�   r(   )r¥   Ú_asciirerË   r	   r–   r   rE   r´   )rÎ   rB   rC   rÏ   rÐ   rË   r•   r:   r:   r;   r     s    


Fc       	      C   sN   i }t | ||||d�}x2|D ]*\}}||kr<|| j|ƒ q|g||< qW |S )aO  Parse a query given as a string argument.

        Arguments:

        qs: percent-encoded query string to be parsed

        keep_blank_values: flag indicating whether blank values in
            percent-encoded queries should be treated as blank strings.
            A true value indicates that blanks should be retained as
            blank strings.  The default false value indicates that
            blank values are to be ignored and treated as if they were
            not included.

        strict_parsing: flag indicating what to do with parsing errors.
            If false (the default), errors are silently ignored.
            If true, errors raise a ValueError exception.

        encoding and errors: specify how to decode percent-encoded sequences
            into Unicode characters, as accepted by the bytes.decode() method.
    )rB   rC   )r   rË   )	ÚqsÚkeep_blank_valuesÚstrict_parsingrB   rC   Úparsed_resultÚpairsÚnameÚvaluer:   r:   r;   r     s    
c             C   sê   t | ƒ\} }dd„ | jdƒD ƒ}g }xÀ|D ]¸}| r<| r<q*|jddƒ}	t|	ƒdkrx|rftd|f ƒ‚|r*|	jdƒ nq*t|	d ƒsˆ|r*|	d	 jd
dƒ}
t|
||d�}
||
ƒ}
|	d jd
dƒ}t|||d�}||ƒ}|j|
|fƒ q*W |S )a;  Parse a query given as a string argument.

    Arguments:

    qs: percent-encoded query string to be parsed

    keep_blank_values: flag indicating whether blank values in
        percent-encoded queries should be treated as blank strings.  A
        true value indicates that blanks should be retained as blank
        strings.  The default false value indicates that blank values
        are to be ignored and treated as if they were  not included.

    strict_parsing: flag indicating what to do with parsing errors. If
        false (the default), errors are silently ignored. If true,
        errors raise a ValueError exception.

    encoding and errors: specify how to decode percent-encoded sequences
        into Unicode characters, as accepted by the bytes.decode() method.

    Returns a list, as G-d intended.
    c             S   s    g | ]}|j d ƒD ]}|‘qqS )rˆ   )r¥   )rF   Ús1Ús2r:   r:   r;   ú
<listcomp>T  s    zparse_qsl.<locals>.<listcomp>ú&ú=rL   r�   zbad query field: %rr(   r   ú+ú )rB   rC   )rQ   r¥   r–   r¤   rË   rÓ   r   )rÖ   r×   rØ   rB   rC   r�   rÚ   ÚrÚ
name_valueÚnvrÛ   rÜ   r:   r:   r;   r   <  s,    
c             C   s   | j ddƒ} t| ||ƒS )z›Like unquote(), but also replace plus signs by spaces, as required for
    unquoting HTML form values.

    unquote_plus('%7e/abc+def') -> '~/abc def'
    râ   rã   )rÓ   r   )rÎ   rB   rC   r:   r:   r;   r   l  s    sA   ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚQuoterzÌA mapping from bytes (in range(0,256)) to strings.

    String values are percent-encoded byte values, unless the key < 128, and
    in the "safe" set (either the specified safe set, or default set).
    c             C   s   t jt|ƒƒ| _dS )zsafe: bytes object.N)Ú_ALWAYS_SAFEÚunionr   Úsafe)rT   rê   r:   r:   r;   Ú__init__„  s    zQuoter.__init__c             C   s   dt | ƒ S )Nz<Quoter %r>)r   )rT   r:   r:   r;   Ú__repr__ˆ  s    zQuoter.__repr__c             C   s(   || j krt|ƒndj|ƒ}|| |< |S )Nz%{0:02X})rê   r   Úformat)rT   rÈ   rÐ   r:   r:   r;   Ú__missing__Œ  s    zQuoter.__missing__N)rU   rV   rW   rX   rë   rì   rî   r:   r:   r:   r;   rç   |  s   rç   r’   c             C   sb   t | tƒr8| s| S |dkrd}|dkr*d}| j||ƒ} n |dk	rHtdƒ‚|dk	rXtdƒ‚t| |ƒS )a˜  quote('abc def') -> 'abc%20def'

    Each part of a URL, e.g. the path info, the query, etc., has a
    different set of reserved characters that must be quoted.

    RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists
    the following reserved characters.

    reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                  "$" | ","

    Each of these characters is reserved in some component of a URL,
    but not necessarily in all of them.

    By default, the quote function is intended for quoting the path
    section of a URL.  Thus, it will not encode '/'.  This character
    is reserved, but in typical usage the quote function is being
    called on a path where the existing slash characters are used as
    reserved characters.

    string and safe may be either str or bytes objects. encoding must
    not be specified if string is a str.

    The optional encoding and errors parameters specify how to deal with
    non-ASCII characters, as accepted by the str.encode method.
    By default, encoding='utf-8' (characters are encoded with UTF-8), and
    errors='strict' (unsupported characters raise a UnicodeEncodeError).
    Nzutf-8r>   z,quote() doesn't support 'encoding' for bytesz*quote() doesn't support 'errors' for bytes)rM   r
   rA   rN   r   )rÎ   rê   rB   rC   r:   r:   r;   r   ’  s    
c             C   sl   t | tƒrd| ks$t | tƒr2d| kr2t| |||ƒS t |tƒrFtdƒ}ntdƒ}t| || ||ƒ} | jddƒS )zÞLike quote(), but also replace ' ' with '+', as required for quoting
    HTML form values. Plus signs in the original string are escaped unless
    they are included in safe. It also does not have safe default to '/'.
    rã   ó    râ   )rM   r
   r   r   rÓ   )rÎ   rê   rB   rC   Úspacer:   r:   r;   r   ¾  s    

c                sÆ   t | ttfƒstdƒ‚| s"tdƒS t| ƒ} t |tƒrFt|ƒjddƒ}nt|ƒ}tdd„ |D ƒƒ}| jt| ƒsv| jƒ S yt	| ‰ W n& t
k
r¨   t|ƒj t	|< ‰ Y nX tdƒj‡ fdd„| D ƒƒS )zËLike quote(), but accepts a bytes object rather than a str, and does
    not perform string-to-bytes encoding.  It always returns an ASCII string.
    quote_from_bytes(b'abc def?') -> 'abc%20def%3f'
    z!quote_from_bytes() expected bytesr(   r=   Úignorec             S   s   g | ]}|d k r|‘qS )é€   r:   )rF   rš   r:   r:   r;   rß   â  s    z$quote_from_bytes.<locals>.<listcomp>c                s   g | ]}ˆ |ƒ‘qS r:   r:   )rF   Úchar)Úquoterr:   r;   rß   é  s    )rM   r   Ú	bytearrayrN   r
   rA   ÚrstripÚ_ALWAYS_SAFE_BYTESrE   r9   rÍ   rç   Ú__getitem__r´   )Úbsrê   r:   )rô   r;   r   Ï  s     
c             C   s   t | dƒr| jƒ } nRy t| ƒr2t| d tƒ r2t‚W n0 tk
rd   tjƒ \}}}ttdƒ|ƒ Y nX g }|sæxr| D ]j\}	}
t|	t	ƒr’t
|	|ƒ}	nt
t|	ƒ|||ƒ}	t|
t	ƒrºt
|
|ƒ}
nt
t|
ƒ|||ƒ}
|j|	d |
 ƒ qtW �n,�x(| D �]\}	}
t|	t	ƒ�rt
|	|ƒ}	nt
t|	ƒ|||ƒ}	t|
t	ƒ�rLt
|
|ƒ}
|j|	d |
 ƒ qît|
tƒ�rzt
|
|||ƒ}
|j|	d |
 ƒ qîyt|
ƒ}W n: tk
�rÀ   t
t|
ƒ|||ƒ}
|j|	d |
 ƒ Y qîX xJ|
D ]B}t|t	ƒ�rät
||ƒ}nt
t|ƒ|||ƒ}|j|	d | ƒ �qÈW qîW tdƒj|ƒS )a#  Encode a sequence of two-element tuples or dictionary into a URL query string.

    If any values in the query arg are sequences and doseq is true, each
    sequence element is converted to a separate parameter.

    If the query arg is a sequence of two-element tuples, the order of the
    parameters in the output will match the order of parameters in the
    input.

    The query arg may be either a string or a bytes type. When query arg is a
    string, the safe, encoding and error parameters are sent the quote_plus for
    encoding.
    Úitemsr   z1not a valid non-string sequence or mapping objectrá   rà   )Úhasattrrú   r–   rM   rI   rN   ÚsysÚexc_infor   r   r   r
   rË   r´   )r�   Údoseqrê   rB   rC   ÚtyÚvaÚtbÚlÚkrª   rG   Úeltr:   r:   r;   r   ë  sP    





c             C   sJ   t | tƒrFy| jdƒjƒ } W n( tk
rD   tdt| ƒ d ƒ‚Y nX | S )zto_bytes(u"URL") --> 'URL'.ÚASCIIzURL z contains non-ASCII characters)rM   r
   rA   rE   ÚUnicodeErrorÚrepr)r�   r:   r:   r;   Úto_bytesH  s    
r  c             C   s`   t | ƒjƒ } | dd… dkr<| dd… dkr<| dd… jƒ } | dd… dkr\| dd… jƒ } | S )	z8unwrap('<URL:type://host/path>') --> 'type://host/path'.NrL   ú<ú>é   zURL:r°   r°   )r
   Ústrip)r�   r:   r:   r;   ÚunwrapU  s      r  c             C   sV   t dkrddl}|jdƒa t j| ƒ}|rN|jdƒ}|jƒ | t|ƒd d… fS d| fS )z:splittype('type:opaquestring') --> 'type', 'opaquestring'.Nr   z
^([^/:]+):rL   )Ú	_typeprogÚreÚcompileÚmatchÚgroupra   r–   )r�   r  r  r‹   r:   r:   r;   Ú	splittype^  s    


r  c             C   sd   t dkrddl}|jdƒa t j| ƒ}|r\|jdƒ}|jdƒ}|rT|jdƒ rTd| }||fS d| fS )z;splithost('//host[:port]/path') --> 'host[:port]', '/path'.Nr   z^//([^/?]*)(.*)$rL   r�   r’   )Ú	_hostprogr  r  r  r  Ú
startswith)r�   r  r  Ú	host_portr¼   r:   r:   r;   Ú	splithostl  s    



r  c             C   s<   t dkrddl}|jdƒa t j| ƒ}|r4|jddƒS d| fS )zJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.Nr   z^(.*)@(.*)$rL   r�   )Ú	_userprogr  r  r  r  )Úhostr  r  r:   r:   r;   Ú	splituser}  s    

 r  c             C   s@   t dkrddl}|jd|jƒa t j| ƒ}|r8|jddƒS | dfS )z/splitpasswd('user:passwd') -> 'user', 'passwd'.Nr   z^([^:]*):(.*)$rL   r�   )Ú_passwdprogr  r  ÚSr  r  )Úuserr  r  r:   r:   r;   Úsplitpasswd‰  s    
 r  c             C   s<   t dkrddl}|jdƒa t j| ƒ}|r4|jddƒS | dfS )z*splitport('host:port') --> 'host', 'port'.Nr   z^(.*):([0-9]+)$rL   r�   )Ú	_portprogr  r  r  r  )r  r  r  r:   r:   r;   Ú	splitport–  s    

 r   rL   c             C   sz   t dkrddl}|jdƒa t j| ƒ}|rr|jddƒ\} }y|sFtdƒ‚t|ƒ}W n tk
rh   d}Y nX | |fS | |fS )zÛSplit host and port, returning numeric port.
    Return given default port if no ':' found; defaults to -1.
    Return numerical port if a valid number are found after ':'.
    Return None if ':' but not a valid number.Nr   z^(.*):(.*)$rL   r�   z	no digits)Ú
_nportprogr  r  r  r  r¤   r   )r  Údefportr  r  rd   Únportr:   r:   r;   Ú
splitnport¢  s    

 
r$  c             C   s<   t dkrddl}|jdƒa t j| ƒ}|r4|jddƒS | dfS )z/splitquery('/path?query') --> '/path', 'query'.Nr   z^(.*)\?([^?]*)$rL   r�   )Ú
_queryprogr  r  r  r  )r�   r  r  r:   r:   r;   Ú
splitquery¸  s    

 r&  c             C   s<   t dkrddl}|jdƒa t j| ƒ}|r4|jddƒS | dfS )z)splittag('/path#tag') --> '/path', 'tag'.Nr   z^(.*)#([^#]*)$rL   r�   )Ú_tagprogr  r  r  r  )r�   r  r  r:   r:   r;   ÚsplittagÄ  s    

 r(  c             C   s   | j dƒ}|d |dd… fS )zksplitattr('/path;attr1=value1;attr2=value2;...') ->
        '/path', ['attr1=value1', 'attr2=value2', ...].rˆ   r   rL   N)r¥   )r�   Úwordsr:   r:   r;   Ú	splitattrÏ  s    
r*  c             C   s<   t dkrddl}|jdƒa t j| ƒ}|r4|jddƒS | dfS )z-splitvalue('attr=value') --> 'attr', 'value'.Nr   z^([^=]*)=(.*)$rL   r�   )Ú
_valueprogr  r  r  r  )Úattrr  r  r:   r:   r;   Ú
splitvalueÖ  s    

 r-  )r(   T)r   )r(   T)T)rÒ   rÓ   )FFrÒ   rÓ   )FFrÒ   rÓ   )rÒ   rÓ   )r’   NN)r(   NN)r’   )Fr(   NNr°   )r°   )drX   Ú
__future__r   r   r   Zfuture.builtinsr   r   r   r   r	   r
   Zfuture.utilsr   r  rü   ÚcollectionsÚ__all__r²   r­   r‰   Únon_hierarchicalÚ
uses_queryÚuses_fragmentr¦   r£   r7   r<   Ú_implicit_encodingÚ_implicit_errorsr@   rD   rK   rQ   ÚobjectrR   rZ   r\   rf   rv   r{   Ú_DefragResultBaseÚ_SplitResultBaseÚ_ParseResultBaseÚ
ResultBaser|   r}   r~   rƒ   r…   r†   r‡   r   rŠ   rœ   r   r   r   r   r   rÇ   rÌ   r   r  rÕ   r   r   r   r   Ú	frozensetrè   r÷   r9   Údefaultdictrç   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Ö    








 




	

8
5


 
 
/
	
,


]
