+
    ioj                       ^ RI Ht ^ RIt^ RIt^ RIt^ RIHt ^RIHtH	t	H
t
HtHtHt ^RIHt ^RIHtHtHtHtHtHtHtHtHtHt ^RIHtHt ^RIHt ^R	I H!t!H"t"H#t#H$t$ . ROt%]],          ],          t&  ! R R]PN                  4      t(](PR                  t)](PT                  t* ! R R]PN                  4      t+]+PX                  t,]+PZ                  t-]+P\                  t.]+P^                  t/Rt0  ! R R
4      t1R# )    )annotationsN)	Generator)ConnectionClosedConnectionClosedErrorConnectionClosedOKInvalidStatePayloadTooBigProtocolError)	Extension)
OK_CLOSE_CODES	OP_BINARYOP_CLOSEOP_CONTOP_PINGOP_PONGOP_TEXTClose	CloseCodeFrame)RequestResponse)StreamReader)	BytesLike
LoggerLikeOriginSubprotocolProtocolSideStatec                  0    ] tR t^-tRt]! ^4      w  ttRtR# )r   z6A WebSocket connection is either a server or a client. N)	__name__
__module____qualname____firstlineno____doc__rangeSERVERCLIENT__static_attributes__r!       Z/home/wkmabra/.openclaw/workspace/venv/lib/python3.14/site-packages/websockets/protocol.pyr   r   -   s    @1XNFFr+   c                  4    ] tR t^7tRt]! ^4      w  tttt	Rt
R# )r   z6A WebSocket connection is in one of these four states.r!   N)r"   r#   r$   r%   r&   r'   
CONNECTINGOPENCLOSINGCLOSEDr*   r!   r+   r,   r   r   7   s    @(-a%Jgvr+   r+   c                     ] tR t^GtRtR]RR5RR/R R llt]R R	 l4       t]P                  R
 R l4       t]R R l4       t
]R R l4       t]R R l4       tR R ltR R ltR R ltR6R R lltR6R R lltR7R R lltR R ltR  R! ltR8R" R# lltR$ R% ltR& R' ltR( R) ltR* R+ ltR, R- ltR. R/ ltR0 R1 ltR2 R3 ltR4tR# )9r   a  
Sans-I/O implementation of a WebSocket connection.

Args:
    side: :attr:`~Side.CLIENT` or :attr:`~Side.SERVER`.
    state: Initial state of the WebSocket connection.
    max_size: Maximum size of incoming messages in bytes.
        :obj:`None` disables the limit. You may pass a ``(max_message_size,
        max_fragment_size)`` tuple to set different limits for messages and
        fragments when you expect long messages sent in short fragments.
    logger: Logger for this connection; depending on ``side``,
        defaults to ``logging.getLogger("websockets.client")``
        or ``logging.getLogger("websockets.server")``;
        see the :doc:`logging guide <../../topics/logging>` for details.

statemax_sizeloggerNc          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )   sider   r3   r   r4   z*tuple[int | None, int | None] | int | Noner5   zLoggerLike | NonereturnNoner!   )formats   "r,   __annotate__Protocol.__annotate__Y   sC     E1 E1E1 	E1
 =E1 "E1 
E1r+   c               	   \         P                  ! 4       V n         Vf2   \        P                  ! RVP
                  P                  4        24      pW@n         VP                  \        P                  4      V n
        Wn        W n        \        V\        4      '       g   Vf   VR uV n        V n        MVw  V n        V n        R V n        RV n        R V n        . V n        R V n        R V n        R V n        R V n        R V n         RV n        \7        4       V n        . V n        . V n        V P?                  4       V n         \C        V P@                  4       R V n"        R # )Nzwebsockets.F)#uuiduuid4idlogging	getLoggernamelowerr5   isEnabledForDEBUGdebugr8   r3   
isinstanceintmax_message_sizemax_fragment_sizecurrent_sizeexpect_continuation_frameorigin
extensionssubprotocol
close_rcvd
close_sentclose_rcvd_then_senthandshake_exceof_sentr   readereventswritesparseparsernext
parser_exc)selfr8   r3   r4   r5   s   &&$$$r,   __init__Protocol.__init__Y   s7    "ZZ\B >&&TYY__5F4G'HIF"() ((7
 	 
 h$$(8<Dd9D!4#9<D9D!4#9 )- */& &*+-/3 )-(,15! 04	  #n#%#%jjlT[[,0r+   c                   V ^8  d   QhRR/# )r7   r9   r   r!   )r;   s   "r,   r<   r=      s      u r+   c                    V P                   # )au  
State of the WebSocket connection.

Defined in 4.1_, 4.2_, 7.1.3_, and 7.1.4_ of :rfc:`6455`.

.. _4.1: https://datatracker.ietf.org/doc/html/rfc6455#section-4.1
.. _4.2: https://datatracker.ietf.org/doc/html/rfc6455#section-4.2
.. _7.1.3: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.3
.. _7.1.4: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.4

)_stater^   s   &r,   r3   Protocol.state   s     {{r+   c                    V ^8  d   QhRRRR/# )r7   r3   r   r9   r:   r!   )r;   s   "r,   r<   r=      s      5 T r+   c                	    V P                   '       d'   V P                  P                  R VP                  4       Wn        R# )z= connection is %sN)rH   r5   rD   rc   )r^   r3   s   &&r,   r3   re      s)    :::KK2EJJ?r+   c                   V ^8  d   QhRR/# )r7   r9   z
int | Noner!   )r;   s   "r,   r<   r=      s     ( (J (r+   c                    V P                   \        Jd   R# V P                  f   \        P                  # V P                  P
                  # )z
WebSocket close code received from the remote endpoint.

Defined in 7.1.5_ of :rfc:`6455`.

.. _7.1.5: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5

:obj:`None` if the connection isn't closed yet.

N)r3   r1   rR   r   ABNORMAL_CLOSUREcoderd   s   &r,   
close_codeProtocol.close_code   s9     ::V#__$---??'''r+   c                   V ^8  d   QhRR/# )r7   r9   z
str | Noner!   )r;   s   "r,   r<   r=      s     * *j *r+   c                z    V P                   \        Jd   R# V P                  f   R# V P                  P                  # )z
WebSocket close reason  received from the remote endpoint.

Defined in 7.1.6_ of :rfc:`6455`.

.. _7.1.6: https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.6

:obj:`None` if the connection isn't closed yet.

N )r3   r1   rR   reasonrd   s   &r,   close_reasonProtocol.close_reason   s0     ::V#__$??)))r+   c                   V ^8  d   QhRR/# )r7   r9   r   r!   )r;   s   "r,   r<   r=      s     ! !+ !r+   c                |   V P                   \        J g   Q R4       hV P                  eT   V P                  eF   V P                  P                  \
        9   d'   V P                  P                  \
        9   d   \        pM\        pV! V P                  V P                  V P                  4      pV P                  Vn
        V# )a  
Exception to raise when trying to interact with a closed connection.

Don't raise this exception while the connection :attr:`state`
is :attr:`~websockets.protocol.State.CLOSING`; wait until
it's :attr:`~websockets.protocol.State.CLOSED`.

Indeed, the exception includes the close code and reason, which are
known only once the connection is closed.

Raises:
    AssertionError: If the connection isn't closed yet.

zconnection isn't closed yet)r3   r1   rR   rS   rk   r   r   r   rT   r]   	__cause__)r^   exc_typeexcs   &  r,   	close_excProtocol.close_exc   s      zzV#B%BB# OO'+$$6$$6)H,H (OOOO%%!
 
r+   c                    V ^8  d   QhRRRR/# )r7   datazbytes | bytearrayr9   r:   r!   )r;   s   "r,   r<   r=     s      !2 t r+   c                f    V P                   P                  V4       \        V P                  4       R# )a  
Receive data from the network.

After calling this method:

- You must call :meth:`data_to_send` and send this data to the network.
- You should call :meth:`events_received` and process resulting events.

Raises:
    EOFError: If :meth:`receive_eof` was called earlier.

N)rW   	feed_datar\   r[   r^   r|   s   &&r,   receive_dataProtocol.receive_data  s"     	d#T[[r+   c                   V ^8  d   QhRR/# r7   r9   r:   r!   )r;   s   "r,   r<   r=     s      T r+   c                    V P                   P                  '       d   R# V P                   P                  4        \        V P                  4       R# )aa  
Receive the end of the data stream from the network.

After calling this method:

- You must call :meth:`data_to_send` and send this data to the network;
  it will return ``[b""]``, signaling the end of the stream, or ``[]``.
- You aren't expected to call :meth:`events_received`; it won't return
  any new events.

:meth:`receive_eof` is idempotent.

N)rW   eoffeed_eofr\   r[   rd   s   &r,   receive_eofProtocol.receive_eof  s0     ;;???T[[r+   c               $    V ^8  d   QhRRRRRR/# r7   r|   r   finboolr9   r:   r!   )r;   s   "r,   r<   r=   &  s!     3 3i 3d 3t 3r+   c                   V P                   '       g   \        R4      hV P                  \        Jd1   \	        RV P
                  P                  P                  4        24      hV'       * V n         V P                  \        \        W4      4       R# )a  
Send a `Continuation frame`_.

.. _Continuation frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.6

Parameters:
    data: payload containing the same kind of data
        as the initial frame.
    fin: FIN bit; set it to :obj:`True` if this is the last frame
        of a fragmented message and to :obj:`False` otherwise.

Raises:
    ProtocolError: If a fragmented message isn't in progress.

unexpected continuation frameconnection is N)rN   r
   rc   r/   r   r3   rD   rE   
send_framer   r   r^   r|   r   s   &&&r,   send_continuationProtocol.send_continuation&  si    " --- ?@@;;d"

0E0E0G/HIJJ-0&gt12r+   c               $    V ^8  d   QhRRRRRR/# r   r!   )r;   s   "r,   r<   r=   >  s!     3 3i 3d 3d 3r+   c                   V P                   '       d   \        R4      hV P                  \        Jd1   \	        RV P
                  P                  P                  4        24      hV'       * V n         V P                  \        \        W4      4       R# )aS  
Send a `Text frame`_.

.. _Text frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.6

Parameters:
    data: payload containing text encoded with UTF-8.
    fin: FIN bit; set it to :obj:`False` if this is the first frame of
        a fragmented message.

Raises:
    ProtocolError: If a fragmented message is in progress.

expected a continuation framer   N)rN   r
   rc   r/   r   r3   rD   rE   r   r   r   r   s   &&&r,   	send_textProtocol.send_text>  si      ))) ?@@;;d"

0E0E0G/HIJJ-0&gt12r+   c               $    V ^8  d   QhRRRRRR/# r   r!   )r;   s   "r,   r<   r=   U  s!     5 5	 5 5 5r+   c                   V P                   '       d   \        R4      hV P                  \        Jd1   \	        RV P
                  P                  P                  4        24      hV'       * V n         V P                  \        \        W4      4       R# )aU  
Send a `Binary frame`_.

.. _Binary frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.6

Parameters:
    data: payload containing arbitrary binary data.
    fin: FIN bit; set it to :obj:`False` if this is the first frame of
        a fragmented message.

Raises:
    ProtocolError: If a fragmented message is in progress.

r   r   N)rN   r
   rc   r/   r   r3   rD   rE   r   r   r   r   s   &&&r,   send_binaryProtocol.send_binaryU  si      ))) ?@@;;d"

0E0E0G/HIJJ-0&i34r+   c               $    V ^8  d   QhRRRRRR/# )r7   rk   zCloseCode | int | Nonerq   strr9   r:   r!   )r;   s   "r,   r<   r=   l  s#     " "5 "c "SW "r+   c                   V P                   \        Jd1   \        RV P                  P                  P                  4        24      hVf0   VR8w  d   \        R4      h\        \        P                  R4      pRpM\        W4      pVP                  4       pV P                  \        \        V4      4       V P                  e   Q hW0n        \         V n        R# )a  
Send a `Close frame`_.

.. _Close frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.1

Parameters:
    code: close code.
    reason: close reason.

Raises:
    ProtocolError: If the code isn't valid or if a reason is provided
        without a code.

r   Nrp   z#cannot send a reason without a coder+   )rc   r/   r   r3   rD   rE   r
   r   r   NO_STATUS_RCVD	serializer   r   r   rR   rS   r0   r^   rk   rq   closer|   s   &&&  r,   
send_closeProtocol.send_closel  s    $ ;;d"

0E0E0G/HIJJ<|#$IJJ)22B7ED$'E??$Dh-. &&&
r+   c                    V ^8  d   QhRRRR/# r7   r|   r   r9   r:   r!   )r;   s   "r,   r<   r=          . .i .D .r+   c                    V P                   \        JdE   V P                   \        Jd1   \        RV P                  P
                  P                  4        24      hV P                  \        \        V4      4       R# )z
Send a `Ping frame`_.

.. _Ping frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.2

Parameters:
    data: payload containing arbitrary binary data.

r   N)
rc   r/   r0   r   r3   rD   rE   r   r   r   r   s   &&r,   	send_pingProtocol.send_ping  R     ;;d"t{{''A

0E0E0G/HIJJgt,-r+   c                    V ^8  d   QhRRRR/# r   r!   )r;   s   "r,   r<   r=     r   r+   c                    V P                   \        JdE   V P                   \        Jd1   \        RV P                  P
                  P                  4        24      hV P                  \        \        V4      4       R# )z
Send a `Pong frame`_.

.. _Pong frame:
    https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.3

Parameters:
    data: payload containing arbitrary binary data.

r   N)
rc   r/   r0   r   r3   rD   rE   r   r   r   r   s   &&r,   	send_pongProtocol.send_pong  r   r+   c               $    V ^8  d   QhRRRRRR/# )r7   rk   zCloseCode | intrq   r   r9   r:   r!   )r;   s   "r,   r<   r=     s!     - - -# -t -r+   c                   V P                   \        J dv   V\        P                  8w  da   \	        W4      pVP                  4       pV P                  \        \        V4      4       W0n	        V P                  e   RV n        \        V n         V P                  \        J d#   V P                  '       g   V P!                  4        V P#                  4       V n        \'        V P$                  4       R# )z
`Fail the WebSocket connection`_.

.. _Fail the WebSocket connection:
    https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.7

Parameters:
    code: close code
    reason: close reason

Raises:
    ProtocolError: If the code isn't valid.
NT)r3   r/   r   rj   r   r   r   r   r   rS   rR   rT   r0   r8   r(   rV   send_eofdiscardr[   r\   r   s   &&&  r,   failProtocol.fail  s    & ::y111d+(h 56"'
 ??.04D-$
 99t}}}MMO llnT[[r+   c                   V ^8  d   QhRR/# )r7   r9   zlist[Event]r!   )r;   s   "r,   r<   r=     s       r+   c                ,    V P                   . uqn         V# )z
Fetch events generated from data received from the network.

Call this method immediately after any of the ``receive_*()`` methods.

Process resulting events, likely by passing them to the application.

Returns:
    Events read from the connection.
)rX   )r^   rX   s   & r,   events_receivedProtocol.events_received  s     #kk2r+   c                   V ^8  d   QhRR/# )r7   r9   zlist[bytes]r!   )r;   s   "r,   r<   r=     s      k r+   c                ,    V P                   . uqn         V# )ay  
Obtain data to send to the network.

Call this method immediately after any of the ``receive_*()``,
``send_*()``, or :meth:`fail` methods.

Write resulting data to the connection.

The empty bytestring :data:`~websockets.protocol.SEND_EOF` signals
the end of the data stream. When you receive it, half-close the TCP
connection.

Returns:
    Data to write to the connection.

)rY   )r^   rY   s   & r,   data_to_sendProtocol.data_to_send  s    " #kk2r+   c                   V ^8  d   QhRR/# )r7   r9   r   r!   )r;   s   "r,   r<   r=     s     ) ) )r+   c                    V P                   \        J d   R# V P                   \        J d   R# V P                   \        J d   R# V P                   \        J g   Q hV P
                  # )ai  
Tell if the TCP connection is expected to close soon.

Call this method immediately after any of the ``receive_*()``,
``send_close()``, or :meth:`fail` methods.

If it returns :obj:`True`, schedule closing the TCP connection after a
short timeout if the other side hasn't already closed it.

Returns:
    Whether the TCP connection is expected to close soon.

FT)r3   r/   r0   r1   r.   rV   rd   s   &r,   close_expectedProtocol.close_expected  sN    D :::: ::zzZ'''}}r+   c                   V ^8  d   QhRR/# r7   r9   zGenerator[None]r!   )r;   s   "r,   r<   r=   2  s     MC MC MCr+   c              #  0  "     V P                   P                  4        Rj  xL
 '       d9   V P                  '       d   V P                  P                  R4       \	        R4      hRpV P
                  e9   V P                  f   V P
                  pMV P
                  V P                  ,
          pV P                  e'   Vf   V P                  pM\        WP                  4      p\        P                  ! V P                   P                  V P                  \        J VV P                  R7       Rj  xL
 pV P                  '       d   V P                  P                  RV4       V P                  V4       EKo   ELQ LI  \          d;   pT P#                  \$        P&                  \)        T4      4       Y0n         Rp?EMORp?i\         d;   pT P#                  \$        P,                  \)        T4      4       Y0n         Rp?EMRp?i\.         dJ   pT P#                  \$        P0                  TP2                   RTP4                   24       Y0n         Rp?MRp?i\6         dU   pTP9                  T P                  4       T P#                  \$        P:                  \)        T4      4       Y0n         Rp?M]Rp?i\<         dM   pT P                  P?                  RRR	7       T P#                  \$        P@                  4       Y0n         Rp?MRp?ii ; iRx  \C        R
4      h5i)z
Parse incoming data into frames.

:meth:`receive_data` and :meth:`receive_eof` run this generator
coroutine until it needs more data or reaches EOF.

:meth:`parse` never raises an exception. Instead, it sets the
:attr:`parser_exc` and yields control.

TN< EOFzunexpected end of stream)maskr4   rP   z< %sz at position zparser failed)exc_infoz"parse() shouldn't step after error)"rW   at_eofrH   r5   EOFErrorrK   rM   rL   minr   rZ   
read_exactr8   r(   rP   
recv_framer
   r   r   PROTOCOL_ERRORr   r]   rj   UnicodeDecodeErrorINVALID_DATArq   startr	   set_current_sizeMESSAGE_TOO_BIG	ExceptionerrorINTERNAL_ERRORAssertionError)r^   r4   framerx   s   &   r,   rZ   Protocol.parse2  s;    =	"#{{11333zzz))'2
 ##=>>((4((0#'#8#8#'#8#84;L;L#L))5'#'#9#9#&x1G1G#H
 $);;KK**f,%#	$  :::KK%%fe4&I 44  	"IIi..C9!OO 	"IIi00#c(;!OO! 	"IIi,,M#)).UV!OO 	"  !2!23IIi//S:!OO 	"KKo=IIi../!OO		" 	ABBs   LE8 E3	E8 E8 C-E8 ,E6-E8 1E8 6E8 8L/F82L8LL/G;5L;LL	?ILLLA
J*%L*L7L8AK?:L?LLc                   V ^8  d   QhRR/# r   r!   )r;   s   "r,   r<   r=     s     C C Cr+   c              #    "   V P                   \        J ;'       g    V P                  \        J V P                  8X  g   Q hV P
                  P                  4        Rj  xL
 '       g   V P
                  P                  4        KD  V P                  '       d   V P                  P                  R4       V P                   \        J d%   V P                  \        Jd   V P                  4        \        V n        Rx  \        R4      h L5i)z
Discard incoming data.

This coroutine replaces :meth:`parse`:

- after receiving a close frame, during a normal closure (1.4);
- after sending a close frame, during an abnormal closure (7.1.7).

Nr   z"discard() shouldn't step after EOF)r8   r(   r3   r.   rV   rW   r   r   rH   r5   r)   r   r1   r   rd   s   &r,   r   Protocol.discard  s      		V#??tzzZ'?T]]SSS"kk00222KK!:::KKg& 994::Z#?MMO
 ABB 3s   ADD	D(-DA.Dc                    V ^8  d   QhRRRR/# r7   r   r   r9   r:   r!   )r;   s   "r,   r<   r=     s     N" N" N"$ N"r+   c                @   VP                   \        J g   VP                   \        J dH   V P                  e   \	        R4      hVP
                  '       g   \        VP                  4      V n        EMVP                   \        J dc   V P                  f   \	        R4      hVP
                  '       d
   RV n        EMV ;P                  \        VP                  4      ,          un        EMVP                   \        J d.   \        \        VP                  4      pV P                  V4       EM\VP                   \        J d   EMFVP                   \        J Ed   \        P                  ! VP                  4      V n        V P"                  \$        J d   V P&                  f   Q hRV n        V P                  e   \	        R4      hV P"                  \*        J dM   V P                  \        \        VP                  4      4       V P                   V n        RV n        \$        V n        V P,                  \.        J d   V P1                  4        V P3                  4       V n        \7        V P4                  4       M\9        RVP                   R 24      hV P:                  P=                  V4       R# )	z
Process an incoming frame.

Nr   r   Fzincomplete fragmented messageTzunexpected opcode: 02x)opcoder   r   rM   r
   r   lenr|   r   r   r   r   r   r   r   rZ   rR   r3   r0   rS   rT   r/   r8   r(   r   r   r[   r\   r   rX   append)r^   r   
pong_frames   && r,   r   Protocol.recv_frame  s   
 <<7"elli&?  ,#$CDD999$'

O!\\W$  (#$CDDyyy$(!!!S_4!\\W$ w

3JOOJ'\\W$ \\X% $kk%**5DOzzW$222,1)  ,#$CDD zzT!
 h

 ;<"&//,0)$
 yyF" ,,.DK !#6u||C6H!IJJ5!r+   c                    V ^8  d   QhRRRR/# r   r!   )r;   s   "r,   r<   r=     s     
 
 
$ 
r+   c                	    V P                   '       d   V P                  P                  R V4       V P                  P                  VP	                  V P
                  \        J V P                  R7      4       R# )z> %s)r   rP   N)rH   r5   rY   r   r   r8   r)   rP   )r^   r   s   &&r,   r   Protocol.send_frame  sU    :::KKfe,OOYY&(??  	
r+   c                   V ^8  d   QhRR/# r   r!   )r;   s   "r,   r<   r=     s     % %$ %r+   c                	    V P                   '       d   Q hR V n         V P                  '       d   V P                  P                  R4       V P                  P	                  \
        4       R# )Tz> EOFN)rV   rH   r5   rY   r   SEND_EOFrd   s   &r,   r   Protocol.send_eof  sE    ===  :::KKg&8$r+   )rc   rR   rT   rS   rM   rH   rV   rX   rN   rP   rU   rA   r5   rL   rK   rO   r[   r]   rW   r8   r3   rQ   rY   i   )T)Nrp   )rp   )r"   r#   r$   r%   r&   r/   r_   propertyr3   setterrl   rr   ry   r   r   r   r   r   r   r   r   r   r   r   r   rZ   r   r   r   r   r*   r!   r+   r,   r   r   G   s    "E1 	E1
 @EE1 %)E1N   \\ 
 ( ($ * *$ ! !J *303.5."H. . -b ()ZMC^C<N"d
% %r+   )r   r   r   r   )2
__future__r   enumrB   r?   collections.abcr   
exceptionsr   r   r   r   r	   r
   rP   r   framesr   r   r   r   r   r   r   r   r   r   http11r   r   streamsr   typingr   r   r   r   __all__EventIntEnumr   r(   r)   r   r.   r/   r0   r1   r   r   r!   r+   r,   <module>r      s    "    %  "   & ! > > 	(U" ?4<<  
	1DLL 1 
zz
--	  Ey
% y
%r+   