
    < j                       S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
JrJrJrJrJrJr  SSKJrJrJrJr  SS	KJr  \(       a  SS
KJr  SSKJr   " S S\5      r " S S\5      r\R<                  r\R>                  r " S S5      r g)zU
wsproto/connection
~~~~~~~~~~~~~~~~~~

An implementation of a WebSocket connection.
    )annotations)deque)Enum)TYPE_CHECKING   )BytesMessageCloseConnectionEventMessagePingPongTextMessage)CloseReasonFrameProtocolOpcodeParseFailed)LocalProtocolError)	Generator)	Extensionc                  0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)ConnectionState   z)
RFC 6455, Section 4 - Opening Handshake
r   r                N)__name__
__module____qualname____firstlineno____doc__
CONNECTINGOPENREMOTE_CLOSINGLOCAL_CLOSINGCLOSED	REJECTING__static_attributes__r       c/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/wsproto/connection.pyr   r      s'    
 JDNMFIr*   r   c                       \ rS rSrSrSrSrSrg)ConnectionType2   z#An enumeration of connection types.r   r   r   N)r   r   r    r!   r"   CLIENTSERVERr)   r   r*   r+   r-   r-   2   s    - F Fr*   r-   c                  j    \ rS rSrSr  S
       SS jjr\SS j5       rSS jrSS jr	SS jr
S	rg)
Connection@   z
A low-level WebSocket connection object.

This wraps two other protocol objects, an HTTP/1.1 protocol object used
to do the initial HTTP upgrade handshake and a WebSocket frame protocol
object used to exchange messages and other control frames.
Nc                    U[         R                  L U l        [        5       U l        [        U R                  U=(       d    / 5      U l        [        R                  U l	        U R                  U5        g)a`  
Constructor

:param wsproto.connection.ConnectionType connection_type: Whether this
    object is on the client- or server-side of a connection.
    To initialise as a client pass ``CLIENT`` otherwise pass ``SERVER``.
:param list extensions: The proposed extensions.
:param bytes trailing_data: Data that has been received, but not yet
    processed.
N)r-   r/   clientr   _eventsr   _protor   r$   _statereceive_data)selfconnection_type
extensionstrailing_datas       r+   __init__Connection.__init__I   sQ      &)>)>>%*W#DKK1ArB%**-(r*   c                    U R                   $ )N)r8   )r:   s    r+   stateConnection.state_   s    {{r*   c                   Sn[        U[        5      (       aR  U R                  [        R                  :X  a4  X R
                  R                  UR                  UR                  5      -  nU$ [        U[        5      (       aG  U R                  [        R                  :X  a)  X R
                  R                  UR                  5      -  nU$ [        U[        5      (       aG  U R                  [        R                  :X  a)  X R
                  R                  UR                  5      -  nU$ [        U[        5      (       a  U R                  [        R                  [        R                  1;   a  X R
                  R!                  UR"                  UR$                  5      -  nU R                  [        R                  :X  a  [        R&                  U l        U$ [        R*                  U l         U$ SU SU R                   S3n[-        U5      e)Nr*   zEvent z cannot be sent in state .)
isinstancer   rA   r   r$   r7   	send_datadatamessage_finishedr   pingpayloadr   pongr	   r%   closecodereasonr'   r8   r&   r   )r:   eventrG   msgs       r+   sendConnection.sendc   s   eW%%$**8L8L*LKK))%**e6L6LMMD& % t$$7K7K)KKK$$U]]33D" ! t$$7K7K)KKK$$U]]33D  //DJJ  **C
 5
 KK%%ejj%,,??Dzz_;;;-44  .;; 	 5'!:4::,aHC$ r*   c                ~   UcF  U R                   R                  [        [        R                  S95        [
        R                  U l        gU R                  [
        R                  [
        R                  4;   a  U R                  R                  U5        gU R                  [
        R                  L a  Sn[        U5      eg)a  
Pass some received data to the connection for handling.

A list of events that the remote peer triggered by sending this data can
be retrieved with :meth:`~wsproto.connection.Connection.events`.

:param data: The data received from the remote peer on the network.
:type data: ``bytes``
N)rM   zConnection already closed.)r6   appendr	   r   ABNORMAL_CLOSUREr   r'   r8   rA   r$   r&   r7   receive_bytesr   )r:   rG   rP   s      r+   r9   Connection.receive_data{   s     <
 LL[5Q5Q RS)00DK::/..0M0MNNKK%%d+ZZ?111.C$S))r*   c              #  F  #    U R                   (       a/  U R                   R                  5       v   U R                   (       a  M/   U R                  R                  5        GH  nUR                  [
        R                  L ad  UR                  (       d   eUR                  (       d   e[        UR                  [        [        45      (       d   e[        UR                  S9v   M  UR                  [
        R                  L ae  UR                  (       d   eUR                  (       d   e[        UR                  [        [        45      (       d   e[        UR                  S9v   GM  UR                  [
        R                   L a  [        UR                  ["        5      (       d   eUR                  u  p#U R$                  [&        R(                  L a  [&        R*                  U l        O[&        R.                  U l        [1        X#S9v   GM  UR                  [
        R2                  L aO  [        UR                  [4        5      (       d   e[7        UR                  UR                  UR                  S9v   GM  UR                  [
        R8                  L aU  [        UR                  [        [        45      (       d   e[;        UR                  UR                  UR                  S9v   GM  GM     g! [<         a)  n[1        UR>                  [5        U5      S9v    SnAgSnAff = f7f)z
Return a generator that provides any events that have been generated
by protocol activity.

:returns: generator of :class:`Event <wsproto.events.Event>` subclasses
)rJ   )rM   rN   )rG   frame_finishedrH   N) r6   popleftr7   received_framesopcoder   PINGrY   rH   rE   rJ   bytes	bytearrayr   PONGr   CLOSEtuplerA   r   r&   r'   r8   r%   r	   TEXTstrr   BINARYr   r   rM   )r:   framerM   rN   excs        r+   eventsConnection.events   s4     ll,,&&(( lll*	B446<<6;;. //// 1111%emmeY5GHHHHu}}55\\V[[0 //// 1111%emmeY5GHHHHu}}55\\V\\1%emmU;;;;#(==LDzz_%B%BB&5&<&<&5&D&D)tCC\\V[[0%emmS9999%"]]',';';).)?)?  \\V]]2%emmeY5GHHHH&"]]',';';).)?)?  O 7P  	B!sxxCAA	Bs0   ?L!J&K+ *L!+
L5LL!LL!)r6   r7   r8   r5   )Nr*   )r;   r-   r<   zlist[Extension] | Noner=   r^   returnNone)rj   r   )rO   r
   rj   r^   )rG   zbytes | Nonerj   rk   )rj   zGenerator[Event, None, None])r   r   r    r!   r"   r>   propertyrA   rQ   r9   rh   r)   r   r*   r+   r2   r2   @   s^     .2"	)') +) 	)
 
),  064Br*   r2   N)!r"   
__future__r   collectionsr   enumr   typingr   rh   r   r	   r
   r   r   r   r   frame_protocolr   r   r   r   	utilitiesr   collections.abcr   r<   r   r   r-   r/   r0   r2   r   r*   r+   <module>rt      sz    #       L K ))%d &T  
					JB JBr*   