§
    xÅj'  ã                  ó(  — d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	m
Z
 g d¢Z G d„ de¦  «        Z ej        d¦  «        j        Z G d	„ d
eeef         ¦  «        Z G d„ de
¦  «        Zeeeef         z  eeeef                  z  ez  Z	 ddlmZ dS )é    )ÚannotationsN)ÚIterableÚIteratorÚMappingÚMutableMapping)ÚAnyÚProtocol)ÚHeadersÚHeadersLikeÚMultipleValuesErrorc                  ó$   ‡ — e Zd ZdZdˆ fd„Zˆ xZS )r   zP
    Exception raised when :class:`Headers` has multiple values for a key.

    ÚreturnÚstrc                ó¨   •— t          | j        ¦  «        dk    rt          | j        d         ¦  «        S t          ¦   «                              ¦   «         S ©Né   r   )ÚlenÚargsÚreprÚsuperÚ__str__)ÚselfÚ	__class__s    €úJC:\Projects\Historical\venv\Lib\site-packages\websockets/datastructures.pyr   zMultipleValuesError.__str__   s>   ø€ åˆtŒy‰>Œ>˜QÒÐÝ˜œ	 !œÑ%Ô%Ð%Ý‰wŒw�ŠÑ Ô Ð ó    ©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__©r   s   @r   r   r      sG   ø€ € € € € ðð ð
!ð !ð !ð !ð !ð !ð !ð !ð !ð !r   r   z[\x09\x20-\x7e\x80-\xff]*c                  ó¬   ‡ — e Zd ZdZddgZd&d
„Zd'd„Zd'd„Zd(d„Zd)d„Z	d*d„Z
d+d„Zd,d„Zd-d„Zd.d„Zd/d„Zd0d„Zd1d„Zd&ˆ fd „Zd2d"„Zd3d$„Zd.d%„Zˆ xZS )4r
   a¢	  
    Efficient data structure for manipulating HTTP headers.

    A :class:`list` of ``(name, values)`` is inefficient for lookups.

    A :class:`dict` doesn't suffice because header names are case-insensitive
    and multiple occurrences of headers with the same name are possible.

    :class:`Headers` stores HTTP headers in a hybrid data structure to provide
    efficient insertions and lookups while preserving the original data.

    In order to account for multiple values with minimal hassle,
    :class:`Headers` follows this logic:

    - When getting a header with ``headers[name]``:
        - if there's no value, :exc:`KeyError` is raised;
        - if there's exactly one value, it's returned;
        - if there's more than one value, :exc:`MultipleValuesError` is raised.

    - When setting a header with ``headers[name] = value``, the value is
      appended to the list of values for that header.

    - When deleting a header with ``del headers[name]``, all values for that
      header are removed (this is slow).

    Other methods for manipulating headers are consistent with this logic.

    As long as no header occurs multiple times, :class:`Headers` behaves like
    :class:`dict`, except keys are lower-cased to provide case-insensitivity.

    Two methods support manipulating multiple values explicitly:

    - :meth:`get_all` returns a list of all values for a header;
    - :meth:`raw_items` returns an iterator of ``(name, values)`` pairs.

    Header names and values are expected to contain only ASCII text. However,
    non-ASCII values happen in practice, even though there is no standard for
    transmitting non-ASCII data in HTTP headers. :class:`Headers` supports it
    by treating it as ISO-8859-1 data. This is a safe and reversible encoding
    to represent arbitrary data in a :class:`str`.

    When reading headers from the network, if the actual encoding isn't
    ISO-8859-1, you must re-encode and decode, e.g.::

        value = headers[key].encode("iso-8859-1").decode("utf-8")

    Conversely, when sending headers to the network, if you need to use a
    different encoding, you can encode and decode, e.g.::

        headers[key] = value.encode("utf-8").decode("iso-8859-1")

    When assigning a value to a header, as a security hardening measure, the
    value is checked for unsafe characters. The name isn't checked because it's
    usually a constant in code, unlikely to be tainted by user input.

    Ú_dictÚ_listr   r   Úkwargsr   r   ÚNonec                ó<   — i | _         g | _         | j        |i |¤Ž d S ©N)r$   r%   Úupdate)r   r   r&   s      r   Ú__init__zHeaders.__init__]   s-   € Ø+-ˆŒ
Ø,.ˆŒ
ØˆŒ�TÐ$˜VÐ$Ð$Ð$Ð$Ð$r   c                óP   — d                      d„ | j        D ¦   «         ¦  «        dz   S )NÚ c              3  ó,   K  — | ]\  }}|› d |› d�V — ŒdS )z: ú
N© )Ú.0ÚkeyÚvalues      r   ú	<genexpr>z"Headers.__str__.<locals>.<genexpr>c   s7   è è € ÐJÐJ±°°e˜#Ð,Ð, Ð,Ð,Ð,ÐJÐJÐJÐJÐJÐJr   r/   )Újoinr%   ©r   s    r   r   zHeaders.__str__b   s*   € Ø�wŠwÐJÐJ¸t¼zÐJÑJÔJÑJÔJÈVÑSÐSr   c                ó0   — | j         j        › d| j        ›d�S )Nú(ú))r   r   r%   r6   s    r   Ú__repr__zHeaders.__repr__e   s    € Ø”.Ô)Ð;Ð;¨D¬JÐ;Ð;Ð;Ð;r   c                ó¦   — |                       ¦   «         }| j                             ¦   «         |_        | j                             ¦   «         |_        |S r)   )r   r$   Úcopyr%   )r   r<   s     r   r<   zHeaders.copyh   s<   € Ø�~Š~ÑÔˆØ”Z—_’_Ñ&Ô&ˆŒ
Ø”Z—_’_Ñ&Ô&ˆŒ
Øˆr   Úbytesc                óF   — t          | ¦  «                             d¦  «        S )Nz
iso-8859-1)r   Úencoder6   s    r   Ú	serializezHeaders.serializen   s   € õ �4‰yŒy×Ò Ñ-Ô-Ð-r   r2   ÚobjectÚboolc                ób   — t          |t          ¦  «        o|                     ¦   «         | j        v S r)   )Ú
isinstancer   Úlowerr$   ©r   r2   s     r   Ú__contains__zHeaders.__contains__u   s&   € Ý˜#�sÑ#Ô#ÐA¨¯	ª	©¬°t´zÐ(AÐAr   úIterator[str]c                ó*   — t          | j        ¦  «        S r)   )Úiterr$   r6   s    r   Ú__iter__zHeaders.__iter__x   s   € Ý�D”JÑÔÐr   Úintc                ó*   — t          | j        ¦  «        S r)   )r   r$   r6   s    r   Ú__len__zHeaders.__len__{   s   € Ý�4”:‰ŒÐr   c                ó”   — | j         |                     ¦   «                  }t          |¦  «        dk    r|d         S t          |¦  «        ‚r   )r$   rE   r   r   ©r   r2   r3   s      r   Ú__getitem__zHeaders.__getitem__€   s<   € Ø”
˜3Ÿ9š9™;œ;Ô'ˆÝˆu‰:Œ:˜Š?ˆ?Ø˜”8ˆOå% cÑ*Ô*Ð*r   r3   c                ó  — t          t          |¦  «        ¦  «        st          ||¦  «        ‚| j                             |                     ¦   «         g ¦  «                             |¦  «         | j                             ||f¦  «         d S r)   )Úis_valid_header_valuer   ÚInvalidHeaderValuer$   Ú
setdefaultrE   Úappendr%   rP   s      r   Ú__setitem__zHeaders.__setitem__‡   sv   € Ý$¥S¨¡Z¤ZÑ0Ô0ð 	1Ý$ S¨%Ñ0Ô0Ð0ØŒ
×Ò˜cŸiši™kœk¨2Ñ.Ô.×5Ò5°eÑ<Ô<Ð<ØŒ
×Ò˜3 ˜,Ñ'Ô'Ð'Ð'Ð'r   c                ó”   ‡— |                      ¦   «         Š| j                             ‰¦  «         ˆfd„| j        D ¦   «         | _        d S )Nc                óN   •— g | ]!\  }}|                      ¦   «         ‰k    ¯||f‘Œ"S r0   )rE   )r1   ÚkÚvÚ	key_lowers      €r   ú
<listcomp>z'Headers.__delitem__.<locals>.<listcomp>‘   s3   ø€ ÐNÐNÐN¡  A°q·w²w±y´yÀIÒ7MÐ7M�q˜!�fÐ7MÐ7MÐ7Mr   )rE   r$   Ú__delitem__r%   )r   r2   r\   s     @r   r^   zHeaders.__delitem__�   sG   ø€ Ø—I’I‘K”Kˆ	ØŒ
×Ò˜yÑ)Ô)Ð)àNÐNÐNÐN¨¬ÐNÑNÔNˆŒ
ˆ
ˆ
r   Úotherr   c                óZ   — t          |t          ¦  «        st          S | j        |j        k    S r)   )rD   r
   ÚNotImplementedr$   )r   r_   s     r   Ú__eq__zHeaders.__eq__“   s)   € Ý˜%¥Ñ)Ô)ð 	"Ý!Ð!ØŒz˜Uœ[Ò(Ð(r   c                ó"   — i | _         g | _        dS )z&
        Remove all headers.

        N)r$   r%   r6   s    r   ÚclearzHeaders.clear˜   s   € ð
 ˆŒ
ØˆŒ
ˆ
ˆ
r   c                ól   •— t          d„ |D ¦   «         ¦  «        } t          ¦   «         j        |i |¤Ž dS )zT
        Update from a :class:`Headers` instance and/or keyword arguments.

        c              3  ól   K  — | ]/}t          |t          ¦  «        r|                     ¦   «         n|V — Œ0d S r)   )rD   r
   Ú	raw_items)r1   Úargs     r   r4   z!Headers.update.<locals>.<genexpr>¥   sN   è è € ð 
ð 
ØEH�z¨#­wÑ7Ô7Ð@ˆC�MŠM‰OŒOˆO¸Sð
ð 
ð 
ð 
ð 
ð 
r   N)Útupler   r*   )r   r   r&   r   s      €r   r*   zHeaders.update    sS   ø€ õ
 ð 
ð 
ØLPð
ñ 
ô 
ñ 
ô 
ˆð 	�‰ŒŒ˜Ð' Ð'Ð'Ð'Ð'Ð'r   ú	list[str]c                ó\   — | j                              |                     ¦   «         g ¦  «        S )z|
        Return the (possibly empty) list of all values for a header.

        Args:
            key: Header name.

        )r$   ÚgetrE   rF   s     r   Úget_allzHeaders.get_all¬   s"   € ð Œz�~Š~˜cŸiši™kœk¨2Ñ.Ô.Ð.r   úIterator[tuple[str, str]]c                ó*   — t          | j        ¦  «        S )zO
        Return an iterator of all values as ``(name, value)`` pairs.

        )rJ   r%   r6   s    r   rg   zHeaders.raw_items¶   s   € õ
 �D”JÑÔÐr   c                ó¾   — | j                              |                     ¦   «         g ¦  «                             |¦  «         | j                             ||f¦  «         dS )z=
        Set a header without validating its value.

        N)r$   rU   rE   rV   r%   rP   s      r   Úset_insecurezHeaders.set_insecure¿   sR   € ð
 	Œ
×Ò˜cŸiši™kœk¨2Ñ.Ô.×5Ò5°eÑ<Ô<Ð<ØŒ
×Ò˜3 ˜,Ñ'Ô'Ð'Ð'Ð'r   )r   r   r&   r   r   r'   r   )r   r
   )r   r=   )r2   rA   r   rB   )r   rH   )r   rL   ©r2   r   r   r   )r2   r   r3   r   r   r'   )r2   r   r   r'   )r_   r   r   rB   )r   r'   )r2   r   r   rj   )r   rn   )r   r   r   r    Ú	__slots__r+   r   r:   r<   r@   rG   rK   rN   rQ   rW   r^   rb   rd   r*   rm   rg   rq   r!   r"   s   @r   r
   r
       s   ø€ € € € € ð7ð 7ðr ˜'Ð"€Ið%ð %ð %ð %ð
Tð Tð Tð Tð<ð <ð <ð <ðð ð ð ð.ð .ð .ð .ðBð Bð Bð Bð ð  ð  ð  ðð ð ð ð
+ð +ð +ð +ð(ð (ð (ð (ðOð Oð Oð Oð)ð )ð )ð )ð
ð ð ð ð(ð (ð (ð (ð (ð (ð/ð /ð /ð /ð ð  ð  ð  ð(ð (ð (ð (ð (ð (ð (ð (r   r
   c                  ó"   — e Zd ZdZd	d„Zd
d„ZdS )ÚSupportsKeysAndGetItemz_
    Dict-like types with ``keys() -> str`` and ``__getitem__(key: str) -> str`` methods.

    r   úIterable[str]c                ó   — d S r)   r0   r6   s    r   ÚkeyszSupportsKeysAndGetItem.keysÏ   ó   € € € r   r2   r   c                ó   — d S r)   r0   rF   s     r   rQ   z"SupportsKeysAndGetItem.__getitem__Ñ   ry   r   N)r   rv   rr   )r   r   r   r    rx   rQ   r0   r   r   ru   ru   É   s4   € € € € € ðð ð
 )Ð(Ð(Ð(à/Ð/Ð/Ð/Ð/Ð/r   ru   r   )rT   )Ú
__future__r   ÚreÚcollections.abcr   r   r   r   Útypingr   r	   Ú__all__ÚLookupErrorr   ÚcompileÚ	fullmatchrS   r   r
   ru   ri   r   Ú
exceptionsrT   r0   r   r   ú<module>r„      sd  ðØ "Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GÐ GØ  Ð  Ð  Ð  Ð  Ð  Ð  Ð  ðð ð €ð
!ð 
!ð 
!ð 
!ð 
!˜+ñ 
!ô 
!ð 
!ð #˜œ
Ð#?Ñ@Ô@ÔJÐ ðe(ð e(ð e(ð e(ð e(ˆn˜S #˜XÔ&ñ e(ô e(ð e(ðR0ð 0ð 0ð 0ð 0˜Xñ 0ô 0ð 0ð ˆg�c˜3�hÔÑ (¨5°°c°¬?Ô";Ñ;Ð>TÑTð ðð +Ð *Ð *Ð *Ð *Ð *Ð *Ð *r   