
    'g                       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
Z ej                   de       ddZ eg  ed      dd      j)                         Z ede      Z ededz         Z ededz         Z ededz         ZddZddZdej8                  j:                  vr%ej8                  j:                  j=                  d       d dZd!dZ y)"    )annotationsN)quote)unquote)	urlencode)urlsplit)
urlunsplit   )iter_multi_itemsc                z    t        | j                  | j                  | j                   d      }|| j                  fS )zRUsed in :func:`uri_to_iri` after unquoting to re-quote any
    invalid bytes.
     safe)r   objectstartend)eouts     E/var/www/html/knws/venv/lib/python3.12/site-packages/werkzeug/urls.py_codec_error_url_quoter      s1     155)
3C:    werkzeug.url_quotec                    dj                  d t        |      D              }t        j                  d| dt        j                        dfd}d|  |_        |S )zCreate 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              3  6   K   | ]  }t        |      d   yw)02XN)ord).0cs     r   	<genexpr>z%_make_unquote_part.<locals>.<genexpr>"   s     >1#a&>s   z((?:%(?:z))+)c                    t        j                  |             }g }|D ]9  }|j                  t        |dd             |j                  t	        |d             ; dj                  |      S )Nzutf-8r   r   )itersplitappendr   nextjoin)valuepartsr   partpatterns       r   _unquote_partialz,_make_unquote_part.<locals>._unquote_partial%   sb    W]]5)* 	(DJJwtW.BCDJJtE2'	( wws|r   	_unquote_)r&   strreturnr,   )r%   sortedrecompileI__name__)namecharschoicesr*   r)   s       @r   _make_unquote_partr6      sW    
 hh>u>>Gjj8G9D12448G #,D6 2r   !   %      fragmentqueryz&=+#pathz/?#userz:@/?#c                    t        |       }t        |j                        }t        |j                        }t        |j                        }|j                  rt        |j                        }nd}d|v rd| d}|j                  r| d|j                   }|j                  rDt        |j                        }|j                  rt        |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.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   :[]@)r   _unquote_pathr<   _unquote_queryr;   _unquote_fragmentr:   hostname_decode_idnaportusername_unquote_userpasswordr   scheme)urir'   r<   r;   r:   netlocauthrK   s           r   
uri_to_irirP   =   s    0 SME$D5;;'E 0H~~enn-
f}VHAzz81UZZL)~~U^^,>>$U^^4HV1XJ'D66(#u||VT5(CDDr   c                >   t        |       }t        |j                  d      }t        |j                  d      }t        |j                  d      }|j
                  r+|j
                  j                  d      j                  d      }nd}d|v rd	| d
}|j                  r| d|j                   }|j                  rHt        |j                  d      }|j                  rt        |j                  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.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@   rA   z%!$&'()*+,;=rB   )r   r   r<   r;   r:   rF   encodedecoderH   rI   rK   r   rL   )irir'   r<   r;   r:   rN   rO   rK   s           r   
iri_to_urirW   q   s   2 SME "34D%++$67EU^^*=>H~~&&v.55g>
f}VHAzz81UZZL)~~U^^.9>>U^^.AHV1XJ'D66(#u||VT5(CDDr   zitms-servicesc                |   	 | j                  d      }	 |j                  d      S # t        $ r | cY S w xY w# t        $ r Y nw xY wg }|j	                  d      D ]R  }	 |j                  |j                  d             %# t        $ r# |j                  |j                  d             Y Pw xY w dj                  |      S )NrS   rR      ..)rT   UnicodeEncodeErrorrU   UnicodeDecodeErrorr"   r#   r%   )domaindatar'   r(   s       r   rG   rG      s    }}W%
{{6""     E

4  /	/LLV,-! 	/LLW-.	// 88E?s-   % 6 33	AA A==)B)(B)c                b    t        |       D cg c]
  }|d   	| }}t        |d      S c c}w )Nr	   z!$'()*,/:;?@r   )r
   r   )r;   xitemss      r   
_urlencoderb      s6    (/D11Q43CQDEDU00 Es   
,,)r   UnicodeErrorr-   ztuple[str, int])r3   r,   r4   r,   r-   zt.Callable[[str], str])rM   r,   r-   r,   )rV   r,   r-   r,   )r]   r,   r-   r,   )r;   z1t.Mapping[str, str] | t.Iterable[tuple[str, str]]r-   r,   )!
__future__r   codecsr/   typingturllib.parseurllibr   r   r   r   r   datastructuresr
   r   register_errorr6   bytesrangerU   _always_unsaferE   rD   rC   rJ   rP   rW   parseuses_netlocr#   rG   rb    r   r   <module>rr      s    "  	      " ! # ,   *,B C2 1t1d1D1299;&z>B #G^f-DE"6>E+AB"6>G+CD1Eh4Et &,,222
LL##O421r   