o �J�h��@s�ddlmZddlmZmZmZmZddlmZm Z m Z gd�Z Gdd�de �Z Gdd�deeef�ZGd d �d e �Ze eeeefeeeefefZd S) �)� annotations)�Iterable�Iterator�Mapping�MutableMapping)�Any�Protocol�Union)�Headers� HeadersLike�MultipleValuesErrorcs"eZdZdZd�fdd� Z�ZS)r zP Exception raised when :class:`Headers` has multiple values for a key. �return�strcs&t|j�dkrt|jd�St���S�N�r)�len�args�repr�super�__str__��self�� __class__��WC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\websockets\datastructures.pyrs zMultipleValuesError.__str__�r r)�__name__� __module__� __qualname__�__doc__r� __classcell__rrrrr sr cs�eZdZdZddgZd5d d �Zd6d d �Zd6dd�Zd7dd�Zd8dd�Z d9dd�Z d:dd�Z d;dd�Z d<d d!�Z d=d#d$�Zd>d%d&�Zd?d)d*�Zd@d+d,�Zd5�fd-d.� ZdAd0d1�ZdBd3d4�Z�ZS)Cr 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. �_dict�_listrr �kwargsrr �NonecOs i|_g|_|j|i|��dS�N)r"r#�update�rrr$rrr�__init__DszHeaders.__init__cCsd�dd�|jD��dS)N�css$�|] \}}|�d|�d�VqdS)z: � Nr)�.0�key�valuerrr� <genexpr>Js�"z"Headers.__str__.<locals>.<genexpr>r+)�joinr#rrrrrIszHeaders.__str__cCs|jj�d|j�d�S)N�(�))rrr#rrrr�__repr__LszHeaders.__repr__cCs$|��}|j��|_|j��|_|Sr&)rr"�copyr#)rr4rrrr4Os  z Headers.copy�bytescCs t|���Sr&)r�encoderrrr� serializeUs zHeaders.serializer-�object�boolcCst|t�o |��|jvSr&)� isinstancer�lowerr"�rr-rrr� __contains__[szHeaders.__contains__� Iterator[str]cC� t|j�Sr&)�iterr"rrrr�__iter__^� zHeaders.__iter__�intcCr?r&)rr"rrrr�__len__arBzHeaders.__len__cCs*|j|��}t|�dkr|dSt|��r)r"r;rr �rr-r.rrr� __getitem__fs zHeaders.__getitem__r.cCs,|j�|��g��|�|j�||f�dSr&)r"� setdefaultr;�appendr#rErrr� __setitem__mszHeaders.__setitem__cs.|���|j����fdd�|jD�|_dS)Ncs$g|]\}}|���kr||f�qSr)r;)r,�k�v�� key_lowerrr� <listcomp>us$z'Headers.__delitem__.<locals>.<listcomp>)r;r"� __delitem__r#r<rrLrrOqs zHeaders.__delitem__�otherrcCst|t�stS|j|jkSr&)r:r �NotImplementedr")rrPrrr�__eq__ws  zHeaders.__eq__cCsi|_g|_dS)z& Remove all headers. N)r"r#rrrr�clear|s z Headers.clearcs(tdd�|D��}t�j|i|��dS)zT Update from a :class:`Headers` instance and/or keyword arguments. css&�|]}t|t�r |��n|VqdSr&)r:r � raw_items)r,�argrrrr/�s� �z!Headers.update.<locals>.<genexpr>N)�tuplerr'r(rrrr'�s�zHeaders.update� list[str]cCs|j�|��g�S)z| Return the (possibly empty) list of all values for a header. Args: key: Header name. )r"�getr;r<rrr�get_all�szHeaders.get_all�Iterator[tuple[str, str]]cCr?)zO Return an iterator of all values as ``(name, value)`` pairs. )r@r#rrrrrT�s zHeaders.raw_items)rr r$rr r%r)r r )r r5)r-r8r r9)r r>)r rC�r-rr r)r-rr.rr r%)r-rr r%)rPrr r9)r r%)r-rr rW)r rZ)rrrr � __slots__r)rr3r4r7r=rArDrFrIrOrRrSr'rYrTr!rrrrr s&%               r c@s$eZdZdZd dd�Zd dd �Zd S) �SupportsKeysAndGetItemz_ Dict-like types with ``keys() -> str`` and ``__getitem__(key: str) -> str`` methods. r � Iterable[str]cC�dSr&rrrrr�keys��zSupportsKeysAndGetItem.keysr-rcCr_r&rr<rrrrF�raz"SupportsKeysAndGetItem.__getitem__N)r r^r[)rrrr r`rFrrrrr]�s r]N)� __future__r�collections.abcrrrr�typingrrr �__all__� LookupErrorr rr r]rVr rrrr�<module>s     ��
Memory