o
    ]i                     @  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.1c                   @  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   CLIENTclientr   	handshake
connection)selfr    r   U/var/www/html/stock_analysis/be/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