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: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/websockets/legacy/__pycache__/auth.cpython-310.pyc
o

�h��@s�ddlmZddlZddlZddlZddlmZmZddlm	Z	m
Z
mZddlm
Z
ddlmZddlmZmZd	d
lmZmZddgZeeefZddd�ZGdd�de�Z				dd dd�ZdS)!�)�annotationsN)�	Awaitable�Iterable)�Any�Callable�cast�)�Headers)�
InvalidHeader)�build_www_authenticate_basic�parse_authorization_basic�)�HTTPResponse�WebSocketServerProtocol� BasicAuthWebSocketServerProtocol�basic_auth_protocol_factory�valuer�return�boolc	Cs:z|\}}WnttfyYdSwt|t�ot|t�S�NF)�	TypeError�
ValueError�
isinstance�str)r�username�password�r�I/usr/local/CyberCP/lib/python3.10/site-packages/websockets/legacy/auth.py�is_credentialss�rcs`eZdZUdZdZded<	dZded<	ddd�d�fdd�Zddd�Zd�fdd�Z	�Z
S)rzC
    WebSocket server protocol that enforces HTTP Basic Auth.

    �r�realmN�
str | Noner�r �check_credentials�argsrr#�,Callable[[str, str], Awaitable[bool]] | None�kwargsr�Nonecs*|dur||_||_t�j|i|��dS�N)r �_check_credentials�super�__init__)�selfr r#r$r&��	__class__rrr+.sz)BasicAuthWebSocketServerProtocol.__init__rrc�s"�|jdur|�||�IdHSdS)a�
        Check whether credentials are authorized.

        This coroutine may be overridden in a subclass, for example to
        authenticate against a database or an external service.

        Args:
            username: HTTP Basic Auth username.
            password: HTTP Basic Auth password.

        Returns:
            :obj:`True` if the handshake should continue;
            :obj:`False` if it should fail with an HTTP 401 error.

        NF)r))r,rrrrrr#:s�
z2BasicAuthWebSocketServerProtocol.check_credentials�path�request_headersr	�HTTPResponse | Nonec�s��z|d}Wntytjjdt|j�fgdfYSwzt|�\}}Wnty<tjjdt|j�fgdfYSw|�||�IdHsStjjdt|j�fgdfS||_	t
��||�IdHS)zS
        Check HTTP Basic Auth and return an HTTP 401 response if needed.

        �
AuthorizationzWWW-AuthenticatesMissing credentials
sUnsupported credentials
NsInvalid credentials
)�KeyError�http�
HTTPStatus�UNAUTHORIZEDrr rr
r#rr*�process_request)r,r/r0�
authorizationrrr-rrr7Os0�	�����z0BasicAuthWebSocketServerProtocol.process_request)
r$rr r!r#r%r&rrr'�rrrrrr)r/rr0r	rr1)�__name__�
__module__�__qualname__�__doc__r �__annotations__rr+r#r7�
__classcell__rrr-rrs
�
r r!�credentials�*Credentials | Iterable[Credentials] | Noner#r%�create_protocol�6Callable[..., BasicAuthWebSocketServerProtocol] | None�/Callable[..., BasicAuthWebSocketServerProtocol]cs�|du|dukrtd��|durLt|�rtt|�g}n&t|t�r:tttt|��}tdd�|D��s9td|����ntd|����t|��d�fdd�}|durRt	}tt
d
t	f|�}tj|||d�S)a
    Protocol factory that enforces HTTP Basic Auth.

    :func:`basic_auth_protocol_factory` is designed to integrate with
    :func:`~websockets.legacy.server.serve` like this::

        serve(
            ...,
            create_protocol=basic_auth_protocol_factory(
                realm="my dev server",
                credentials=("hello", "iloveyou"),
            )
        )

    Args:
        realm: Scope of protection. It should contain only ASCII characters
            because the encoding of non-ASCII characters is undefined.
            Refer to section 2.2 of :rfc:`7235` for details.
        credentials: Hard coded authorized credentials. It can be a
            ``(username, password)`` pair or a list of such pairs.
        check_credentials: Coroutine that verifies credentials.
            It receives ``username`` and ``password`` arguments
            and returns a :class:`bool`. One of ``credentials`` or
            ``check_credentials`` must be provided but not both.
        create_protocol: Factory that creates the protocol. By default, this
            is :class:`BasicAuthWebSocketServerProtocol`. It can be replaced
            by a subclass.
    Raises:
        TypeError: If the ``credentials`` or ``check_credentials`` argument is
            wrong.

    Nz/provide either credentials or check_credentialscss�|]}t|�VqdSr()r)�.0�itemrrr�	<genexpr>�s�z.basic_auth_protocol_factory.<locals>.<genexpr>zinvalid credentials argument: rrrrrc�s0�z�|}Wn
tyYdSwt�||�Sr)r3�hmac�compare_digest)rr�expected_password��credentials_dictrrr#�s��z6basic_auth_protocol_factory.<locals>.check_credentials.r"r9)
rrr�Credentialsrr�list�all�dictrr�	functools�partial)r r@r#rB�credentials_listrrKrrvs.&
���)rrrr)NNNN)
r r!r@rAr#r%rBrCrrD)�
__future__rrQrHr4�collections.abcrr�typingrrr�datastructuresr	�
exceptionsr
�headersrr�serverrr�__all__�tuplerrMrrrrrrr�<module>s&
	Z�