a
    �ÏOcï  ã                   @   sî   d dl ZddlmZ ddlmZ ddlmZ ddlmZ e	ej
e	 edœdd	„Zde	eje	 ejeje	eje f  ejej
e	  e	d
œdd„Zde	e	eje	 eje	 eje e	dœdd„Zdeje	df eje	df eje dœdd„ZdS )é    Né   )Ú_encode_idna)ÚSecurityError)Ú
uri_to_iri)Ú	url_quote)ÚhostnameÚtrusted_listÚreturnc              	   C   sÂ   | sdS t |tƒr|g}ttdœdd„}z|| ƒ}W n tyH   Y dS 0 |D ]n}| d¡rn|dd… }d}nd}z||ƒ}W n ty”   Y  dS 0 ||kr¤ dS |rN| d	| ¡rN dS qNdS )
zôCheck 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   r	   c                 S   s    d| v r|   dd¡d } t| ƒS )Nú:é   r   )Úrsplitr   )r   © r   úL/var/www/html/gsl.tools/lib/python3.9/site-packages/werkzeug/sansio/utils.pyÚ
_normalize   s    z#host_is_trusted.<locals>._normalizeÚ.r   NTó   .)Ú
isinstanceÚstrÚbytesÚUnicodeErrorÚ
startswithÚendswith)r   r   r   Zhostname_bytesÚrefZsuffix_matchZ	ref_bytesr   r   r   Úhost_is_trusted	   s.    	


r   )ÚschemeÚhost_headerÚserverÚtrusted_hostsr	   c                 C   s¤   d}|dur|}n.|dur@|d }|d dur@|› d|d › �}| dv r`|  d¡r`|dd… }n| d	v r~|  d
¡r~|dd… }|dur 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.
    Ú Nr   r   r
   >   ÚwsÚhttpz:80éýÿÿÿ>   ÚhttpsÚwssz:443éüÿÿÿzHost z is not trusted.)r   r   r   )r   r   r   r   Úhostr   r   r   Úget_host8   s    
r&   )r   r%   Ú	root_pathÚpathÚquery_stringr	   c                 C   s    | d|g}|du r*|  d¡ td |¡ƒS |  t| d¡ƒ¡ |  d¡ |du r^td |¡ƒS |  t| d¡ƒ¡ |r’|  d¡ |  t|d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)Úappendr   Újoinr   ÚrstripÚlstrip)r   r%   r'   r(   r)   Úurlr   r   r   Úget_current_urlh   s    



r2   r   )Úhttp_content_lengthÚhttp_transfer_encodingr	   c              	   C   s@   |dkrdS | dur<zt dt| ƒƒW S  ttfy:   Y n0 dS )a  Returns the content length as an integer or ``None`` if
    unavailable or chunked transfer encoding is used.

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

    .. versionadded:: 2.2
    ÚchunkedNr   )ÚmaxÚintÚ
ValueErrorÚ	TypeError)r3   r4   r   r   r   Úget_content_length‘   s    r:   )NN)NNN)Nr   )ÚtypingÚtÚ	_internalr   Ú
exceptionsr   Úurlsr   r   r   ÚIterableÚboolr   ÚOptionalÚTupler7   r&   r   r2   ÚUnionr:   r   r   r   r   Ú<module>   s@   2  üû3   ûú*  þý