o
    ¨Ýj™  ã                   @  s~   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
 er2ddlmZ ddlmZ dd	lmZ d
ZG dd„ dƒZdZdS )z.
wsproto
~~~~~~~

A WebSocket implementation.
é    )Úannotations)ÚTYPE_CHECKINGé   )Ú
ConnectionÚConnectionStateÚConnectionType)ÚH11Handshake)Ú	Generator)ÚEvent)ÚHeadersz1.3.2c                   @  sP   e Zd ZdZddd„Zedd	d
„ƒZd dd„Zd!dd„Zd"dd„Z	d#dd„Z
dS )$ÚWSConnectionzN
    Represents the local end of a WebSocket connection to a remote peer.
    Úconnection_typer   ÚreturnÚNonec                 C  s    |t ju | _t|ƒ| _d| _dS )z­
        Constructor

        :param wsproto.connection.ConnectionType connection_type: Controls
            whether the library behaves as a client or as a server.
        N)r   ZCLIENTÚclientr   Ú	handshakeÚ
connection)Úselfr   © r   úK/var/www/html/chatgpt/venv/lib/python3.10/site-packages/wsproto/__init__.pyÚ__init__   s   

zWSConnection.__init__r   c                 C  s   | j du r	| jjS | j jS )z_
        :returns: Connection state
        :rtype: wsproto.connection.ConnectionState
        N)r   r   Ústate©r   r   r   r   r   '   s   
zWSConnection.stateÚheadersr   Úpathúbytes | strc                 C  s   | j  ||¡ d S )N)r   Úinitiate_upgrade_connection)r   r   r   r   r   r   r   1   s   z(WSConnection.initiate_upgrade_connectionÚeventr
   Úbytesc                 C  s@   d}| j du r|| j |¡7 }| jj | _ |S || j  |¡7 }|S )a‹  
        Generate network data for the specified event.

        When you want to communicate with a WebSocket peer, you should construct
        an event and pass it to this method. This method will return the bytes
        that you should send to the peer.

        :param wsproto.events.Event event: The event to generate data for
        :returns bytes: The data to send to the peer
        ó    N)r   r   Úsend)r   r   Údatar   r   r   r    6   s   

ÿzWSConnection.sendr!   úbytes | Nonec                 C  s4   | j du r| j |¡ | jj | _ dS | j  |¡ dS )zý
        Feed network data into the connection instance.

        After calling this method, you should call :meth:`events` to see if the
        received data triggered any new events.

        :param bytes data: Data received from remote peer
        N)r   r   Úreceive_data)r   r!   r   r   r   r#   I   s   
	zWSConnection.receive_dataúGenerator[Event, None, None]c                 c  s4   � | j  ¡ E dH  | jdur| j ¡ E dH  dS dS )z”
        A generator that yields pending events.

        Each event is an instance of a subclass of
        :class:`wsproto.events.Event`.
        N)r   Úeventsr   r   r   r   r   r%   X   s
   €
ÿzWSConnection.eventsN)r   r   r   r   )r   r   )r   r   r   r   r   r   )r   r
   r   r   )r!   r"   r   r   )r   r$   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r    r#   r%   r   r   r   r   r      s    

	

r   )r   r   N)r)   Ú
__future__r   Útypingr   r   r   r   r   r   r   Úcollections.abcr	   r%   r
   r   Ú__version__r   Ú__all__r   r   r   r   Ú<module>   s    M