
    h                    ~    d dl m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Z	 	 d"d#dZ	 	 	 d$d%dZ	 	 d"d&d ZdS )'    )annotationsN)quote   )
_plain_int)SecurityError)
uri_to_irihostname
str | Nonetrusted_listt.Iterable[str]returnboolc                (   | sdS 	 |                      d          d                             d                              d          } n# t          $ r Y dS w xY wt	          |t
                    r|g}|D ]}|                    d          r|dd         }d	}nd}	 |                     d          d                             d                              d          }n# t          $ r Y  dS w xY w|| k    s|r|                     d|           r d	S dS )
zCheck if a host matches a list of trusted names.

    :param hostname: The name to check.
    :param trusted_list: A list of valid names to match. If a name
        starts with a dot it will match all subdomains.

    .. versionadded:: 0.9
    F:r   idnaascii.   NT)	partitionencodedecodeUnicodeEncodeError
isinstancestr
startswithendswith)r	   r   refsuffix_matchs       W/var/www/html/prod/cognitive/venv/lib/python3.11/site-packages/werkzeug/sansio/utils.pyhost_is_trustedr       sV     u%%c**1-44V<<CCGLL   uu ,$$ &$~  >># 	!abb'CLL L	--$$Q'..v66==gFFCC! 	 	 	555	 (??|?0A0A)c))0L0L?445s%   AA 
AAAC
C+*C+schemer   host_headerservertuple[str, int | None] | Nonetrusted_hostst.Iterable[str] | Nonec                V   d}||}n5|3|d         }d|v r|d         dk    rd| d}|d         | d|d          }| dv r |                     d	          r|dd
         }n#| dv r|                     d          r
|dd         }|#t          ||          st          d|d          |S )a  Return the host for the given parameters.

    This first checks the ``host_header``. If it's not present, then
    ``server`` is used. The host will only contain the port if it is
    different than the standard port for the protocol.

    Optionally, verify that the host is trusted using
    :func:`host_is_trusted` and raise a
    :exc:`~werkzeug.exceptions.SecurityError` if it is not.

    :param scheme: The protocol the request used, like ``"https"``.
    :param host_header: The ``Host`` header value.
    :param server: Address of the server. ``(host, port)``, or
        ``(path, None)`` for unix sockets.
    :param trusted_hosts: A list of trusted host names.

    :return: Host, with port if necessary.
    :raise ~werkzeug.exceptions.SecurityError: If the host is not
        trusted.

    .. versionchanged:: 3.1.3
        If ``SERVER_NAME`` is IPv6, it is wrapped in ``[]``.
     Nr   r   []r   >   wshttpz:80>   wsshttpsz:443zHost z is not trusted.)r   r    r   )r!   r"   r#   r%   hosts        r   get_hostr2   1   s    : D		ay $;;47c>>t;;;D!9 ((VAY((DDMM%$8$8CRCy	#	#	#f(=(=	#CRCy t]33 	B @ @ @ @AAAK    r1   	root_pathpathquery_stringbytes | Nonec                   | d|g}|7|                     d           t          d                    |                    S |                     t          |                    d          d                     |                     d           |"t          d                    |                    S |                     t          |                    d          d                     |r9|                     d           |                     t          |d                     t          d                    |                    S )	a  Recreate the URL for a request. If an optional part isn't
    provided, it and subsequent parts are not included in the URL.

    The URL is an IRI, not a URI, so it may contain Unicode characters.
    Use :func:`~werkzeug.urls.iri_to_uri` to convert it to ASCII.

    :param scheme: The protocol the request used, like ``"https"``.
    :param host: The host the request was made to. See :func:`get_host`.
    :param root_path: Prefix that the application is mounted under. This
        is prepended to ``path``.
    :param path: The path part of the URL after ``root_path``.
    :param query_string: The portion of the URL after the "?".
    z://N/r(   z!$&'()*+,/:;=@%)safe?z!$&'()*+,/:;=?@%)appendr   joinr   rstriplstrip)r!   r1   r4   r5   r6   urls         r   get_current_urlrA   i   s   ( 5$
C

3"''#,,''' JJuY%%c**1BCCCDDDJJsOOO|"''#,,'''JJuT[[%%,=>>>??? A

3

5,>???@@@bggcll###r3   http_content_lengthhttp_transfer_encoding
int | Nonec                t    |dk    s| dS 	 t          dt          |                     S # t          $ r Y dS w xY w)a  Return the ``Content-Length`` header value as an int. If the header is not given
    or the ``Transfer-Encoding`` header is ``chunked``, ``None`` is returned to indicate
    a streaming request. If the value is not an integer, or negative, 0 is returned.

    :param http_content_length: The Content-Length HTTP header.
    :param http_transfer_encoding: The Transfer-Encoding HTTP header.

    .. versionadded:: 2.2
    chunkedNr   )maxr   
ValueError)rB   rC   s     r   get_content_lengthrI      sZ     **.A.It1j!455666   qqs   ) 
77)r	   r
   r   r   r   r   )NN)
r!   r   r"   r
   r#   r$   r%   r&   r   r   )NNN)r!   r   r1   r   r4   r
   r5   r
   r6   r7   r   r   )rB   r
   rC   r
   r   rD   )
__future__r   typingturllib.parser   	_internalr   
exceptionsr   urlsr   r    r2   rA   rI    r3   r   <module>rR      s    " " " " " "           " " " " " " & & & & & &      # # # #R -1,0	5 5 5 5 5v !!%($ ($ ($ ($ ($X '+)-      r3   