U
    ÌZjøŽ  ã                
   @   s8  U d Z ddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ ejrtdd	lmZ e d
¡ZeedƒƒZdZdd„ eD ƒZdd„ edƒD ƒZG dd„ dejƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZeƒ eiZejej e! eje"e!f f e#d< dlej$e%e"f ej$e%e"f e"dœdd„Z&ej$ej'e%e%f ej(ej)e%e%f  f e%e*ej+ej,ej)e%e%f gej-f  ej.e% dœd d!„Z/dme%e%e%d"œd#d$„Z0dne%ej+e% e*ed&œd'd(„Z1doe%e%ej$e%e"f ej$e%e"f ej,e"ge%f d,œd-d.„Z2e2ƒ Z3e2d/d0d1�Z4e"e%d2œd3d4„Z5dpej$e%e"f e%e%ej$e%e"f ej$e%e"f e%d5œd6d7„Z6dqe%e%e%e%e%d8œd9d:„Z7ej)e%e%e%e%e%f e%d;œd<d=„Z8drej$e%e"f e%e%e%e%d?œd@dA„Z9dsej$e%e"f e%e%e%dBœdCdD„Z:dte%e%e%dEœdFdG„Z;d <dHd„ edIƒD ƒ¡Z=e>ej)e%e!f dJœdKdL„Z?e @dMe?¡ duej$e%ej)e%e%e%e%e%f f e%e%e%dNœdOdP„ZAdQZBdvej$e%ej)e%e%e%e%e%f f e%e%e*e%dSœdTdU„ZCdwejDe%e*e%e%ej+ejEdW  dXdYœdZd[„ZFdxejGe" e%e*e%e"ej+ejEdW  ej+e! dXd]œd^d_„ZHej(ejD e%e*e%ej.ej)e%e%f  d`œdadb„ZIdyej$ej'e%e%f ej(ej)e%e%f  f e%e*ej+ej,ej)e%e%f gej-f  e%e%dcœddde„ZJdzej$ej'e%e%f ej(ej)e%e%f  f ej+ejGe%  e%e*ej+ej,ej)e%e%f gej-f  e%ddfœdgdh„ZKd{ej$e%ej)e%e%e%e%e%f f ej$e%ej)e%e%e%e%e%f f e*e%diœdjdk„ZLdS )|z€Functions for working with URLs.

Contains implementations of functions from :mod:`urllib.parse` that
handle bytes and strings.
é    Né   )Ú_check_str_tuple)Ú_decode_idna)Ú_encode_idna)Ú_make_encode_wrapper)Ú_to_str)Údatastructuresz^[a-zA-Z0-9+-.]+$sK   abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~$!'()*+,;Ú0123456789ABCDEFabcdefc                 C   s8   i | ]0}t D ]&}|› |› � d ¡t|› |› �dƒ“qqS )Úasciié   )Ú
_hexdigitsÚencodeÚint)Ú.0ÚaÚb© r   úP/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/werkzeug/urls.pyÚ
<dictcomp>#   s
    þ r   c                 C   s   g | ]}d |d›�  d¡‘qS )ú%Ú02Xr
   )r   )r   Úcharr   r   r   Ú
<listcomp>(   s     r   é   c                   @   s6   e Zd ZU eed< eed< eed< eed< eed< dS )Ú	_URLTupleÚschemeÚnetlocÚpathÚqueryÚfragmentN)Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__r   r   r   r   r   +   s
   
r   c                   @   s  e Zd ZU dZdZeed< eed< eed< eed< edœdd	„Zej	d d
œdd„Z
eeje dœdd„ƒZeeje dœdd„ƒZeeje dœdd„ƒZeeje dœdd„ƒZeeje dœdd„ƒZeeje dœdd„ƒZeeje dœdd„ƒZeeje dœdd„ƒZej	ej	ddœdd „Zej	ej	d dœd!d"„Zedœd#d$„Zedœd%d&„Zedœd'd(„Zd dœd)d*„Zd dœd+d,„Zd7eje ejeje eje f d.œd/d0„Zejeje ef dœd1d2„Zejeje eje f dœd3d4„Z ejeje eje f dœd5d6„Z!d-S )8ÚBaseURLz7Superclass of :py:class:`URL` and :py:class:`BytesURL`.r   Ú_atÚ_colonÚ	_lbracketÚ	_rbracket©Úreturnc                 C   s   |   ¡ S ©N)Úto_url©Úselfr   r   r   Ú__str__<   s    zBaseURL.__str__)Úkwargsr+   c                 K   s   | j f |ŽS )z†Return an URL with the same values, except for those parameters
        given new values by whichever keyword arguments are specified.)Ú_replace)r/   r1   r   r   r   Úreplace?   s    zBaseURL.replacec                 C   s   |   ¡ d S )z¹The host part of the URL if available, otherwise `None`.  The
        host is either the hostname or the IP address mentioned in the
        URL.  It will not contain the port.
        r   )Ú_split_hostr.   r   r   r   ÚhostD   s    zBaseURL.hostc                 C   sR   | j }|dk	rFt|tƒrFzt|ƒ}W n  tk
rD   | dd¡}Y nX t|ddƒS )a   Works exactly like :attr:`host` but will return a result that
        is restricted to ASCII.  If it finds a netloc that is not ASCII
        it will attempt to idna decode it.  This is useful for socket
        operations when the URL might include internationalized characters.
        Nr
   Úignore)r5   Ú
isinstancer#   r   ÚUnicodeErrorr   r   ©r/   Úrvr   r   r   Ú
ascii_hostL   s    zBaseURL.ascii_hostc              	   C   sT   z6t t|  ¡ d ƒƒ}d|  kr*dkr4n n|W S W n ttfk
rN   Y nX dS )z}The port in the URL as an integer if it was present, `None`
        otherwise.  This does not fill in default ports.
        r   r   iÿÿ  N)r   r   r4   Ú
ValueErrorÚ	TypeErrorr9   r   r   r   Úport[   s    
zBaseURL.portc                 C   s   |   ¡ d S )zSThe authentication part in the URL if available, `None`
        otherwise.
        r   )Ú_split_netlocr.   r   r   r   Úauthh   s    zBaseURL.authc                 C   s    |   ¡ d }|dk	rt|ƒS dS )zƒThe username if it was part of the URL, `None` otherwise.
        This undergoes URL decoding and will always be a string.
        r   N©Ú_split_authÚ_url_unquote_legacyr9   r   r   r   Úusernameo   s    zBaseURL.usernamec                 C   s   |   ¡ d S )z�The username if it was part of the URL, `None` otherwise.
        Unlike :attr:`username` this one is not being decoded.
        r   ©rB   r.   r   r   r   Úraw_usernamey   s    zBaseURL.raw_usernamec                 C   s    |   ¡ d }|dk	rt|ƒS dS )zƒThe password if it was part of the URL, `None` otherwise.
        This undergoes URL decoding and will always be a string.
        r   NrA   r9   r   r   r   Úpassword€   s    zBaseURL.passwordc                 C   s   |   ¡ d S )z�The password if it was part of the URL, `None` otherwise.
        Unlike :attr:`password` this one is not being decoded.
        r   rE   r.   r   r   r   Úraw_passwordŠ   s    zBaseURL.raw_passwordúds.MultiDict[str, str])Úargsr1   r+   c                 O   s   t | jf|ž|ŽS )zØDecodes the query part of the URL.  Ths is a shortcut for
        calling :func:`url_decode` on the query argument.  The arguments and
        keyword arguments are forwarded to :func:`url_decode` unchanged.
        )Ú
url_decoder   ©r/   rJ   r1   r   r   r   Údecode_query‘   s    zBaseURL.decode_queryc                 O   s   t t| f|ž|ŽƒS )z©Joins this URL with another one.  This is just a convenience
        function for calling into :meth:`url_join` and then parsing the
        return value again.
        )Ú	url_parseÚurl_joinrL   r   r   r   Újoin˜   s    zBaseURL.joinc                 C   s   t | ƒS )zºReturns a URL string or bytes depending on the type of the
        information stored.  This is just a convenience function
        for calling :meth:`url_unparse` for this URL.
        )Úurl_unparser.   r   r   r   r-   Ÿ   s    zBaseURL.to_urlc              
   C   s„   | j pd}d|krd|› d�}| j}|dk	r:|› d|› �}d tdt| jpLddddƒt| jp^ddddƒgƒ¡}|r€|› d	|› �}|S )
z6Encodes the netloc part to an ASCII safe URL as bytes.Ú ú:ú[ú]Núutf-8Ústrictz/:%ú@)r;   r>   rP   ÚfilterÚ	url_quoterF   rH   ©r/   r:   r>   r@   r   r   r   Úencode_netloc¦   s"    
þþÿ	zBaseURL.encode_netlocc                 C   s€   t | jp
dƒ}d|kr"d|› d�}| j}|dk	r>|› d|› �}d tdt| jpPddƒt| jp^ddƒgƒ¡}|r||› d|› �}|S )z&Decodes the netloc part into a string.rR   rS   rT   rU   Nz/:%@rX   )r   r5   r>   rP   rY   rC   rF   rH   r[   r   r   r   Údecode_netloc»   s"    þþÿ	zBaseURL.decode_netlocc                 C   s   t t| ƒƒS )a*  Returns a :class:`BytesURL` tuple that holds a URI.  This will
        encode all the information in the URL properly to ASCII using the
        rules a web browser would follow.

        It's usually more interesting to directly call :meth:`iri_to_uri` which
        will return a string.
        )rN   Ú
iri_to_urir.   r   r   r   Úto_uri_tupleÑ   s    zBaseURL.to_uri_tuplec                 C   s   t t| ƒƒS )aS  Returns a :class:`URL` tuple that holds a IRI.  This will try
        to decode as much information as possible in the URL without
        losing information similar to how a web browser does it for the
        URL bar.

        It's usually more interesting to directly call :meth:`uri_to_iri` which
        will return a string.
        )rN   Ú
uri_to_irir.   r   r   r   Úto_iri_tupleÛ   s    	zBaseURL.to_iri_tupleN)Ú
pathformatr+   c                 C   s:  | j dkrdS t| jƒ}| jp d}|dkr>tjdkr:d}nd}|dkrø|dd… dkr”|dd	…  ¡ r”|d	d
… dkr”|dd	… › d|d
d… › �}|dd
… dk}ddl}| |¡}|rö|dkrö| 	d¡ 
dd¡}t|ƒd	krê|\}}n|d }d}n,|dk�rddl}| |¡}ntd|›�ƒ‚|dk�r2d}||fS )a@  Returns a tuple with the location of the file in the form
        ``(server, location)``.  If the netloc is empty in the URL or
        points to localhost, it's represented as ``None``.

        The `pathformat` by default is autodetection but needs to be set
        when working with URLs of a specific system.  The supported values
        are ``'windows'`` when working with Windows or DOS paths and
        ``'posix'`` when working with posix paths.

        If the URL does not point to a local file, the server and location
        are both represented as ``None``.

        :param pathformat: The expected format of the path component.
                           Currently ``'windows'`` and ``'posix'`` are
                           supported.  Defaults to ``None`` which is
                           autodetect.
        Úfile©NNNÚntÚwindowsÚposixr   ú/é   é   z|:rS   )z\\\z///r   ú\rR   zInvalid path format )z	127.0.0.1z::1Ú	localhost)r   Úurl_unquoter   r   ÚosÚnameÚisalphaÚntpathÚnormpathÚlstripÚsplitÚlenÚ	posixpathr=   )r/   rb   r   r5   Zwindows_sharerq   Úpartsrv   r   r   r   Úget_file_locationæ   s6    



0



zBaseURL.get_file_locationc                 C   s2   | j | jkr(| j | j ¡\}}}||fS d | jfS r,   )r&   r   Ú	partition)r/   r@   Ú_r   r   r   r   r?   $  s    zBaseURL._split_netlocc                 C   s@   |   ¡ d }|sdS | j|kr&|d fS | | j¡\}}}||fS )Nr   rd   )r?   r'   ry   )r/   r@   rD   rz   rG   r   r   r   rB   *  s    
zBaseURL._split_authc                 C   s¨   |   ¡ d }|sdS | | j¡sL| j|krD| | j¡\}}}||fS |d fS | | j¡}|dk rh|d fS |d|… }||d d … }| | j¡r ||dd … fS |d fS )Nr   rd   r   )r?   Ú
startswithr(   r'   ry   Úfindr)   )r/   r:   r5   rz   r>   ÚidxÚrestr   r   r   r4   4  s     
zBaseURL._split_host)N)"r    r!   r"   Ú__doc__Ú	__slots__r#   r$   r0   ÚtÚAnyr3   ÚpropertyÚOptionalr5   r;   r   r>   r@   rD   rF   rG   rH   rM   rP   r-   r\   r]   r_   ra   ÚTuplerx   r?   rB   r4   r   r   r   r   r%   3   sN   
		
 ÿþ>$
r%   c                   @   s8   e Zd ZdZdZdZdZdZdZde	e	d	d
œdd„Z
dS )ÚURLz“Represents a parsed URL.  This behaves like a regular tuple but
    also has some extra attributes that give further insight into the
    URL.
    r   rX   rS   rT   rU   rV   r3   ÚBytesURL©ÚcharsetÚerrorsr+   c              	   C   s:   t | j d¡|  ¡ | j ||¡| j ||¡| j ||¡ƒS )z€Encodes the URL to a tuple made out of bytes.  The charset is
        only being used for the path, query and fragment.
        r
   )r‡   r   r   r\   r   r   r   ©r/   r‰   rŠ   r   r   r   r   V  s    
ûz
URL.encodeN)rV   r3   )r    r!   r"   r   r€   r&   r'   r(   r)   r#   r   r   r   r   r   r†   J  s   r†   c                   @   sT   e Zd ZdZdZdZdZdZdZe	dœdd	„Z
edœd
d„Zde	e	ddœdd„ZdS )r‡   z!Represents a parsed URL in bytes.r   ó   @ó   :ó   [ó   ]r*   c                 C   s   |   ¡  dd¡S )NrV   r3   )r-   Údecoder.   r   r   r   r0   l  s    zBytesURL.__str__c                 C   s   | j S )z&Returns the netloc unchanged as bytes.)r   r.   r   r   r   r\   o  s    zBytesURL.encode_netlocrV   r3   r†   rˆ   c              	   C   s:   t | j d¡|  ¡ | j ||¡| j ||¡| j ||¡ƒS )z‚Decodes the URL to a tuple made out of strings.  The charset is
        only being used for the path, query and fragment.
        r
   )r†   r   r�   r]   r   r   r   r‹   r   r   r   r�   s  s    
ûzBytesURL.decodeN)rV   r3   )r    r!   r"   r   r€   r&   r'   r(   r)   r#   r0   Úbytesr\   r�   r   r   r   r   r‡   c  s   r‡   Ú_unquote_mapsrR   )ÚstringÚunsafer+   c                    sì   t | tƒr|  d¡} t ˆ tƒr(ˆ  d¡‰ ttˆ ƒƒ‰ t|  d¡ƒ}tt|dƒƒ}ztˆ  }W n2 t	k
rŽ   ‡ fdd„t
 ¡ D ƒ }tˆ < Y nX |D ]N}|d d… }||krÎ| || ¡ | |dd … ¡ q”| d¡ | |¡ q”t|ƒS )NrV   ó   %ó    c                    s   i | ]\}}|ˆ kr||“qS r   r   )r   Úhr   ©r”   r   r   r   “  s      z%_unquote_to_bytes.<locals>.<dictcomp>ri   é%   )r7   r#   r   Ú	frozensetÚ	bytearrayÚiterrt   Únextr’   ÚKeyErrorÚ
_hextobyteÚitemsÚappendÚextendr‘   )r“   r”   ÚgroupsÚresultZhex_to_byteÚgroupÚcoder   r˜   r   Ú_unquote_to_bytesƒ  s*    




ÿ
r§   )Úobjr‰   ÚsortÚkeyr+   c           
      c   s”   ddl m} || ƒ}|r$t||d�}|D ]f\}}|d kr:q(t|tƒsTt|ƒ |¡}n|}t|tƒsrt|ƒ |¡}	n|}	t|ƒ› dt|	ƒ› �V  q(d S )Nr   )Úiter_multi_items)rª   ú=)r   r«   Úsortedr7   r‘   r#   r   Ú_fast_url_quote_plus)
r¨   r‰   r©   rª   r«   ÚiterableZkey_strZ	value_strÚ	key_bytesZvalue_bytesr   r   r   Ú_url_encode_impl¤  s    

r±   )Úvaluer”   r+   c                 C   s:   zt | dd|d�W S  tk
r4   t | d|d� Y S X d S )NrV   rW   )r‰   rŠ   r”   Úlatin1)r‰   r”   )rm   r8   )r²   r”   r   r   r   rC   Â  s    rC   T)Úurlr   Úallow_fragmentsr+   c                    s®  t | ƒ‰ t| tƒ}|dkr"ˆ dƒ}ˆ dƒ } }}|  ˆ dƒ¡}|dkr¢t t| d|… dd�¡r¢| |d d… }|rŒt‡ fdd	„|D ƒƒr¢| d|…  ¡ | }} | dd
… ˆ dƒk�rFt	| ƒ}	ˆ dƒD ]"}
|  |
d
¡}|dkrÈt
|	|ƒ}	qÈ| d
|	… | |	d…  }} ˆ dƒ|k�r"ˆ dƒ|k�s>ˆ dƒ|k�rFˆ dƒ|k�rFtdƒ‚|�rnˆ dƒ| k�rn|  ˆ dƒd¡\} }ˆ dƒ| k�r�|  ˆ dƒd¡\} }|�rštnt}|||| ||ƒS )a  Parses a URL from a string into a :class:`URL` tuple.  If the URL
    is lacking a scheme it can be provided as second argument. Otherwise,
    it is ignored.  Optionally fragments can be stripped from the URL
    by setting `allow_fragments` to `False`.

    The inverse of this function is :func:`url_unparse`.

    :param url: the URL to parse.
    :param scheme: the default schema to use if the URL is schemaless.
    :param allow_fragments: if set to `False` a fragment will be removed
                            from the URL.
    NrR   rS   r   r3   )rŠ   r   c                 3   s   | ]}|ˆ d ƒkV  qdS )Ú
0123456789Nr   ©r   Úc©Úsr   r   Ú	<genexpr>ã  s     zurl_parse.<locals>.<genexpr>ri   ú//z/?#rT   rU   zInvalid IPv6 URLú#ú?)r   r7   r#   r|   Ú
_scheme_reÚmatchr   ÚanyÚlowerru   Úminr<   rt   r†   r‡   )r´   r   rµ   Zis_text_basedr   r   r   Úir~   Údelimr¸   ÚwdelimZresult_typer   r¹   r   rN   É  s:    
"
ÿ
ÿrN   rV   rW   ú/:)r‰   rŠ   Úsafer”   r+   c                    sv   t ˆ tƒrˆ  | |¡‰ t |tƒr,| | |¡}ttˆ ƒƒtB tt|ƒƒ ‰ ‡ fdd„tdƒD ƒ‰ttdœ‡fdd„}|S )a£  Precompile the translation table for a URL encoding function.

    Unlike :func:`url_quote`, the generated function only takes the
    string to quote.

    :param charset: The charset to encode the result with.
    :param errors: How to handle encoding errors.
    :param safe: An optional sequence of safe characters to never encode.
    :param unsafe: An optional sequence of unsafe characters to always encode.
    c                    s(   g | ] }|ˆ krt |ƒn
d |d›�‘qS )r   r   )Úchrr·   ©rÈ   r   r   r     s     z(_make_fast_url_quote.<locals>.<listcomp>r   ©r“   r+   c                    s   d  ‡ fdd„| D ƒ¡S )NrR   c                    s   g | ]}ˆ | ‘qS r   r   r·   ©Útabler   r   r     s     z7_make_fast_url_quote.<locals>.quote.<locals>.<listcomp>)rP   ©r“   rÌ   r   r   Úquote  s    z#_make_fast_url_quote.<locals>.quote)r7   r#   r   rš   r›   Ú_always_safeÚranger‘   )r‰   rŠ   rÈ   r”   rÏ   r   )rÈ   rÍ   r   Ú_make_fast_url_quoteü  s    

rÒ   ú ú+)rÈ   r”   rË   c                 C   s   t | ƒ dd¡S )NrÓ   rÔ   )Ú_fast_quote_plusr3   rÎ   r   r   r   r®     s    r®   )r“   r‰   rŠ   rÈ   r”   r+   c                 C   sº   t | tttfƒst| ƒ} t | tƒr.|  ||¡} t |tƒrD| ||¡}t |tƒrZ| ||¡}tt|ƒƒtB tt|ƒƒ }tƒ }t| ƒD ]&}||krœ| |¡ q„| t	| ¡ q„t|ƒ 
|¡S )aD  URL encode a single string with a given encoding.

    :param s: the string to quote.
    :param charset: the charset to be used.
    :param safe: an optional sequence of safe characters.
    :param unsafe: an optional sequence of unsafe characters.

    .. versionadded:: 0.9.2
       The `unsafe` parameter was added.
    )r7   r#   r‘   r›   r   rš   rÐ   r¡   r¢   Ú
_bytetohexr�   )r“   r‰   rŠ   rÈ   r”   r:   r   r   r   r   rZ   #  s    


rZ   )r“   r‰   rŠ   rÈ   r+   c                 C   s   t | |||d dƒ dd¡S )zäURL encode a single string with the given encoding and convert
    whitespace to "+".

    :param s: The string to quote.
    :param charset: The charset to be used.
    :param safe: An optional sequence of safe characters.
    rÓ   rÔ   )rZ   r3   )r“   r‰   rŠ   rÈ   r   r   r   Úurl_quote_plusF  s    
r×   )Ú
componentsr+   c                 C   sÆ   t | ƒ | \}}}}}t|ƒ}|dƒ}|s<|rz| |dƒ¡rz|r`|dd… |dƒkr`|dƒ| }|dƒ|pp|dƒ | }n|r†||7 }|rš||dƒ | }|r®||dƒ | }|rÂ||dƒ | }|S )	zþThe reverse operation to :meth:`url_parse`.  This accepts arbitrary
    as well as :class:`URL` tuples and returns a URL as a string.

    :param components: the parsed URL as tuple which should be converted
                       into a URL string.
    rR   rh   Nr   r¼   rS   r¾   r½   )r   r   r{   )rØ   r   r   r   r   r   rº   r´   r   r   r   rQ   S  s"    rQ   r3   )rº   r‰   rŠ   r”   r+   c                 C   s"   t | |ƒ}|dkr|S | ||¡S )af  URL decode a single string with a given encoding.  If the charset
    is set to `None` no decoding is performed and raw bytes are
    returned.

    :param s: the string to unquote.
    :param charset: the charset of the query string.  If set to `None`
        no decoding will take place.
    :param errors: the error handling for the charset decoding.
    N)r§   r�   )rº   r‰   rŠ   r”   r:   r   r   r   rm   r  s    
rm   )rº   r‰   rŠ   r+   c                 C   s0   t | tƒr|  dd¡} n|  dd¡} t| ||ƒS )a¹  URL decode a single string with the given `charset` and decode "+" to
    whitespace.

    Per default encoding errors are ignored.  If you want a different behavior
    you can set `errors` to ``'replace'`` or ``'strict'``.

    :param s: The string to unquote.
    :param charset: the charset of the query string.  If set to `None`
        no decoding will take place.
    :param errors: The error handling for the `charset` decoding.
    rÔ   rÓ   ó   +ó    )r7   r#   r3   rm   )rº   r‰   rŠ   r   r   r   Úurl_unquote_plus‡  s    
rÛ   )rº   r‰   r+   c                 C   s    t | |dƒ dd¡} |  d¡rP| dd…  ¡ rP| dd… dkrPd	| dd
… › �} t| ƒ}t|j|dd�}t|j|dd�}t|j	|dd�}t
|j| ¡ |||fƒS )a  Sometimes you get an URL by a user that just isn't a real URL because
    it contains unsafe characters like ' ' and so on. This function can fix
    some of the problems in a similar way browsers handle data entered by the
    user:

    >>> url_fix('http://de.wikipedia.org/wiki/Elf (Begriffskl\xe4rung)')
    'http://de.wikipedia.org/wiki/Elf%20(Begriffskl%C3%A4rung)'

    :param s: the string with the URL to fix.
    :param charset: The target charset for the URL if the url was given
        as a string.
    r3   rk   rh   zfile://é   é   é
   )z:/z|/zfile:///Nz
/%+$!*'(),rÊ   z:&%=+$!*'(),)r   r3   r{   rp   rN   rZ   r   r×   r   r   rQ   r   r\   )rº   r‰   r´   r   ÚqsÚanchorr   r   r   Úurl_fixœ  s    *rá   c                 C   s   g | ]}|t krt|ƒ‘qS r   )rÐ   rÉ   r·   r   r   r   r   »  s      é€   )Úer+   c                 C   s    t | j| j| j… ƒ}|| jfS )zRUsed in :func:`uri_to_iri` after unquoting to re-quote any
    invalid bytes.
    )Ú_fast_url_quoteÚobjectÚstartÚend)rã   Úoutr   r   r   Ú_codec_error_url_quote¾  s    ré   úwerkzeug.url_quote)Úurir‰   rŠ   r+   c                 C   sh   t | tƒrt| ƒ} tt| |ƒƒ} t| j||tƒ}t| j||tƒ}t| j	||tƒ}t| j
|  ¡ |||fƒS )aõ  Convert a URI to an IRI. All valid UTF-8 characters are unquoted,
    leaving all reserved and invalid characters quoted. If the URL has
    a domain, it is decoded from Punycode.

    >>> uri_to_iri("http://xn--n3h.net/p%C3%A5th?q=%C3%A8ry%DF")
    'http://\u2603.net/p\xe5th?q=\xe8ry%DF'

    :param uri: The URI to convert.
    :param charset: The encoding to encode unquoted bytes with.
    :param errors: Error handler to use during ``bytes.encode``. By
        default, invalid bytes are left quoted.

    .. versionchanged:: 0.15
        All reserved and invalid characters remain quoted. Previously,
        only some reserved characters were preserved, and invalid bytes
        were replaced instead of left quoted.

    .. versionadded:: 0.6
    )r7   ÚtuplerQ   rN   r   rm   r   Ú_to_iri_unsafer   r   r   r]   )rë   r‰   rŠ   r   r   r   r   r   r   r`   Ë  s    
r`   z:/?#[]@!$&'()*+,;=%F)Úirir‰   rŠ   Úsafe_conversionr+   c           	      C   s°   t | tƒrt| ƒ} |rXz,t| ƒ}| d¡}t| ¡ ƒdkr@|W S W n tk
rV   Y nX tt| ||ƒƒ} t	| j
||tƒ}t	| j||tƒ}t	| j||tƒ}t| j|  ¡ |||fƒS )a  Convert an IRI to a URI. All non-ASCII and unsafe characters are
    quoted. If the URL has a domain, it is encoded to Punycode.

    >>> iri_to_uri('http://\u2603.net/p\xe5th?q=\xe8ry%DF')
    'http://xn--n3h.net/p%C3%A5th?q=%C3%A8ry%DF'

    :param iri: The IRI to convert.
    :param charset: The encoding of the IRI.
    :param errors: Error handler to use during ``bytes.encode``.
    :param safe_conversion: Return the URL unchanged if it only contains
        ASCII characters and no whitespace. See the explanation below.

    There is a general problem with IRI conversion with some protocols
    that are in violation of the URI specification. Consider the
    following two IRIs::

        magnet:?xt=uri:whatever
        itms-services://?action=download-manifest

    After parsing, we don't know if the scheme requires the ``//``,
    which is dropped if empty, but conveys different meanings in the
    final URL if it's present or not. In this case, you can use
    ``safe_conversion``, which will return the URL unchanged if it only
    contains ASCII characters and no whitespace. This can result in a
    URI with unquoted characters if it was not already quoted correctly,
    but preserves the URL's semantics. Werkzeug uses this for the
    ``Location`` header for redirects.

    .. versionchanged:: 0.15
        All reserved characters remain unquoted. Previously, only some
        reserved characters were left unquoted.

    .. versionchanged:: 0.9.6
       The ``safe_conversion`` parameter was added.

    .. versionadded:: 0.6
    r
   r   )r7   rì   rQ   r   r   ru   rt   r8   rN   rZ   r   Ú_to_uri_safer   r   r   r\   )	rî   r‰   rŠ   rï   Z
native_iriZ	ascii_irir   r   r   r   r   r   r^   ñ  s    +


r^   ú&zds.MultiDictrI   )rº   r‰   Úinclude_emptyrŠ   Ú	separatorÚclsr+   c                 C   sv   |dkrddl m} |}t| tƒr<t|tƒs<| |p6d¡}n"t| tƒr^t|tƒs^| |pZd¡}|t|  |¡|||ƒƒS )aw  Parse a query string and return it as a :class:`MultiDict`.

    :param s: The query string to parse.
    :param charset: Decode bytes to string with this charset. If not
        given, bytes are returned as-is.
    :param include_empty: Include keys with empty values in the dict.
    :param errors: Error handling behavior when decoding bytes.
    :param separator: Separator character between pairs.
    :param cls: Container to hold result instead of :class:`MultiDict`.

    .. versionchanged:: 2.0
        The ``decode_keys`` parameter is deprecated and will be removed
        in Werkzeug 2.1.

    .. versionchanged:: 0.5
        In previous versions ";" and "&" could be used for url decoding.
        Now only "&" is supported. If you want to use ";", a different
        ``separator`` can be provided.

    .. versionchanged:: 0.5
        The ``cls`` parameter was added.
    Nr   ©Ú	MultiDictr
   )	r   rö   r7   r#   r�   r‘   r   Ú_url_decode_implrt   )rº   r‰   rò   rŠ   ró   rô   rö   r   r   r   rK   3  s       ÿÿrK   ó   &)Ústreamr‰   rò   rŠ   ró   rô   Úlimitr+   c                 C   sF   ddl m} || ||ƒ}t||||ƒ}	|dkr>ddlm}
 |
}||	ƒS )a_  Works like :func:`url_decode` but decodes a stream.  The behavior
    of stream and limit follows functions like
    :func:`~werkzeug.wsgi.make_line_iter`.  The generator of pairs is
    directly fed to the `cls` so you can consume the data while it's
    parsed.

    :param stream: a stream with the encoded querystring
    :param charset: the charset of the query string.  If set to `None`
        no decoding will take place.
    :param include_empty: Set to `False` if you don't want empty values to
                          appear in the dict.
    :param errors: the decoding error behavior.
    :param separator: the pair separator to be used, defaults to ``&``
    :param cls: an optional dict class to use.  If this is not specified
                       or `None` the default :class:`MultiDict` is used.
    :param limit: the content length of the URL data.  Not necessary if
                  a limited stream is provided.

    .. versionchanged:: 2.0
        The ``decode_keys`` and ``return_iterator`` parameters are
        deprecated and will be removed in Werkzeug 2.1.

    .. versionadded:: 0.8
    r   )Úmake_chunk_iterNrõ   )Zwsgirû   r÷   r   rö   )rù   r‰   rò   rŠ   ró   rô   rú   rû   Ú	pair_iterÚdecoderrö   r   r   r   Úurl_decode_stream`  s    !rþ   )rü   r‰   rò   rŠ   r+   c           	      c   sj   | D ]`}|sqt |ƒ}|dƒ}||kr8| |d¡\}}n|s>q|}|dƒ}t|||ƒt|||ƒfV  qd S )Nr¬   r   rR   )r   rt   rÛ   )	rü   r‰   rò   rŠ   Úpairrº   Úequalrª   r²   r   r   r   r÷   Ž  s    

þr÷   )r¨   r‰   r©   rª   ró   r+   c                 C   s   t |dƒ}| t| |||ƒ¡S )a  URL encode a dict/`MultiDict`.  If a value is `None` it will not appear
    in the result string.  Per default only values are encoded into the target
    charset strings.

    :param obj: the object to encode into a query string.
    :param charset: the charset of the query string.
    :param sort: set to `True` if you want parameters to be sorted by `key`.
    :param separator: the separator to be used for the pairs.
    :param key: an optional function to be used for sorting.  For more details
                check out the :func:`sorted` documentation.

    .. versionchanged:: 2.0
        The ``encode_keys`` parameter is deprecated and will be removed
        in Werkzeug 2.1.

    .. versionchanged:: 0.5
        Added the ``sort``, ``key``, and ``separator`` parameters.
    r
   )r   rP   r±   )r¨   r‰   r©   rª   ró   r   r   r   Ú
url_encode£  s    
r  )r¨   rù   r‰   r©   rª   ró   r+   c           	      C   sR   t |dƒ}t| |||ƒ}|dkr$|S t|ƒD ] \}}|rB| |¡ | |¡ q,dS )a�  Like :meth:`url_encode` but writes the results to a stream
    object.  If the stream is `None` a generator over all encoded
    pairs is returned.

    :param obj: the object to encode into a query string.
    :param stream: a stream to write the encoded object into or `None` if
                   an iterator over the encoded pairs should be returned.  In
                   that case the separator argument is ignored.
    :param charset: the charset of the query string.
    :param sort: set to `True` if you want parameters to be sorted by `key`.
    :param separator: the separator to be used for the pairs.
    :param key: an optional function to be used for sorting.  For more details
                check out the :func:`sorted` documentation.

    .. versionchanged:: 2.0
        The ``encode_keys`` parameter is deprecated and will be removed
        in Werkzeug 2.1.

    .. versionadded:: 0.8
    r
   N)r   r±   Ú	enumerateÚwrite)	r¨   rù   r‰   r©   rª   ró   Úgenr}   Úchunkr   r   r   Úurl_encode_streamÀ  s    

r  )Úbaser´   rµ   r+   c                    sî  t | tƒrt| ƒ} t |tƒr$t|ƒ}t| |fƒ t| ƒ‰ | s@|S |sH| S t| |d�\}}}}}t|||ƒ\}}	}
}}||kr€|S |	r–t||	|
||fƒS |}	|
dd… ˆ dƒkr¾|
 ˆ dƒ¡}n@|
sÚ| ˆ dƒ¡}|sþ|}n$| ˆ dƒ¡dd… |
 ˆ dƒ¡ }|d ˆ dƒk�rˆ dƒ|d< ‡ fdd	„|D ƒ}d}t|ƒd }||k �r¢|| ˆ d
ƒk�rŽ||d  ˆ dƒˆ d
ƒfk�rŽ||d |d …= �q.|d7 }�q>�q¢�q.ˆ dƒˆ d
ƒg}|dd… |k�rÎ|d= �q²ˆ dƒ |¡}
t||	|
||fƒS )a	  Join a base URL and a possibly relative URL to form an absolute
    interpretation of the latter.

    :param base: the base URL for the join operation.
    :param url: the URL to join.
    :param allow_fragments: indicates whether fragments should be allowed.
    )rµ   Nr   rh   éÿÿÿÿÚ.rR   c                    s   g | ]}|ˆ d ƒkr|‘qS )r	  r   )r   Úsegmentr¹   r   r   r     s      zurl_join.<locals>.<listcomp>z..ri   )	r7   rì   rQ   r   r   rN   rt   ru   rP   )r  r´   rµ   ÚbschemeÚbnetlocÚbpathÚbqueryÚ	bfragmentr   r   r   r   r   ÚsegmentsrÄ   ÚnZunwanted_markerr   r¹   r   rO   ç  sV    

 ÿ$
0
rO   )rR   )rR   )NT)rV   rW   rÇ   rR   )rV   rW   rÇ   rR   )rV   rW   rR   )rV   r3   rR   )rV   r3   )rV   )rV   rê   )rV   rW   F)rV   Tr3   rñ   N)rV   Tr3   rø   NN)rV   FNrñ   )NrV   FNrñ   )T)Mr   Úcodecsrn   ÚreÚtypingr�   Ú	_internalr   r   r   r   r   ÚTYPE_CHECKINGrR   r   ZdsÚcompiler¿   rš   r›   rÐ   r   rŸ   rÑ   rÖ   Ú
NamedTupler   r%   r†   r‡   r’   ÚDictÚ	FrozenSetr   r‘   r$   ÚUnionr#   r§   ÚMappingÚIterabler…   Úboolr„   ÚCallabler‚   ÚIteratorr±   rC   rN   rÒ   rä   rÕ   r®   rZ   r×   rQ   rm   rÛ   rá   rP   rí   r8   ré   Úregister_errorr`   rð   r^   ÚAnyStrÚTyperK   ÚIOrþ   r÷   r  r  rO   r   r   r   r   Ú<module>   sŠ  
ÿÿ
þ  , ÿ þ"& û   ÿ  þ4    üû    ûú$     ÿ   þ !   üû   ÿ  þ
  ýü#   üûD     úù/      ùø/
   þ    û& ú     ú& ù* ýü