o
    RhG                     @   sj   d Z ddlmZmZmZ ddlmZmZmZ d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.
    )	GeneratorOptionalUnion   )
ConnectionConnectionStateConnectionType)Event)H11Handshake)Headersz1.2.0c                   @   s   e Zd ZdZdeddfddZedefddZd	e	d
e
eef ddfddZdedefddZdee ddfddZdeeddf fddZdS )WSConnectionzN
    Represents the local end of a WebSocket connection to a remote peer.
    connection_typereturnNc                 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   CLIENTclientr
   	handshake
connection)selfr    r   R/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/wsproto/__init__.py__init__   s   

zWSConnection.__init__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headerspathc                 C   s   | j || d S )N)r   initiate_upgrade_connection)r   r   r   r   r   r   r   +   s   z(WSConnection.initiate_upgrade_connectioneventc                 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   0   s   

zWSConnection.sendr   c                 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    C   s   
	zWSConnection.receive_datac                 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!   R   s
   
zWSConnection.events)__name__
__module____qualname____doc__r   r   propertyr   r   r   r   bytesstrr   r	   r   r   r    r   r!   r   r   r   r   r      s    	

r   )r   r   N)r%   typingr   r   r   r   r   r   r   r!   r	   r   r
   r   __version__r   __all__r   r   r   r   <module>   s    M