o
    
¨Ýj  ã                   @  s,  d dl m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 dd	lmZ d.dd„Ze de¡ d/dd„Zeg edƒ¢d‘d‘R ƒ ¡ ZedeƒZeded ƒZeded ƒZeded  ƒZd0d"d#„Zd1d%d&„Zd'ejjvrŠejj d'¡ d2d)d*„Zd3d,d-„Z dS )4é    )ÚannotationsN)Úquote)Úunquote)Ú	urlencode)Úurlsplit)Ú
urlunsplité   )Úiter_multi_itemsÚeÚUnicodeErrorÚreturnútuple[str, int]c                 C  s$   t | j| j| j… dd�}|| jfS )zRUsed in :func:`uri_to_iri` after unquoting to re-quote any
    invalid bytes.
    Ú ©Úsafe)r   ÚobjectÚstartÚend)r
   Úout© r   úH/var/www/html/chatgpt/venv/lib/python3.10/site-packages/werkzeug/urls.pyÚ_codec_error_url_quote   s   
r   úwerkzeug.url_quoteÚnameÚstrÚcharsút.Callable[[str], str]c                   sL   d  dd„ t|ƒD ƒ¡}t d|› d�tj¡‰ d‡ fd	d
„}d| › �|_|S )zÑCreate a function that unquotes all percent encoded characters except those
    given. This allows working with unquoted characters if possible while not changing
    the meaning of a given part of a URL.
    ú|c                 s  s   � | ]	}t |ƒd ›V  qdS )Z02XN)Úord)Ú.0Úcr   r   r   Ú	<genexpr>"   s   € z%_make_unquote_part.<locals>.<genexpr>z((?:%(?:z))+)Úvaluer   r   c                   sH   t ˆ  | ¡ƒ}g }|D ]}| t|ddƒ¡ | t|dƒ¡ qd |¡S )Nzutf-8r   r   )ÚiterÚsplitÚappendr   ÚnextÚjoin)r"   Úpartsr   Úpart©Úpatternr   r   Ú_unquote_partial%   s   
z,_make_unquote_part.<locals>._unquote_partialZ	_unquote_N)r"   r   r   r   )r'   ÚsortedÚreÚcompileÚIÚ__name__)r   r   Úchoicesr,   r   r*   r   Ú_make_unquote_part   s
   
r3   é!   é%   é   ÚfragmentÚqueryz&=+#Úpathz/?#Úuserz:@/?#Úuric                 C  sÂ   t | ƒ}t|jƒ}t|jƒ}t|jƒ}|jrt|jƒ}nd}d|v r(d|› d�}|j	dur5|› d|j	› �}|j
durWt|j
ƒ}|jdurPt|jƒ}|› d|› �}|› d|› �}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.

    .. versionchanged:: 3.1.9
        Empty username, password, and port 0 are preserved.

    .. versionchanged:: 3.0
        Passing a tuple or bytes, and the ``charset`` and ``errors`` parameters,
        are removed.

    .. versionchanged:: 2.3
        Which characters remain quoted is specific to each part of the URL.

    .. 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
    r   ú:ú[ú]Nú@)r   Ú_unquote_pathr9   Ú_unquote_queryr8   Ú_unquote_fragmentr7   ÚhostnameÚ_decode_idnaÚportÚusernameÚ_unquote_userÚpasswordr   Úscheme)r;   r(   r9   r8   r7   ÚnetlocÚauthrH   r   r   r   Ú
uri_to_iri=   s$   







rL   Úiric                 C  sÞ   t | ƒ}t|jdd�}t|jdd�}t|jdd�}|jr&|j d¡ d¡}nd}d|v r2d	|› d
�}|jdur?|› d|j› �}|j	duret|j	dd�}|j
dur^t|j
dd�}|› d|› �}|› d|› �}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.

    .. versionchanged:: 3.1.9
        Empty username, password, and port 0 are preserved.

    .. versionchanged:: 3.0
        Passing a tuple or bytes, the ``charset`` and ``errors`` parameters,
        and the ``safe_conversion`` parameter, are removed.

    .. versionchanged:: 2.3
        Which characters remain unquoted is specific to each part of the URL.

    .. 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
    z%!$&'()*+,/:;=@r   z%!$&'()*+,/:;=?@z%!#$&'()*+,/:;=?@ÚidnaÚasciir   r<   r=   r>   Nz%!$&'()*+,;=r?   )r   r   r9   r8   r7   rC   ÚencodeÚdecoderE   rF   rH   r   rI   )rM   r(   r9   r8   r7   rJ   rK   rH   r   r   r   Ú
iri_to_urit   s$   


rR   zitms-servicesÚdomainc              	   C  sš   z|   d¡}W n ty   |  Y S w z| d¡W S  ty"   Y nw g }| d¡D ]}z
| | d¡¡ W q* tyG   | | d¡¡ Y q*w d |¡S )NrO   rN   ó   .Ú.)rP   ÚUnicodeEncodeErrorrQ   ÚUnicodeDecodeErrorr$   r%   r'   )rS   Údatar(   r)   r   r   r   rD   µ   s$   þÿÿ
rD   ú1t.Mapping[str, str] | t.Iterable[tuple[str, str]]c                 C  s   dd„ t | ƒD ƒ}t|dd�S )Nc                 S  s   g | ]
}|d  dur|‘qS )r   Nr   )r   Úxr   r   r   Ú
<listcomp>Ï   s    z_urlencode.<locals>.<listcomp>z!$'()*,/:;?@r   )r	   r   )r8   Úitemsr   r   r   Ú
_urlencodeÎ   s   r]   )r
   r   r   r   )r   r   r   r   r   r   )r;   r   r   r   )rM   r   r   r   )rS   r   r   r   )r8   rY   r   r   )!Ú
__future__r   Úcodecsr.   ÚtypingÚtÚurllib.parseÚurllibr   r   r   r   r   Zdatastructuresr	   r   Úregister_errorr3   ÚbytesÚrangerQ   Z_always_unsaferB   rA   r@   rG   rL   rR   ÚparseÚuses_netlocr%   rD   r]   r   r   r   r   Ú<module>   s2    





7=
