
    3i                     @   d dl m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                  d	ej                   ej"                  z  ej$                  z  
      Z	 d	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 	 	 ddZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 ddZy)    )annotationsN)quote   )
_plain_int)SecurityError)parse_set_header)
uri_to_iriz
    (
        [a-z0-9.-]+  # domain or ipv4
    |
        \[[a-f0-9]*:[a-f0-9.:]+]  # ipv6
    )
    (?::[0-9]+)?  # optional port
    )flagsc                   | syt         j                  |       y| j                  d      d   } |syt        |t              r|g}|D ]n  }|j                  d      r|dd }d}nd}	 |j                  d      d   j                  d      j                  d	      }|| k(  s|sY| j                  d|       sn y y# t        $ r Y  yw xY w)
a  Perform some checks on a ``Host`` header ``host:port``. The host must be
    made up of valid characters, but this does not check validity beyond that.
    If a list of trusted domains is given, the domain must match one.

    :param hostname: The ``Host`` header ``host:port`` to check.
    :param trusted_list: A list of trusted domains to match. These should
        already be IDNA encoded, but will be encoded if needed. The port is
        ignored for this check. If a name starts with a dot it will match as a
        suffix, accepting all subdomains. If empty or ``None``, all domains are
        allowed.

    .. versionchanged:: 3.2
        The value's characters are validated.

    .. versionchanged:: 3.2
        ``trusted_list`` defaults to ``None``.

    .. versionadded:: 0.9
    FN:r   T.   idnaascii)
_host_re	fullmatch	partition
isinstancestr
startswithencodedecodeUnicodeEncodeErrorendswith)hostnametrusted_listrefsuffix_matchs       H/var/www/opsc/venv/lib/python3.12/site-packages/werkzeug/sansio/utils.pyhost_is_trustedr       s    , (#+!!#&q)H,$$~ >>#ab'CL L	--$Q'..v6==gFC (?|0A0AAcU)0L  " 		s   %2B88	CCc                    ||}n+|'|d   "|d   }d|v r|d   dk7  rd| d}| d|d    }nd}| dv r|j                  d      }n| d	v r|j                  d
      }t        ||      st        d|d      |S )aW  Get and validate a request's ``host:port`` based on the given values.

    The ``Host`` header sent by the client is preferred. Otherwise, the server's
    configured address is used. The port is omitted if it matches the standard
    HTTP or HTTPS ports.

    The value is passed through :func:`host_is_trusted`. The host must be made
    up of valid characters, but this does not check validity beyond that. If a
    list of trusted domains is given, the domain must match one.

    :param scheme: The protocol of the request. Used to omit the standard ports
        80 and 443.
    :param host_header: The ``Host`` header value.
    :param server: The server's configured address ``(host, port)``. The server
        may be using a Unix socket and give ``(path, None)``; this is ignored as
        it would not produce a useful host value.
    :param trusted_hosts: A list of trusted domains to match. These should
        already be IDNA encoded, but will be encoded if needed. The port is
        ignored for this check. If a name starts with a dot it will match as a
        suffix, accepting all subdomains. If empty or ``None``, all domains are
        allowed.

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

    .. versionchanged:: 3.2
        The characters of the host value are validated. The empty string is no
        longer allowed if no header value is available.

    .. versionchanged:: 3.2
        When using the server address, Unix sockets are ignored.

    .. versionchanged:: 3.1.3
        If ``SERVER_NAME`` is IPv6, it is wrapped in ``[]``.
    r   r   r   [] >   wshttpz:80>   wsshttpsz:443zHost z is not trusted.)removesuffixr    r   )schemehost_headerservertrusted_hostshosts        r   get_hostr/   O   s    R 		q	 5ay $;47c>tfA;Dq$  '	#	#  (4/eD8+;<==K    c                   | d|g}|+|j                  d       t        dj                  |            S |j                  t        |j	                  d      d             |j                  d       |t        dj                  |            S |j                  t        |j                  d      d             |r-|j                  d       |j                  t        |d             t        dj                  |            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:///r$   z!$&'()*+,/:;=@%)safe?z!$&'()*+,/:;=?@%)appendr	   joinr   rstriplstrip)r*   r.   	root_pathpathquery_stringurls         r   get_current_urlr=      s    ( 5$
C

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

3

5,>?@bggcl##r0   c                p    |dt        |      v s| y	 t        dt        |             S # t        $ r Y y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
    Nchunkedr   )r   maxr   
ValueError)http_content_lengthhttp_transfer_encodings     r   get_content_lengthrD      sL     	*)*@AA		$1j!4566 s   ) 	55)N)r   
str | Noner   t.Collection[str] | Nonereturnbool)NN)
r*   r   r+   rE   r,   ztuple[str, int | None] | Noner-   rF   rG   r   )NNN)r*   r   r.   r   r9   rE   r:   rE   r;   zbytes | NonerG   r   )rB   rE   rC   rE   rG   z
int | None)
__future__r   retypingturllib.parser   	_internalr   
exceptionsr   r&   r   urlsr	   compileASCII
IGNORECASEVERBOSEr   r    r/   r=   rD    r0   r   <module>rV      s$   " 	   " & # 2:: ((R]]
"RZZ
/
 DH33(@3	3r -1.2	@@@ *@ ,	@
 	@L !!%($($
($ ($ 	($
 ($ 	($X '+)-#& r0   