a
    !fs                  
   @  s  U d Z ddlm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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lmZ d	dlmZ d	dlmZ ejrd	dlmZ edZ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(d!e)d"< dd$d$d%d&d'd(Z*d)d*d+d,d-d.d/d0Z+dd*d*d*d1d2d3Z,dd*d5d+dd6d7d8Z-dd*d*d$d$d<d=d>d?Z.e. Z/e.d@dAdBZ0d%d*dCdDdEZ1dd$d*d*d$d$d*dFdGdHZ2dd*d*d*d*d*dIdJdKZ3dLd*dMdNdOZ4dd$d*d*d*d*dQdRdSZ5dd$d*d*d*dTdUdVZ6dd*d*d*dWdXdYZ7dZd[d\d]d^Z8e9d_e8 d*d*d`dadbdcZ:e;g e!dddedfR < Z=e:dge=Z>e:dhe=di Z?e:dje=dk Z@e:dle=dm ZAddnd5d5d*dodpdqZBddnd5d5drd*dsdtduZCd*d*dvdwdxZDddzd*d+d*d*d{d|d}d~dZEddd*d+d*d%d{dd|dddZFdd*d+d*ddddZGdd)d*d+d,d*d*dddZHdd)dd*d+d,d*ddddZIddndnd+d*dddZJdd)d*d*dddZKdS )zFunctions for working with URLs.

Contains implementations of functions from :mod:`urllib.parse` that
handle bytes and strings.
    )annotationsN)quote)unquote)	urlencode)urlsplit)
urlunsplit   )_check_str_tuple)_decode_idna)_make_encode_wrapper)_to_striter_multi_items)datastructuresz^[a-zA-Z0-9+-.]+$zKabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~$!'()*+,;ascii0123456789ABCDEFabcdefc                 C  s8   i | ]0}t D ]&}| | d t| | dqqS )r      )
_hexdigitsencodeint).0ab r   N/var/www/html/python-backend/venv/lib/python3.9/site-packages/werkzeug/urls.py
<dictcomp>*   s   r   c                 C  s   g | ]}d |d dqS )%02Xr   )r   )r   charr   r   r   
<listcomp>/       r      c                   @  s6   e Zd ZU ded< ded< ded< ded< ded< dS )	_URLTuplestrschemenetlocpathqueryfragmentN)__name__
__module____qualname____annotations__r   r   r   r   r"   2   s
   
r"   c                      s  e Zd ZU dZdZded< ded< ded< ded< ddd d	 fd
dZddddZdd dddZe	ddddZ
e	ddddZe	ddddZe	ddddZe	ddddZe	ddddZe	ddd d!Ze	ddd"d#Zddd$d	d%d&Zddd d	d'd(Zddd)d*Zddd+d,Zddd-d.Zd dd/d0Zd dd1d2Zd?dd4d5d6d7Zd8dd9d:Zd4dd;d<Zd4dd=d>Z  ZS )@BaseURLzSuperclass of :py:class:`URL` and :py:class:`BytesURL`.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use the ``urllib.parse`` library instead.
    r   r#   _at_colon	_lbracket	_rbracketzt.Any)argskwargsreturnc                   s4   t jd| j dtdd t j| g|R i |S )Nz'werkzeug.urls.z\' is deprecated and will be removed in Werkzeug 3.0. Use the 'urllib.parse' library instead.   
stacklevel)warningswarnr)   DeprecationWarningsuper__new__)clsr2   r3   	__class__r   r   r<   G   s    zBaseURL.__new__r4   c                 C  s   |   S N)to_urlselfr   r   r   __str__P   s    zBaseURL.__str__)r3   r4   c                 K  s   | j f i |S )zReturn an URL with the same values, except for those parameters
        given new values by whichever keyword arguments are specified.)_replace)rD   r3   r   r   r   replaceS   s    zBaseURL.replace
str | Nonec                 C  s   |   d S )zThe 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_hostrC   r   r   r   hostX   s    zBaseURL.hostc                 C  sD   | j }|dur@t|tr@z|dd}W n ty>   Y n0 |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.
        Nidnar   )rJ   
isinstancer#   r   decodeUnicodeErrorrD   rvr   r   r   
ascii_host`   s    zBaseURL.ascii_host
int | Nonec              	   C  sR   z6t t|  d }d|  kr*dkr4n n|W S W n ttfyL   Y n0 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   rI   
ValueError	TypeErrorrO   r   r   r   porto   s    
zBaseURL.portc                 C  s   |   d S )zSThe authentication part in the URL if available, `None`
        otherwise.
        r   )_split_netlocrC   r   r   r   auth|   s    zBaseURL.authc                 C  s    |   d }|durt|S dS )zThe 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_legacyrO   r   r   r   username   s    zBaseURL.usernamec                 C  s   |   d S )zThe username if it was part of the URL, `None` otherwise.
        Unlike :attr:`username` this one is not being decoded.
        r   rY   rC   r   r   r   raw_username   s    zBaseURL.raw_usernamec                 C  s    |   d }|durt|S dS )zThe password if it was part of the URL, `None` otherwise.
        This undergoes URL decoding and will always be a string.
        r   NrX   rO   r   r   r   password   s    zBaseURL.passwordc                 C  s   |   d S )zThe password if it was part of the URL, `None` otherwise.
        Unlike :attr:`password` this one is not being decoded.
        r   r\   rC   r   r   r   raw_password   s    zBaseURL.raw_passwordds.MultiDict[str, str]c                 O  s   t | jg|R i |S )zDecodes 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'   rD   r2   r3   r   r   r   decode_query   s    zBaseURL.decode_queryc                 O  s   t t| g|R i |S )zJoins 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_joinrb   r   r   r   join   s    zBaseURL.joinc                 C  s   t | S )zReturns 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_unparserC   r   r   r   rB      s    zBaseURL.to_urlc              
   C  s   | j pd}d|v rd| d}| j}|du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/:%@)rQ   rU   rf   filter	url_quoter]   r_   )rD   rP   rU   rW   r   r   r   encode_netloc   s"    
	zBaseURL.encode_netlocc                 C  s   | j pd}t|tr| }t|}d|v r8d| d}| j}|durT| d| }dtdt| j	pfddt| j
ptddg}|r| d| }|S )z&Decodes the netloc part into a string.rh   ri   rj   rk   Nz/:%@rn   )rJ   rL   bytesrM   r
   rU   rf   ro   rZ   r]   r_   )rD   rJ   rP   rU   rW   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.
        )rd   
iri_to_urirC   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.
        )rd   
uri_to_irirC   r   r   r   to_iri_tuple   s    	zBaseURL.to_iri_tupleNztuple[str | None, str | None])
pathformatr4   c                 C  s:  | j dkrdS t| j}| jp d}|du r>tjdkr:d}nd}|dkr|dd dkr|dd	  r|d	d
 dv r|dd	  d|d
d  }|dd
 dv }ddl}||}|r|du r|	d
dd}t|d	kr|\}}n|d }d}n,|dkrddl}||}ntd||dv 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   /r5      z|:ri   )z\\\z///r   \rh   zInvalid path format )z	127.0.0.1z::1	localhost)r$   url_unquoter&   r%   osnameisalphantpathnormpathlstripsplitlen	posixpathrT   )rD   rx   r&   rJ   Zwindows_sharer   partsr   r   r   r   get_file_location   s6    



0



zBaseURL.get_file_locationztuple[str | None, str]c                 C  s2   | j | jv r(| j| j \}}}||fS d | jfS rA   )r.   r%   	partition)rD   rW   _r%   r   r   r   rV   =  s    zBaseURL._split_netlocc                 C  s@   |   d }|sdS | j|vr&|d fS || j\}}}||fS )Nr   rz   )rV   r/   r   )rD   rW   r[   r   r^   r   r   r   rY   C  s    
zBaseURL._split_authc                 C  s   |   d }|sdS || jsL| j|v 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   rz   r   )rV   
startswithr0   r/   r   findr1   )rD   rP   rJ   r   rU   idxrestr   r   r   rI   M  s     
zBaseURL._split_host)N)r)   r*   r+   __doc__	__slots__r,   r<   rE   rG   propertyrJ   rQ   rU   rW   r[   r]   r^   r_   rc   rf   rB   rq   rs   ru   rw   r   rV   rY   rI   __classcell__r   r   r>   r   r-   :   sJ   
			
 >
r-   c                   @  s8   e Zd ZdZdZdZdZdZdZdd	d	d
dddZ	dS )URLzRepresents a parsed URL.  This behaves like a regular tuple but
    also has some extra attributes that give further insight into the
    URL.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use the ``urllib.parse`` library instead.
    r   rn   ri   rj   rk   rl   rG   r#   BytesURLcharseterrorsr4   c              	   C  s:   t | jd|  | j||| j||| j||S )zEncodes 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   rq   r&   r'   r(   rD   r   r   r   r   r   r   r  s    
z
URL.encodeN)rl   rG   )
r)   r*   r+   r   r   r.   r/   r0   r1   r   r   r   r   r   r   c  s   r   c                   @  sT   e Zd ZdZdZdZdZdZdZddd	d
Z	ddddZ
dddddddZdS )r   zRepresents a parsed URL in bytes.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use the ``urllib.parse`` library instead.
    r      @   :   [   ]r#   r@   c                 C  s   |   ddS )Nrl   rG   )rB   rM   rC   r   r   r   rE     s    zBytesURL.__str__rr   c                 C  s   | j S )z&Returns the netloc unchanged as bytes.)r%   rC   r   r   r   rq     s    zBytesURL.encode_netlocrl   rG   r   r   c              	   C  s:   t | jd|  | j||| j||| j||S )zDecodes the URL to a tuple made out of strings.  The charset is
        only being used for the path, query and fragment.
        r   )r   r$   rM   rs   r&   r'   r(   r   r   r   r   rM     s    
zBytesURL.decodeN)rl   rG   )r)   r*   r+   r   r   r.   r/   r0   r1   rE   rq   rM   r   r   r   r   r     s   r   z&dict[frozenset[int], dict[bytes, int]]_unquote_mapsrh   zstr | bytesrr   )stringunsafer4   c                   s   t | tr| d} t  tr( d tt  t| d}tt|d}zt  }W n0 t	y    fddt
 D  }t < Y n0 |D ]N}|d d }||v r|||  ||dd   q|d || qt|S )Nrl      %r    c                   s   i | ]\}}| vr||qS r   r   )r   hr   r   r   r   r     s   z%_unquote_to_bytes.<locals>.<dictcomp>r5   %   )rL   r#   r   	frozenset	bytearrayiterr   nextr   KeyError
_hextobyteitemsappendextendrr   )r   r   groupsresultZhex_to_bytegroupcoder   r   r   _unquote_to_bytes  s*    





r   z1t.Mapping[str, str] | t.Iterable[tuple[str, str]]r#   boolz+t.Callable[[tuple[str, str]], t.Any] | Nonezt.Iterator[str])objr   sortkeyr4   c           
      c  s   ddl m} || }|r$t||d}|D ]f\}}|d u r:q(t|tsTt||}n|}t|tsrt||}	n|}	t| dt|	 V  q(d S )Nr   r   )r   =)r   r   sortedrL   rr   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   r4   c                 C  s8   zt | dd|dW S  ty2   t | d|d Y S 0 d S )Nrl   rm   )r   r   r   latin1)r   r   )r   rN   )r   r   r   r   r   rZ     s    rZ   TrH   )urlr$   allow_fragmentsr4   c                   s  t jdtdd t|  t| t}|du r2 d} d } }}|  d}|dkrtt	| d| dd	r| |d
 d }|rt
 fdd|D r| d|  | }} | dd  dkrVt| }	 dD ]"}
| |
d}|dkrt|	|}	q| d|	 | |	d  }}  d|v r2 d|vsN d|v rV d|vrVtd|r~ d| v r~|  dd
\} } d| v r|  dd
\} }|rt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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use ``urllib.parse.urlsplit`` instead.
    zq'werkzeug.urls.url_parse' is deprecated and will be removed in Werkzeug 3.0. Use 'urllib.parse.urlsplit' instead.r5   r6   Nrh   ri   r   rG   )r   r   c                 3  s   | ]}| d vV  qdS )
0123456789Nr   r   csr   r   	<genexpr>
  r    zurl_parse.<locals>.<genexpr>///?#rj   rk   zInvalid IPv6 URL#?)r8   r9   r:   r   rL   r#   r   
_scheme_rematchr   anylowerr   minrS   r   r   r   )r   r$   r   Zis_text_basedr%   r'   r(   ir   delimr   wdelimZresult_typer   r   r   rd     sD    
"

rd   rl   rm   /:zt.Callable[[bytes], str])r   r   safer   r4   c                   sv   t  tr | | t |tr,|| |}tt tB tt|   fddtdD dd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 | ] }| v rt |n
d |dqS )r   r   )chrr   r   r   r   r   ;  r    z(_make_fast_url_quote.<locals>.<listcomp>r!   rr   r#   r   r4   c                   s   d  fdd| D S )Nrh   c                   s   g | ]} | qS r   r   r   tabler   r   r   >  r    z7_make_fast_url_quote.<locals>.quote.<locals>.<listcomp>)rf   r   r   r   r   r   =  s    z#_make_fast_url_quote.<locals>.quote)rL   r#   r   r   r   _always_saferange)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_plusrG   r   r   r   r   r   G  s    r   )r   r   r   r   r   r4   c                 C  s   t jdtdd t| tttfs(t| } t| tr>| ||} t|trT|||}t|trj|||}tt|t	B tt| }t }t| D ]&}||v r|
| q|t|  qt||S )a  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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use ``urllib.parse.quote`` instead.

    .. versionadded:: 0.9.2
       The `unsafe` parameter was added.
    zn'werkzeug.urls.url_quote' is deprecated and will be removed in Werkzeug 3.0. Use 'urllib.parse.quote' instead.r5   r6   )r8   r9   r:   rL   r#   rr   r   r   r   r   r   r   
_bytetohexrM   )r   r   r   r   r   rP   r   r   r   r   rp   K  s(    


rp   )r   r   r   r   r4   c                 C  s,   t jdtdd t| |||d dddS )aO  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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use ``urllib.parse.quote_plus`` instead.
    zx'werkzeug.urls.url_quote_plus' is deprecated and will be removed in Werkzeug 2.4. Use 'urllib.parse.quote_plus' instead.r5   r6   r   r   )r8   r9   r:   rp   rG   )r   r   r   r   r   r   r   url_quote_plusx  s    r   ztuple[str, str, str, str, str])
componentsr4   c                 C  s   t jdtdd t|  | \}}}}}t|}|d}|sL|r||dr|rp|dd |dkrp|d| }|d|p|d | }n|r||7 }|r||d	 | }|r||d
 | }|r||d | }|S )ai  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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use ``urllib.parse.urlunsplit`` instead.
    zu'werkzeug.urls.url_unparse' is deprecated and will be removed in Werkzeug 3.0. Use 'urllib.parse.urlunsplit' instead.r5   r6   rh   r~   Nr   r   ri   r   r   )r8   r9   r:   r	   r   r   )r   r$   r%   r&   r'   r(   r   r   r   r   r   rg     s,    
rg   rG   )r   r   r   r   r4   c                 C  s2   t jdtdd t| |}|du r&|S |||S )a  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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use ``urllib.parse.unquote`` instead.
    zr'werkzeug.urls.url_unquote' is deprecated and will be removed in Werkzeug 3.0. Use 'urllib.parse.unquote' instead.r5   r6   N)r8   r9   r:   r   rM   )r   r   r   r   rP   r   r   r   r     s    
r   )r   r   r   r4   c                 C  s@   t jdtdd 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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use ``urllib.parse.unquote_plus`` instead.
    z|'werkzeug.urls.url_unquote_plus' is deprecated and will be removed in Werkzeug 2.4. Use 'urllib.parse.unquote_plus' instead.r5   r6   r   r      +    )r8   r9   r:   rL   r#   rG   r   )r   r   r   r   r   r   url_unquote_plus  s    
r   )r   r   r4   c                 C  s   t jdtdd t| |ddd} | dr`| dd	  r`| d	d
 dv r`d| dd  } t| }t|j	|dd}t
|j|dd}t
|j|dd}t|j| |||fS )aF  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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0.
    zJ'werkzeug.urls.url_fix' is deprecated and will be removed in Werkzeug 3.0.r5   r6   rG   r   r~   zfile://      
   )z:/z|/zfile:///Nz
/%+$!*'(),r   z:&%=+$!*'(),)r8   r9   r:   r   rG   r   r   rd   rp   r&   r   r'   r(   rg   r$   rq   )r   r   r   r&   qsanchorr   r   r   url_fix  s    *r   rN   ztuple[str, int])er4   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.
    rh   r   )r   objectstartend)r   outr   r   r   _codec_error_url_quote  s    r   werkzeug.url_quotez t.Callable[[str, str, str], str])r   charsr4   c                   sV   d dd t|D }td| dtj ddddd fd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                 s  s   | ]}t |d V  qdS )r   N)ordr   r   r   r   r   -  r    z%_make_unquote_part.<locals>.<genexpr>z((?:%(?:z))+)r#   )r   encodingr   r4   c                   sH   t  | }g }|D ]&}|t||| |t|d qd|S )Nrh   )r   r   r   r   r   rf   )r   r   r   r   r   partpatternr   r   _unquote_partial0  s    z,_make_unquote_part.<locals>._unquote_partialZ	_unquote_)rf   r   recompileIr)   )r   r   choicesr   r   r   r   _make_unquote_part(  s
    
r  !   r      r(   r'   z&=+#r&   r   userz:@/?#z$str | tuple[str, str, str, str, str])urir   r   r4   c           	      C  sJ  t | tr"tjdtdd t| } t | trDtjdtdd |  } |dur^tjdtdd nd}|dur|tjdtdd nd	}t| }t	|j
||}t|j||}t|j||}|jrt|j}nd
}d|v rd| d}|jr| d|j }|jr6t|j||}|jr(| dt|j|| }| 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.
    :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:: 2.3
        Passing a tuple or bytes, and the ``charset`` and ``errors`` parameters, are
        deprecated and will be removed in Werkzeug 3.0.

    .. 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
    HPassing a tuple is deprecated and will not be supported in Werkzeug 3.0.r5   r6   FPassing bytes is deprecated and will not be supported in Werkzeug 3.0.NJThe 'charset' parameter is deprecated and will be removed in Werkzeug 3.0.rl   IThe 'errors' parameter is deprecated and will be removed in Werkzeug 3.0.r   rh   ri   rj   rk   rn   )rL   tupler8   r9   r:   r   rr   rM   r   _unquote_pathr&   _unquote_queryr'   _unquote_fragmentr(   hostnamer
   rU   r[   _unquote_userr^   r$   )	r  r   r   r   r&   r'   r(   r%   rW   r   r   r   rv   H  sZ    

rv   zbool | None)irir   r   safe_conversionr4   c                 C  s  t | tr"tjdtdd t| } t | trFtjdtdd | |} |dur`tjdtdd nd}|dur~tjdtdd nd	}|durtjd
tdd |rz$| d}t	|
 dkr| W S W n ty   Y n0 t| }t|jd||d}t|jd||d}t|jd||d}|jr0|jdd}	nd}	d|	v rJd|	 d}	|jrb|	 d|j }	|jrt|jdd}
|jrt|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.
    :param charset: The encoding of the IRI.
    :param errors: Error handler to use during ``bytes.encode``.

    .. versionchanged:: 2.3
        Passing a tuple or bytes, and the ``charset`` and ``errors`` parameters, are
        deprecated and will be removed in Werkzeug 3.0.

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

    .. versionchanged:: 2.3
        The ``safe_conversion`` parameter is deprecated and will be removed in Werkzeug
        2.4.

    .. 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	  r5   r6   r
  Nr  rl   r  rm   zRThe 'safe_conversion' parameter is deprecated and will be removed in Werkzeug 3.0.r   r   z%!$&'()*+,/:;=@)r   r   r   z%!$&'()*+,/:;=?@z%!#$&'()*+,/:;=?@rK   rh   ri   rj   rk   z%!$&'()*+,;=r   rn   )rL   r  r8   r9   r:   r   rr   rM   r   r   r   rN   r   r   r&   r'   r(   r  rU   r[   r^   r$   )r  r   r   r  Z	ascii_irir   r&   r'   r(   r%   rW   Zpass_quotedr   r   r   rt     sz    $






rt   )r  r4   c                 C  sB   z|  d W n ty    Y n0 t| dddkr:| S t| S )a  The URL scheme ``itms-services://`` must contain the ``//`` even though it does
    not have a host component. There may be other invalid schemes as well. Currently,
    responses will always call ``iri_to_uri`` on the redirect ``Location`` header, which
    removes the ``//``. For now, if the IRI only contains ASCII and does not contain
    spaces, pass it on as-is. In Werkzeug 3.0, this should become a
    ``response.process_location`` flag.

    :meta private:
    r   Nr   )r   rN   r   r   rt   )r  r   r   r   _invalid_iri_to_uri   s    
r  &zt.AnyStrztype[ds.MultiDict] | Noner`   )r   r   include_emptyr   	separatorr=   r4   c                 C  s   t jdtdd |du r(ddlm} |}t| trLt|tsL||pFd}n"t| trnt|tsn|	|pjd}|t
| ||||S )a  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`.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 3.0. Use ``urllib.parse.parse_qs`` instead.

    .. versionchanged:: 2.1
        The ``decode_keys`` parameter was removed.

    .. 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.
    zr'werkzeug.urls.url_decode' is deprecated and will be removed in Werkzeug 2.4. Use 'urllib.parse.parse_qs' instead.r5   r6   Nr   	MultiDictr   )r8   r9   r:   r   r  rL   r#   rM   rr   r   _url_decode_implr   )r   r   r  r   r  r=   r  r   r   r   ra   5  s"     ra      &zt.IO[bytes]rR   )streamr   r  r   r  r=   limitr4   c                 C  sV   t jdtdd ddlm} || ||}t||||}	|du rNd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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 2.4. Use ``urllib.parse.parse_qs`` instead.

    .. versionchanged:: 2.1
        The ``decode_keys`` and ``return_iterator`` parameters were removed.

    .. versionadded:: 0.8
    zy'werkzeug.urls.url_decode_stream' is deprecated and will be removed in Werkzeug 2.4. Use 'urllib.parse.parse_qs' instead.r5   r6   r   )make_chunk_iterNr  )r8   r9   r:   Zwsgir  r  r   r  )r  r   r  r   r  r=   r  r  	pair_iterdecoderr  r   r   r   url_decode_streamk  s    #r"  zt.Iterable[t.AnyStr]zt.Iterator[tuple[str, str]])r   r   r  r   r4   c           	      c  sj   | D ]`}|sqt |}|d}||v r8||d\}}n|s>q|}|d}t|||t|||fV  qd S )Nr   r   rh   )r   r   r   )	r   r   r  r   pairr   equalr   r   r   r   r   r    s    

r  F)r   r   r   r   r  r4   c                 C  s.   t jdtdd t|d}|t| |||S )aP  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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 2.4. Use ``urllib.parse.urlencode`` instead.

    .. versionchanged:: 2.1
        The ``encode_keys`` parameter was removed.

    .. versionchanged:: 0.5
        Added the ``sort``, ``key``, and ``separator`` parameters.
    zs'werkzeug.urls.url_encode' is deprecated and will be removed in Werkzeug 2.4. Use 'urllib.parse.urlencode' instead.r5   r6   r   )r8   r9   r:   r   rf   r   )r   r   r   r   r  r   r   r   
url_encode  s    
r%  zt.IO[str] | NoneNone)r   r  r   r   r   r  r4   c           	      C  sb   t jdtdd t|d}t| |||}|du r4|S t|D ] \}}|rR|| || 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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 2.4. Use ``urllib.parse.urlencode`` instead.

    .. versionchanged:: 2.1
        The ``encode_keys`` parameter was removed.

    .. versionadded:: 0.8
    zz'werkzeug.urls.url_encode_stream' is deprecated and will be removed in Werkzeug 2.4. Use 'urllib.parse.urlencode' instead.r5   r6   r   N)r8   r9   r:   r   r   	enumeratewrite)	r   r  r   r   r   r  genr   chunkr   r   r   url_encode_stream  s    

r+  )baser   r   r4   c                   s  t jdtdd t| tr"t| } t|tr4t|}t| |f t|  | sP|S |sX| S t| |d\}}}}}t|||\}}	}
}}||kr|S |	rt||	|
||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vr||d |d = q>|d7 }qNqq> d
 dg}|dd |kr|d= q d|}
t||	|
||fS )aq  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.

    .. deprecated:: 2.3
        Will be removed in Werkzeug 2.4. Use ``urllib.parse.urljoin`` instead.
    zo'werkzeug.urls.url_join' is deprecated and will be removed in Werkzeug 2.4. Use 'urllib.parse.urljoin' instead.r5   r6   )r   Nr   r~   .rh   c                   s   g | ]}| d kr|qS )r.  r   )r   segmentr   r   r   r   G  r    zurl_join.<locals>.<listcomp>z..)r8   r9   r:   rL   r  rg   r	   r   rd   r   r   rf   )r,  r   r   bschemebnetlocbpathbquery	bfragmentr$   r%   r&   r'   r(   segmentsr   nZunwanted_markerr   r   r   re     s^    

$
0
re   )r'   r   r4   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   r   _  r    z_urlencode.<locals>.<listcomp>z!$'()*,/:;?@)r   r   )r   r   )r'   r   r   r   r   r   
_urlencode\  s    r8  )rh   )rh   )NT)rl   rm   r   rh   )rl   rm   r   rh   )rl   rm   rh   )rl   rG   rh   )rl   rG   )rl   )NN)NNN)rl   TrG   r  N)rl   TrG   r  NN)rl   FNr  )Nrl   FNr  )T)rl   )Lr   
__future__r   codecsr   r   typingtr8   urllib.parser   r   r   r   r   	_internalr	   r
   r   r   r   r   TYPE_CHECKINGrh   Zdsr  r   Z_always_safe_charsr   r   r   r   r   r   r   
NamedTupler"   r-   r   r   r   r,   r   r   rZ   rd   r   Z_fast_url_quoter   r   rp   r   rg   r   r   r   r   register_errorr  rr   rM   Z_always_unsafer  r  r  r  rv   rt   r  ra   r"  r  r%  r+  re   r8  r   r   r   r   <module>   s   
  +! >        . *     &

  _   {     8      7    '     2 R 