HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/websockets/__pycache__/headers.cpython-310.pyc
o

�h�>�@s�ddlmZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZddlm
Z
mZddlmZmZmZmZmZmZgd�Ze
d	�Zd
d�dmdd�Zdndd�Ze�d�Zdodd�Ze�d�Zdpd!d"�Ze�d#�Ze�d$�Zdpd%d&�Z e�d'�Z!e�d(�Z"dqd*d+�Z#drd/d0�Z$dsd2d3�Z%dtd5d6�Z&e�d7�Z'dud9d:�Z(dvd<d=�Z)dwd?d@�Z*dxdBdC�Z+dydEdF�Z,e,Z-dzdKdL�Z.d{dOdP�Z/e/Z0d|dRdS�Z1d}dUdV�Z2e2Z3d~dYdZ�Z4e4Z5dd\d]�Z6d�d_d`�Z7e�da�Z8dpdbdc�Z9d�ddde�Z:d�dgdh�Z;d�dkdl�Z<dS)��)�annotationsN)�Sequence)�Callable�TypeVar�cast�)�InvalidHeaderFormat�InvalidHeaderValue)�ConnectionOption�ExtensionHeader�
ExtensionName�ExtensionParameter�Subprotocol�UpgradeProtocol)�
build_host�parse_connection�
parse_upgrade�parse_extension�build_extension�parse_subprotocol�build_subprotocol�validate_subprotocols�build_www_authenticate_basic�parse_authorization_basic�build_authorization_basic�TF)�always_include_port�host�str�port�int�secure�boolr�returncCs^zt�|�}Wn	tyYnw|jdkrd|�d�}|s&||r#dndkr-|�d|��}|S)z#
    Build a ``Host`` header.

    ��[�]i��P�:)�	ipaddress�
ip_address�
ValueError�version)rrr!r�address�r.�E/usr/local/CyberCP/lib/python3.10/site-packages/websockets/headers.pyr's
�
r�header�pos�
str | NonecCs|t|�krdS||S)z�
    Return the next character from ``header`` at the given position.

    Return :obj:`None` at the end of ``header``.

    We never need to peek more than one character ahead.

    N)�len)r0r1r.r.r/�
peek_aheadIs	r4z[\t ]*cCs t�||�}|dusJ�|��S)z�
    Parse optional whitespace from ``header`` at the given position.

    Return the new position.

    The whitespace itself isn't returned because it isn't significant.

    N)�_OWS_re�match�end)r0r1r6r.r.r/�	parse_OWSXs
r8z[-!#$%&\'*+.^_`|~0-9a-zA-Z]+�header_name�tuple[str, int]cC�2t�||�}|durt|d||��|��|��fS)z�
    Parse a token from ``header`` at the given position.

    Return the token value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    Nzexpected token)�	_token_rer6r�groupr7�r0r1r9r6r.r.r/�parse_tokenj�
r?zC"(?:[\x09\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x09\x20-\x7e\x80-\xff])*"z\\([\x09\x20-\x7e\x80-\xff])cCsBt�||�}|durt|d||��t�d|��dd��|��fS)z�
    Parse a quoted string from ``header`` at the given position.

    Return the unquoted value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    Nzexpected quoted stringz\1r���)�_quoted_string_rer6r�_unquote_re�subr=r7r>r.r.r/�parse_quoted_string�s
 rEz[\x09\x20-\x7e\x80-\xff]*z([\x22\x5c])�valuecCs.t�|�}|dur
td��dt�d|�dS)zh
    Format ``value`` as a quoted string.

    This is the reverse of :func:`parse_quoted_string`.

    Nz-invalid characters for quoted-string encoding�"z\\\1)�_quotable_re�	fullmatchr+�	_quote_rerD)rFr6r.r.r/�build_quoted_string�s
rK�
parse_item�(Callable[[str, int, str], tuple[T, int]]�list[T]cCs�t||�dkrt||d�}t||�dksg}	||||�\}}|�|�t||�}|t|�kr1n3t||�dkr@t||d�}nt|d||��t||�dkr\t||d�}t||�dksN|t|�krcnq|t|�kslJ�|S)a�
    Parse a comma-separated list from ``header`` at the given position.

    This is appropriate for parsing values with the following grammar:

        1#item

    ``parse_item`` parses one item.

    ``header`` is assumed not to start or end with whitespace.

    (This function is designed for parsing an entire header value and
    :func:`~websockets.http.read_headers` strips whitespace from values.)

    Return a list of items.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    �,rTzexpected comma)r4r8�appendr3r)rLr0r1r9�items�itemr.r.r/�
parse_list�s*�

��rS�tuple[ConnectionOption, int]cC�t|||�\}}tt|�|fS)z�
    Parse a Connection option from ``header`` at the given position.

    Return the protocol value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    )r?rr
�r0r1r9rRr.r.r/�parse_connection_option��rW�list[ConnectionOption]cC�tt|dd�S)z�
    Parse a ``Connection`` header.

    Return a list of HTTP connection options.

    Args
        header: value of the ``Connection`` header.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    r�
Connection)rSrW�r0r.r.r/r��
rz>[-!#$%&\'*+.^_`|~0-9a-zA-Z]+(?:/[-!#$%&\'*+.^_`|~0-9a-zA-Z]+)?�tuple[UpgradeProtocol, int]cCs8t�||�}|durt|d||��tt|���|��fS)z�
    Parse an Upgrade protocol from ``header`` at the given position.

    Return the protocol value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    Nzexpected protocol)�_protocol_rer6rrrr=r7r>r.r.r/�parse_upgrade_protocolsr`�list[UpgradeProtocol]cCrZ)z�
    Parse an ``Upgrade`` header.

    Return a list of HTTP protocols.

    Args:
        header: Value of the ``Upgrade`` header.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    r�Upgrade)rSr`r\r.r.r/rr]r�tuple[ExtensionParameter, int]cCs�t|||�\}}t||�}d}t||�dkrJt||d�}t||�dkr=|}t|||�\}}t�|�dur<t|d||��nt|||�\}}t||�}||f|fS)z�
    Parse a single extension parameter from ``header`` at the given position.

    Return a ``(name, value)`` pair and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    N�=rrGzinvalid quoted header content)r?r8r4rEr<rIr)r0r1r9�namerF�
pos_beforer.r.r/�parse_extension_item_param.s 
��
rg�tuple[ExtensionHeader, int]cCstt|||�\}}t||�}g}t||�dkr1t||d�}t|||�\}}|�|�t||�dkstt|�|f|fS)a
    Parse an extension definition from ``header`` at the given position.

    Return an ``(extension name, parameters)`` pair, where ``parameters`` is a
    list of ``(name, value)`` pairs, and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    �;r)r?r8r4rgrPrr)r0r1r9re�
parameters�	parameterr.r.r/�parse_extension_itemRs

�rl�list[ExtensionHeader]cCrZ)a�
    Parse a ``Sec-WebSocket-Extensions`` header.

    Return a list of WebSocket extensions and their parameters in this format::

        [
            (
                'extension name',
                [
                    ('parameter name', 'parameter value'),
                    ....
                ]
            ),
            ...
        ]

    Parameter values are :obj:`None` when no value is provided.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    rzSec-WebSocket-Extensions)rSrlr\r.r.r/rksrrerrj�Sequence[ExtensionParameter]cCs d�tt|�gdd�|D��S)zc
    Build an extension definition.

    This is the reverse of :func:`parse_extension_item`.

    z; cSs*g|]\}}|dur|n|�d|���qS)Nrdr.)�.0rerFr.r.r/�
<listcomp>�s��z(build_extension_item.<locals>.<listcomp>)�joinrr)rerjr.r.r/�build_extension_item�s	
���rr�
extensions�Sequence[ExtensionHeader]cCsd�dd�|D��S)zl
    Build a ``Sec-WebSocket-Extensions`` header.

    This is the reverse of :func:`parse_extension`.

    �, css�|]
\}}t||�VqdS)N)rr)rorerjr.r.r/�	<genexpr>�s�
�z"build_extension.<locals>.<genexpr>�rq)rsr.r.r/r�s
�r�tuple[Subprotocol, int]cCrU)z�
    Parse a subprotocol from ``header`` at the given position.

    Return the subprotocol value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    )r?rrrVr.r.r/�parse_subprotocol_item�rXry�list[Subprotocol]cCrZ)z�
    Parse a ``Sec-WebSocket-Protocol`` header.

    Return a list of WebSocket subprotocols.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    rzSec-WebSocket-Protocol)rSryr\r.r.r/r�s
r�subprotocols�Sequence[Subprotocol]cCs
d�|�S)zl
    Build a ``Sec-WebSocket-Protocol`` header.

    This is the reverse of :func:`parse_subprotocol`.

    rurw)r{r.r.r/r�s
r�NonecCsJt|t�s	td��t|t�rtd��|D]}t�|�s"td|����qdS)zT
    Validate that ``subprotocols`` is suitable for :func:`build_subprotocol`.

    zsubprotocols must be a listz&subprotocols must be a list, not a strzinvalid subprotocol: N)�
isinstancer�	TypeErrorrr<rIr+)r{�subprotocolr.r.r/r�s


��r�realmcCs t|�}td�}d|�d|��S)z�
    Build a ``WWW-Authenticate`` header for HTTP Basic Auth.

    Args:
        realm: Identifier of the protection space.

    zUTF-8zBasic realm=z
, charset=)rK)r��charsetr.r.r/r�s	rz[A-Za-z0-9-._~+/]+=*cCr;)z�
    Parse a token68 from ``header`` at the given position.

    Return the token value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    Nzexpected token68)�_token68_rer6rr=r7r>r.r.r/�
parse_token68�r@r�cCs|t|�kr
t|d||��dS)z8
    Check that parsing reached the end of header.

    z
trailing dataN)r3r)r0r1r9r.r.r/�	parse_ends�r��tuple[str, str]cCs�t|dd�\}}|��dkrtdd|����t||�dkr$tdd||��|d7}t||d�\}}t||d�zt�|�	���
�}WntjyOtdd�d	�wz
|�
d
d�\}}W||fStyjtdd�d	�w)a!
    Parse an ``Authorization`` header for HTTP Basic Auth.

    Return a ``(username, password)`` tuple.

    Args:
        header: Value of the ``Authorization`` header.

    Raises:
        InvalidHeaderFormat: On invalid inputs.
        InvalidHeaderValue: On unsupported inputs.

    r�
Authorization�basiczunsupported scheme: � zexpected space after schemerz#expected base64-encoded credentialsNr(z&expected username:password credentials)r?�lowerr	r4rr�r��base64�	b64decode�encode�decode�binascii�Error�splitr+)r0�schemer1�basic_credentials�	user_pass�username�passwordr.r.r/rsD���������rr�r�cCs4d|vsJ�|�d|��}t�|�����}d|S)z�
    Build an ``Authorization`` header for HTTP Basic Auth.

    This is the reverse of :func:`parse_authorization_basic`.

    r(zBasic )r��	b64encoder�r�)r�r�r�r�r.r.r/r?sr)
rrrr r!r"rr"r#r)r0rr1r r#r2)r0rr1r r#r )r0rr1r r9rr#r:)rFrr#r)
rLrMr0rr1r r9rr#rN)r0rr1r r9rr#rT)r0rr#rY)r0rr1r r9rr#r^)r0rr#ra)r0rr1r r9rr#rc)r0rr1r r9rr#rh)r0rr#rm)rerrjrnr#r)rsrtr#r)r0rr1r r9rr#rx)r0rr#rz)r{r|r#r)r{r|r#r})r�rr#r)r0rr1r r9rr#r})r0rr#r�)r�rr�rr#r)=�
__future__rr�r�r)�re�collections.abcr�typingrrr�
exceptionsrr	r
rrr
rr�__all__rrr4�compiler5r8r<r?rBrCrErHrJrKrSrWrr_r`rrgrlr�parse_extension_listrrr�build_extension_listryr�parse_subprotocol_listr�build_subprotocol_listrrr�r�r�rrr.r.r.r/�<module>sj 
�
"



�






B
�



$












	0