
    ,i                       d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZmZmZmZ ddlmZmZmZmZ dd	lmZ erdd
lmZ ddlmZ  G d de      Z G d de      Zej<                  Zej>                  Z G d d      Z y)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                  (    e Zd ZdZdZdZdZdZdZdZ	y)	ConnectionStatez1
    RFC 6455, Section 4 - Opening Handshake
    r   r               N)
__name__
__module____qualname____doc__
CONNECTINGOPENREMOTE_CLOSINGLOCAL_CLOSINGCLOSED	REJECTING     a/var/www/system.tvplus.app.br/jogos/scrap/venv/lib/python3.12/site-packages/wsproto/connection.pyr   r      s'    
 JDNMFIr'   r   c                      e Zd ZdZdZdZy)ConnectionTypez#An enumeration of connection types.r   r   N)r   r   r   r   CLIENTSERVERr&   r'   r(   r*   r*   2   s    - F Fr'   r*   c                  V    e Zd ZdZ	 	 d	 	 	 	 	 	 	 d	dZed
d       ZddZddZddZ	y)
Connectiona
  
    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                    |t         j                  u | _        t               | _        t        | j                  |xs g       | _        t        j                  | _	        | j                  |       y)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__zConnection.__init__I   sQ      &)>)>>%*W#DKK1ArB%**-(r'   c                    | j                   S )N)r3   )r5   s    r(   statezConnection.state_   s    {{r'   c                   d}t        |t              rR| j                  t        j                  k(  r5|| j
                  j                  |j                  |j                        z  }|S t        |t              rG| j                  t        j                  k(  r*|| j
                  j                  |j                        z  }|S t        |t              rG| j                  t        j                  k(  r*|| j
                  j                  |j                        z  }|S t        |t              r| j                  t        j                  t        j                  hv r~|| j
                  j!                  |j"                  |j$                        z  }| j                  t        j                  k(  rt        j&                  | _        |S t        j*                  | _        |S d| d| j                   d}t-        |      )Nr'   zEvent z cannot be sent in state .)
isinstancer   r;   r   r!   r2   	send_datadatamessage_finishedr   pingpayloadr   pongr	   r"   closecodereasonr$   r3   r#   r   )r5   eventr@   msgs       r(   sendzConnection.sendc   s   eW%$**8L8L*LDKK))%**e6L6LMMD& % t$7K7K)KDKK$$U]]33D" ! t$7K7K)KDKK$$U]]33D  /DJJ  **C
 5
 DKK%%ejj%,,??Dzz_;;;-44  .;; 	 5'!:4::,aHC$ r'   c                |   |I| j                   j                  t        t        j                               t
        j                  | _        y| j                  t
        j                  t
        j                  fv r| j                  j                  |       y| j                  t
        j                  u rd}t        |      y)aO  
        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)rF   zConnection already closed.)r1   appendr	   r   ABNORMAL_CLOSUREr   r$   r3   r;   r!   r#   r2   receive_bytesr   )r5   r@   rI   s      r(   r4   zConnection.receive_data{   s     <
 LL[5Q5Q RS)00DK::/..0M0MNNKK%%d+ZZ?111.C$S))r'   c              #    K   | j                   r)| j                   j                          | j                   r)	 | j                  j                         D ]^  }|j                  t
        j                  u rW|j                  sJ |j                  sJ t        |j                  t        t        f      sJ t        |j                         w|j                  t
        j                  u rW|j                  sJ |j                  sJ t        |j                  t        t        f      sJ t        |j                         |j                  t
        j                   u rt        |j                  t"              sJ |j                  \  }}| j$                  t&        j(                  u rt&        j*                  | _        nt&        j.                  | _        t1        ||       |j                  t
        j2                  u rLt        |j                  t4              sJ t7        |j                  |j                  |j                         |j                  t
        j8                  u rRt        |j                  t        t        f      sJ t;        |j                  |j                  |j                         _a y# t<        $ r,}t1        |j>                  t5        |             Y d}~yd}~ww xY ww)z
        Return a generator that provides any events that have been generated
        by protocol activity.

        :returns: generator of :class:`Event <wsproto.events.Event>` subclasses
        )rC   )rF   rG   )r@   frame_finishedrA   N) r1   popleftr2   received_framesopcoder   PINGrP   rA   r>   rC   bytes	bytearrayr   PONGr   CLOSEtupler;   r   r#   r$   r3   r"   r	   TEXTstrr   BINARYr   r   rF   )r5   framerF   rG   excs        r(   eventszConnection.events   s-     ll,,&&(( ll*	B446 '<<6;;. //// 1111%emmeY5GHHHu}}55\\V[[0 //// 1111%emmeY5GHHHu}}55\\V\\1%emmU;;;#(==LD&zz_%B%BB&5&<&<&5&D&D)tFCC\\V[[0%emmS999%"]]',';';).)?)?  \\V]]2%emmeY5GHHH&"]]',';';).)?)?  O'P  	B!sxxCAA	Bs/   5K.I<J6 5K.6	K+?"K&!K.&K++K.)Nr'   )r6   r*   r7   zlist[Extension] | Noner8   rU   returnNone)r`   r   )rH   r
   r`   rU   )r@   zbytes | Noner`   ra   )r`   zGenerator[Event, None, None])
r   r   r   r   r9   propertyr;   rJ   r4   r_   r&   r'   r(   r.   r.   @   s^     .2"	)') +) 	)
 
),  064Br'   r.   N)!r   
__future__r   collectionsr   enumr   typingr   r_   r   r	   r
   r   r   r   r   frame_protocolr   r   r   r   	utilitiesr   collections.abcr   r7   r   r   r*   r+   r,   r.   r&   r'   r(   <module>rj      sz    #       L K ))%d &T  
					JB JBr'   