
    vKg`                       S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKJrJrJrJrJr  S SKJr  S SKJrJr  SSKJrJrJrJr  SSKJrJrJrJrJ r   SS	K!J"r"J#r#  SS
K$J%r%J&r&J'r'J(r(J)r)  SSKJ*r*J+r+J,r,  SSK-J.r.J/r/J0r0J1r1J2r2  SSK3J4r4  S/r5 " S S\RP                  5      r6 S       SS jjr7S\7l8        g)    )annotationsN)AsyncIterableAsyncIterator	AwaitableIterableMapping)TracebackType)Anycast   )ConcurrencyErrorConnectionClosedConnectionClosedOKProtocolError)DATA_OPCODES	BytesLike	CloseCodeFrameOpcode)RequestResponse)CLOSEDOPENEventProtocolState)Data
LoggerLikeSubprotocol   )TimeoutErroraiteranextasyncio_timeoutasyncio_timeout_at)	Assembler
Connectionc                  (   \ rS rSrSrSSSSSS.             S,S jjr\S-S	 j5       r\S-S
 j5       r\S.S j5       r	\S/S j5       r
\S0S j5       r\S1S j5       rS2S jr        S3S jrS4S jrS5S6S jjrS5S7S jjr S5     S8S jjrS9S:S jjrS;S jrS5S<S jjrS=S>S jjrS?S jrS@S jrS;S jrS;S jrS;S jr\R:                  \S.   SAS  jj5       rS;S! jr SBS" jr!S;S# jr"SCS$ jr#SDS% jr$S;S& jr%S;S' jr&S;S( jr'S@S) jr(S;S* jr)S+r*g)Er'   '   a'  
:mod:`asyncio` implementation of a WebSocket connection.

:class:`Connection` provides APIs shared between WebSocket servers and
clients.

You shouldn't use it directly. Instead, use
:class:`~websockets.asyncio.client.ClientConnection` or
:class:`~websockets.asyncio.server.ServerConnection`.

   
      i   )ping_intervalping_timeoutclose_timeout	max_queuewrite_limitc                  Xl         X l        X0l        X@l        [	        U[
        5      (       d  Uc  US 4nXPl        [	        U[
        5      (       a  US 4nX`l        [        R                  " U R                   R                  SU 05      U R                   l
        U R                   R                  U l         U R                   R                  U l
         U R                   R                  U l        S U l         S U l         [        R                   " 5       U l        U   S U l        S U l        0 U l        SU l         S U l        S U l        U R"                  R1                  5       U l        SU l        [6        R8                  " 5       U l        g )N	websocketr   F)protocolr-   r.   r/   
isinstanceintr0   r1   loggingLoggerAdapterloggeriddebugrequestresponseasyncioget_running_looploopclose_deadlinefragmented_send_waiterpong_waiterslatencykeepalive_taskrecv_exccreate_futureconnection_lost_waiterpausedcollectionsdequedrain_waiters)selfr4   r-   r.   r/   r0   r1   s          ]/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/websockets/asyncio/connection.py__init__Connection.__init__4   se    !*(*i%%):"D)I"k3''&-K&  '44MM  $ 
 "]]--B"&--"6"6)]]((
 (,()-) ,,.	 	 -1 DH# OQ
	 :> /3 =AII<S<S<U# " 	    c                8    U R                   R                  S5      $ )z
Local address of the connection.

For IPv4 connections, this is a ``(host, port)`` tuple.

The format of the address depends on the address family.
See :meth:`~socket.socket.getsockname`.

sockname	transportget_extra_inforM   s    rN   local_addressConnection.local_address        ~~,,Z88rQ   c                8    U R                   R                  S5      $ )z
Remote address of the connection.

For IPv4 connections, this is a ``(host, port)`` tuple.

The format of the address depends on the address family.
See :meth:`~socket.socket.getpeername`.

peernamerT   rW   s    rN   remote_addressConnection.remote_address   rZ   rQ   c                .    U R                   R                  $ )a  
State of the WebSocket connection, defined in :rfc:`6455`.

This attribute is provided for completeness. Typical applications
shouldn't check its value. Instead, they should call :meth:`~recv` or
:meth:`send` and handle :exc:`~websockets.exceptions.ConnectionClosed`
exceptions.

)r4   staterW   s    rN   r`   Connection.state   s     }}"""rQ   c                .    U R                   R                  $ )zf
Subprotocol negotiated during the opening handshake.

:obj:`None` if no subprotocol was negotiated.

)r4   subprotocolrW   s    rN   rc   Connection.subprotocol   s     }}(((rQ   c                .    U R                   R                  $ a  
State of the WebSocket connection, defined in :rfc:`6455`.

This attribute is provided for completeness. Typical applications
shouldn't check its value. Instead, they should inspect attributes
of :exc:`~websockets.exceptions.ConnectionClosed` exceptions.

)r4   
close_coderW   s    rN   rg   Connection.close_code   s     }}'''rQ   c                .    U R                   R                  $ rf   )r4   close_reasonrW   s    rN   rj   Connection.close_reason   s     }})))rQ   c                   #    U $ 7fN rW   s    rN   
__aenter__Connection.__aenter__   s
     s   c                   #    Uc  U R                  5       I S h  vN   g U R                  [        R                  5      I S h  vN   g  N- N7frm   )closer   INTERNAL_ERROR)rM   exc_type	exc_value	tracebacks       rN   	__aexit__Connection.__aexit__   s<      **,**Y55666 6s!   AA'AA	A	Ac               l   #      U R                  5       I Sh  vN 7v   M   N	! [         a     gf = f7f)a"  
Iterate on incoming messages.

The iterator calls :meth:`recv` and yields messages asynchronously in an
infinite loop.

It exits when the connection is closed normally. It raises a
:exc:`~websockets.exceptions.ConnectionClosedError` exception after a
protocol error or a network failure.

N)recvr   rW   s    rN   	__aiter__Connection.__aiter__   s5     	 IIK'' '! 		s    4$ "
$ 
1414Nc                p  #     U R                   R                  U5      I Sh  vN $  N! [         a     O[         a    [        S5      Se[         a  nU R                  5        ISh  vN    U R                  R                  [        R                  UR                   SUR                   35        SSS5      ISh  vN     SnAO&! , ISh  vN  (       d  f        SnAO= fSnAff = f[        R                  " U R                  5      I Sh  vN    U R                  R                  U R                   e7f)aa  
Receive the next message.

When the connection is closed, :meth:`recv` raises
:exc:`~websockets.exceptions.ConnectionClosed`. Specifically, it raises
:exc:`~websockets.exceptions.ConnectionClosedOK` after a normal closure
and :exc:`~websockets.exceptions.ConnectionClosedError` after a protocol
error or a network failure. This is how you detect the end of the
message stream.

Canceling :meth:`recv` is safe. There's no risk of losing data. The next
invocation of :meth:`recv` will return the next message.

This makes it possible to enforce a timeout by wrapping :meth:`recv` in
:func:`~asyncio.timeout` or :func:`~asyncio.wait_for`.

When the message is fragmented, :meth:`recv` waits until all fragments
are received, reassembles them, and returns the whole message.

Args:
    decode: Set this flag to override the default behavior of returning
        :class:`str` or :class:`bytes`. See below for details.

Returns:
    A string (:class:`str`) for a Text_ frame or a bytestring
    (:class:`bytes`) for a Binary_ frame.

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

    You may override this behavior with the ``decode`` argument:

    * Set ``decode=False`` to disable UTF-8 decoding of Text_ frames and
      return a bytestring (:class:`bytes`). This improves performance
      when decoding isn't needed, for example if the message contains
      JSON and you're using a JSON library that expects a bytestring.
    * Set ``decode=True`` to force UTF-8 decoding of Binary_ frames
      and return a string (:class:`str`). This may be useful for
      servers that send binary frames instead of text frames.

Raises:
    ConnectionClosed: When the connection is closed.
    ConcurrencyError: If two coroutines call :meth:`recv` or
        :meth:`recv_streaming` concurrently.

NzRcannot call recv while another coroutine is already running recv or recv_streaming at position )recv_messagesgetEOFErrorr   UnicodeDecodeErrorsend_contextr4   failr   INVALID_DATAreasonstartr>   shieldrH   	close_excrF   )rM   decodeexcs      rN   rz   Connection.recv   s     ^	++//7777 	 	"<  " 	((**""**zzl-		{; +******	 nnT88999mm%%4==8s   D6) ') D6) 
C)D6C)C$'A*(C$,AC0C$;B><C$D6C!	CC!	C$D6!C$$C))&D6D&D6c                 #     U R                   R                  U5        Sh  vN nU7v   M   N
 g! [         a     O[         a    [        S5      Se[         a  nU R                  5        ISh  vN    U R                  R                  [        R                  UR                   SUR                   35        SSS5      ISh  vN     SnAO&! , ISh  vN  (       d  f        SnAO= fSnAff = f[        R                  " U R                  5      I Sh  vN    U R                  R                  U R                   e7f)a  
Receive the next message frame by frame.

This method is designed for receiving fragmented messages. It returns an
asynchronous iterator that yields each fragment as it is received. This
iterator must be fully consumed. Else, future calls to :meth:`recv` or
:meth:`recv_streaming` will raise
:exc:`~websockets.exceptions.ConcurrencyError`, making the connection
unusable.

:meth:`recv_streaming` raises the same exceptions as :meth:`recv`.

Canceling :meth:`recv_streaming` before receiving the first frame is
safe. Canceling it after receiving one or more frames leaves the
iterator in a partially consumed state, making the connection unusable.
Instead, you should close the connection with :meth:`close`.

Args:
    decode: Set this flag to override the default behavior of returning
        :class:`str` or :class:`bytes`. See below for details.

Returns:
    An iterator of strings (:class:`str`) for a Text_ frame or
    bytestrings (:class:`bytes`) for a Binary_ frame.

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

    You may override this behavior with the ``decode`` argument:

    * Set ``decode=False`` to disable UTF-8 decoding of Text_ frames
      and return bytestrings (:class:`bytes`). This may be useful to
      optimize performance when decoding isn't needed.
    * Set ``decode=True`` to force UTF-8 decoding of Binary_ frames
      and return strings (:class:`str`). This is useful for servers
      that send binary frames instead of text frames.

Raises:
    ConnectionClosed: When the connection is closed.
    ConcurrencyError: If two coroutines call :meth:`recv` or
        :meth:`recv_streaming` concurrently.

Nz\cannot call recv_streaming while another coroutine is already running recv or recv_streamingr~   )r   get_iterr   r   r   r   r4   r   r   r   r   r   r>   r   rH   r   rF   )rM   r   framer   s       rN   recv_streamingConnection.recv_streaming;  s     X	#11::6B eB 	 	"<  " 	((**""**zzl-		{; +******	 nnT88999mm%%4==8s   E 3 1/13 13 E 
C3E C3C.1A42C.6AC:C.CC.E C+	CC+	#C.&E +C..C33&E D&E c                L  #    U R                   b7  [        R                  " U R                   5      I Sh  vN   U R                   b  M7  [        U[        5      (       a  U R                  5        ISh  vN   USL a*  U R                  R                  UR                  5       5        O)U R                  R                  UR                  5       5        SSS5      ISh  vN   g[        U[        5      (       af  U R                  5        ISh  vN   USL a  U R                  R                  U5        OU R                  R                  U5        SSS5      ISh  vN   g[        U[        5      (       a  [        S5      e[        U[        5      (       Ga  [        U5      n [        U5      nU R                   b   eU R"                  R%                  5       U l          [        U[        5      (       a  U R                  5        ISh  vN   USL a)  U R                  R                  UR                  5       SS9  O(U R                  R                  UR                  5       SS9  SSS5      ISh  vN   SnO[        U[        5      (       af  U R                  5        ISh  vN   USL a  U R                  R                  USS9  OU R                  R                  USS9  SSS5      ISh  vN   SnO[        S5      eU H  n[        U[        5      (       aZ  U(       aS  U R                  5        ISh  vN   U R                  R'                  UR                  5       SS9  SSS5      ISh  vN   Mr  [        U[        5      (       aL  U(       dE  U R                  5        ISh  vN   U R                  R'                  USS9  SSS5      ISh  vN   M  [        S5      e   U R                  5        ISh  vN   U R                  R'                  SSS9  SSS5      ISh  vN   U R                   R1                  S5        SU l         g[        U[2        5      (       Ga  [5        U5      n [7        U5      I Sh  vN nU R                   b   eU R"                  R%                  5       U l          [        U[        5      (       a  USL aR  U R                  5        ISh  vN   U R                  R                  UR                  5       SS9  SSS5      ISh  vN   OQU R                  5        ISh  vN   U R                  R                  UR                  5       SS9  SSS5      ISh  vN   SnO[        U[        5      (       a  USL aD  U R                  5        ISh  vN   U R                  R                  USS9  SSS5      ISh  vN   OCU R                  5        ISh  vN   U R                  R                  USS9  SSS5      ISh  vN   SnO[        S
5      eU  Sh  vN n[        U[        5      (       aZ  U(       aS  U R                  5        ISh  vN   U R                  R'                  UR                  5       SS9  SSS5      ISh  vN   Mx  [        U[        5      (       aL  U(       dE  U R                  5        ISh  vN   U R                  R'                  USS9  SSS5      ISh  vN   M  [        S5      e[        S5      e GN GN GN,! , ISh  vN  (       d  f       g= f GN GN! , ISh  vN  (       d  f       g= f! [          a     gf = f GNS GN! , ISh  vN  (       d  f       GN= f GN GN! , ISh  vN  (       d  f       GN= f GNl GN7! , ISh  vN  (       d  f       GM  = f GN GN! , ISh  vN  (       d  f       GM  = f GN GN! , ISh  vN  (       d  f       GN= f! [(         aq    U R                  5        ISh  vN    U R                  R+                  [,        R.                  S	5        SSS5      ISh  vN    e ! , ISh  vN  (       d  f       e = ff = f! U R                   R1                  S5        SU l         f = f GN3! [8         a     gf = f GN GN! , ISh  vN  (       d  f       GNs= f GN GN~! , ISh  vN  (       d  f       GN= f GNf GN?! , ISh  vN  (       d  f       GN= f GNC GN! , ISh  vN  (       d  f       GN2= f GN! GN GN! , ISh  vN  (       d  f       GMG  = f GN GN{! , ISh  vN  (       d  f       GMi  = f
 U R                  5        ISh  vN    U R                  R'                  SSS9  SSS5      ISh  vN    O! , ISh  vN  (       d  f       O= f! [(         aq    U R                  5        ISh  vN    U R                  R+                  [,        R.                  S	5        SSS5      ISh  vN    e ! , ISh  vN  (       d  f       e = ff = fU R                   R1                  S5        SU l         g! U R                   R1                  S5        SU l         f = f7f)aK
  
Send a message.

A string (:class:`str`) is sent as a Text_ frame. A bytestring or
bytes-like object (:class:`bytes`, :class:`bytearray`, or
:class:`memoryview`) is sent as a Binary_ frame.

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

You may override this behavior with the ``text`` argument:

* Set ``text=True`` to send a bytestring or bytes-like object
  (:class:`bytes`, :class:`bytearray`, or :class:`memoryview`) as a
  Text_ frame. This improves performance when the message is already
  UTF-8 encoded, for example if the message contains JSON and you're
  using a JSON library that produces a bytestring.
* Set ``text=False`` to send a string (:class:`str`) in a Binary_
  frame. This may be useful for servers that expect binary frames
  instead of text frames.

:meth:`send` also accepts an iterable or an asynchronous iterable of
strings, bytestrings, or bytes-like objects to enable fragmentation_.
Each item is treated as a message fragment and sent in its own frame.
All items must be of the same type, or else :meth:`send` will raise a
:exc:`TypeError` and the connection will be closed.

.. _fragmentation: https://datatracker.ietf.org/doc/html/rfc6455#section-5.4

:meth:`send` rejects dict-like objects because this is often an error.
(If you really want to send the keys of a dict-like object as fragments,
call its :meth:`~dict.keys` method and pass the result to :meth:`send`.)

Canceling :meth:`send` is discouraged. Instead, you should close the
connection with :meth:`close`. Indeed, there are only two situations
where :meth:`send` may yield control to the event loop and then get
canceled; in both cases, :meth:`close` has the same effect and is
more clear:

1. The write buffer is full. If you don't want to wait until enough
   data is sent, your only alternative is to close the connection.
   :meth:`close` will likely time out then abort the TCP connection.
2. ``message`` is an asynchronous iterator that yields control.
   Stopping in the middle of a fragmented message will cause a
   protocol error and the connection will be closed.

When the connection is closed, :meth:`send` raises
:exc:`~websockets.exceptions.ConnectionClosed`. Specifically, it
raises :exc:`~websockets.exceptions.ConnectionClosedOK` after a normal
connection closure and
:exc:`~websockets.exceptions.ConnectionClosedError` after a protocol
error or a network failure.

Args:
    message: Message to send.

Raises:
    ConnectionClosed: When the connection is closed.
    TypeError: If ``message`` doesn't have a supported type.

NFTzdata is a dict-like object)finz"iterable must contain bytes or strz#iterable must contain uniform typesrQ   zerror in fragmented messagez(async iterable must contain bytes or strz)async iterable must contain uniform typesz4data must be str, bytes, iterable, or async iterable)rB   r>   r   r5   strr   r4   send_binaryencode	send_textr   r   	TypeErrorr   iternextStopIterationr@   rG   send_continuation	Exceptionr   r   rs   
set_resultr   r"   r#   StopAsyncIteration)rM   messagetextchunkschunkr   achunkss          rN   sendConnection.send  s    H ))5..!<!<=== ))5 gs##((**5=MM--gnn.>?MM++GNN,<=	 +** ++((**4<MM++G4MM--g6	 +** ))899 **']FV ..666*.))*A*A*CD'.3eS))#00225= MM55elln%5P MM33ELLN3N	  32
 "Fy11#00224< MM33Eu3E MM55e5G	  32
 #F#$HII $E!%--&#'#4#4#6#6 MM;;ELLNPU;V $7#6#6#E955f#'#4#4#6#6 MM;;Eu;M $7#6#6 ((MNN $  ,,..MM33CT3B /. ++66t<.2+ //GnG#Gn, ..666*.))*A*A*CD'03eS))u}#'#4#4#6#6 MM55elln%5P $7#6#6 $(#4#4#6#6 MM33ELLN3N $7#6!Fy11t|#'#4#4#6#6 MM33Eu3E $7#6#6 $(#4#4#6#6 MM55e5G $7#6"F#$NOO $+ U%!%--&#'#4#4#6#6 MM;;ELLNPU;V $7#6#6#E955f#'#4#4#6#6 MM;;Eu;M $7#6#6 ((STT* RSSc > +*** +***" !   3222  3222 $7#6#6#6 $7#6#6#6 /...    ,,..MM&&!005 /..
  /..
  ++66t<.2+ -%  $7#6#6#6 $7#6#6#6
 $7#6#6#6 $7#6#6#6U#6#6#6#6 $7#6#6#6 $+  ,,..MM33CT3B /.....    ,,..MM&&!005 /..
  /..
  ++66t<.2+ ++66t<.2+s$  1j$[>j$)j$0\1j$4A\j$\.j$\!j$=\'j$\$Aj$] &.j$)_8 >]?_8 A]_8 $]%0_8 ]2_8 ;]8_8 ]5 A_8 '^(_8 +)^_8 ^ 6_8 ^5_8 ^;5_8  ^8'_8 (_)_8 ,__8 __8 Aj$b  *b+b  /.j$.g b0g )b69g b3g cg ")cg c5g c2g c8+g 6c57g dg d/g :d;g e;d4e;1g d7	g )d=5g  d:6g 7e8g ;eg !e"g 3j$j$j$\\\j$$j$'\>-\0.\>:j$
]j$]j$_8 _8 ]/] ]/*	_8 5_8 8^>^?^	_8 _8 ^2	^" ^2	,
_8 8_8 ;_	__	
_8 _8 _5#_&$_50_8 3a6 5_8 8a3`a3+aa3aa3a/	a!a/	+a33a6 6$bj$b   
b-*j$,b--j$0g 3g 6c<b?=c		g g c/c c/*	g 5g 8d>d?d	g g d1d" d1,g 4e;7g :g =e	ee	
g g e8	%e(&e8	2g fg g0g ;f><g i= gg	gg i= g i:g=;i?+h<*i5h86i<i	ii	ii= #j$=$j!!j$c                b  #     U R                  5        ISh  vN   U R                  b+  U R                  R                  [        R
                  S5        OU R                  R                  X5        SSS5      ISh  vN   g Nh N! , ISh  vN  (       d  f       g= f! [         a     gf = f7f)a*  
Perform the closing handshake.

:meth:`close` waits for the other end to complete the handshake and
for the TCP connection to terminate.

:meth:`close` is idempotent: it doesn't do anything once the
connection is closed.

Args:
    code: WebSocket close code.
    reason: WebSocket close reason.

Nzclose during fragmented message)r   rB   r4   r   r   rs   
send_closer   )rM   coder   s      rN   rr   Connection.closeW  s     	 ((**..:MM&&!009
 MM,,T: +*****   	 	sz   B/B BB AB0B ;B<B  B/B B BBBB B/B 
B,)B/+B,,B/c                `   #    [         R                  " U R                  5      I Sh  vN   g N7f)z
Wait until the connection is closed.

:meth:`wait_closed` waits for the closing handshake to complete and for
the TCP connection to terminate.

N)r>   r   rH   rW   s    rN   wait_closedConnection.wait_closedv  s      nnT88999s   $.,.c                  #    [        U[        5      (       a  [        U5      nO4[        U[        5      (       a  UR	                  5       nOUb  [        S5      eU R                  5        ISh  vN   XR                  ;   a  [        S5      eUb  XR                  ;   aA  [        R                  " S[        R                  " S5      5      nUc  M0  XR                  ;   a  MA  U R                  R                  5       nU R                  R                  5       nX#4U R                  U'   U R                   R#                  U5        UsSSS5      ISh  vN   $  N N! , ISh  vN  (       d  f       g= f7f)ax  
Send a Ping_.

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

A ping may serve as a keepalive or as a check that the remote endpoint
received all messages up to this point

Args:
    data: Payload of the ping. A :class:`str` will be encoded to UTF-8.
        If ``data`` is :obj:`None`, the payload is four random bytes.

Returns:
    A future that will be completed when the corresponding pong is
    received. You can ignore it if you don't intend to wait. The result
    of the future is the latency of the connection in seconds.

    ::

        pong_waiter = await ws.ping()
        # only if you want to wait for the corresponding pong
        latency = await pong_waiter

Raises:
    ConnectionClosed: When the connection is closed.
    ConcurrencyError: If another ping was sent with the same data and
        the corresponding pong wasn't received yet.

Ndata must be str or bytes-likez-already waiting for a pong with the same dataz!I    )r5   r   bytesr   r   r   r   rC   r   structpackrandomgetrandbitsr@   rG   timer4   	send_ping)rM   datapong_waiterping_timestamps       rN   pingConnection.ping  s    < dI&&;Dc"";;=D<==$$&&(((&'VWW ,$*;*;";{{4););B)?@ ,$*;*;"; ))113K "YY^^-N'2&CDd#MM##D) '&&&&&sV   A*E.,E-E.0AEEA E>E.
EE.E.E+EE+'E.c                t  #    [        U[        5      (       a  [        U5      nO1[        U[        5      (       a  UR	                  5       nO[        S5      eU R                  5        ISh  vN   U R                  R                  U5        SSS5      ISh  vN   g N0 N! , ISh  vN  (       d  f       g= f7f)a"  
Send a Pong_.

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

An unsolicited pong may serve as a unidirectional heartbeat.

Args:
    data: Payload of the pong. A :class:`str` will be encoded to UTF-8.

Raises:
    ConnectionClosed: When the connection is closed.

r   N)	r5   r   r   r   r   r   r   r4   	send_pongrM   r   s     rN   pongConnection.pong  sv      dI&&;Dc"";;=D<==$$&&MM##D) '&&&&&sH   A'B8)B*B8-B	B8BB8B8B5$B'%B51B8c                   [        U[        5      (       d   eUR                  [        ;   a  U R                  R                  U5        UR                  [        R                  L a%  U R                  [        UR                  5      5        gg)z`
Process one incoming event.

This method is overridden in subclasses to handle the handshake.

N)r5   r   opcoder   r   putr   PONGacknowledge_pingsr   r   )rM   events     rN   process_eventConnection.process_event  sc     %''''<<<'""5)<<6;;&""5#45 'rQ   c                T   XR                   ;  a  gU R                  R                  5       nSn/ nU R                   R                  5        H;  u  nu  pVUR	                  U5        X&-
  nUR                  U5        X1:X  d  M5  Xpl          O   [        S5      eU H  nU R                   U	 M     g)z+
Acknowledge pings when receiving a pong.

Nz!solicited pong not found in pings)rC   r@   r   itemsappendr   rD   AssertionError)rM   r   pong_timestampping_idping_idsr   r   rD   s           rN   r   Connection.acknowledge_pings  s     ((() 6:6G6G6M6M6O2G2kOOG$$5G""7+& 7P !!DEE  G!!'*  rQ   c                T   U R                   R                  [        L d   eU R                   R                  nU R                  R                  5        H;  u  p#UR                  5       (       d  UR                  U5        UR                  5         M=     U R                  R                  5         g)zh
Raise ConnectionClosed in pending pings.

They'll never receive a pong once the connection is closed.

N)
r4   r`   r   r   rC   valuesdoneset_exceptioncancelclear)rM   r   r   _ping_timestamps       rN   abort_pingsConnection.abort_pings  s     }}""f,,,mm%%,0,=,=,D,D,F(K##%%))#.
   -G 	!rQ   c                  #    U R                   c   eSn  [        R                  " U R                   U-
  5      I Sh  vN   U R                  R	                  S5        U R                  5       I Sh  vN nU R                  bT   [        U R                  5       ISh  vN   UI Sh  vN nSSS5      ISh  vN   U R                  R	                  S5        M   N Ni N? N7 N)! , ISh  vN  (       d  f       N>= f! [        R                   a    U R                  (       a  U R                  R	                  S5        U R                  5        ISh  vN    U R                  R                  [        R                  S5        SSS5      ISh  vN    O! , ISh  vN  (       d  f       O= f[        S5      ef = f! [         a    U R                  R!                  S	SS
9   gf = f7f)zD
Send a Ping frame and wait for a Pong frame at regular intervals.

Ng        Tz% sending keepalive pingz% received keepalive pongz&- timed out waiting for keepalive pongzkeepalive ping timeoutzKsend_context() should wait for connection_lost(), which cancels keepalive()zkeepalive ping failedexc_info)r-   r>   sleepr9   r;   r   r.   r$   r!   r   r4   r   r   rs   r   r   error)rM   rD   r   s      rN   	keepaliveConnection.keepalive  s    
 !!--- 	F mmD$6$6$@AAA!!"<=$(IIK/$$0#243D3D#E#E
 -8&7G $F#E ))*EF#  B 0 $F
 '8 $F#E#E#E #// :: KK--.VW#'#4#4#6#6 MM.. ) 8 8 8 $7#6#6#6#6#6
 -8   	FKK5E	Fs   G$'F: C2F: /C0F: C; CC; C!%C&C!*C; 5C6C; F: F: C; C!C; !C8'C*(C84C; ;AF7EF7+F?F7
FF7F(	FF(	$F77F: :$G!G$ G!!G$c                |    U R                   b/  U R                  R                  U R                  5       5      U l        gg)zA
Run :meth:`keepalive` in a task, unless keepalive is disabled.

N)r-   r@   create_taskr   rE   rW   s    rN   start_keepaliveConnection.start_keepalive:  s3    
 )"&))"7"78H"ID *rQ   )expected_statec              R  #    SnSnSnU R                   R                  UL a   S7v   U R                   R                  5       (       aJ  SnU R                  b;  U R                  b   eU R
                  R                  5       U R                  -   U l         U R                  5         U R                  5       I Sh  vN   OJSnU R                  b9  U R                  c,  U R
                  R                  5       U R                  -   U l        SnU(       aW   [        U R                  5       ISh  vN   [         R"                  " U R$                  5      I Sh  vN   SSS5      ISh  vN   U(       aO  U R+                  5         [         R"                  " U R$                  5      I Sh  vN   U R                   R,                  Ueg GN! [         a;  nU R                  (       a  U R                  R                  SSS9  SnSnUn SnANSnAff = f! [        [        4 a    e [         a+  nU R                  R                  SSS9  SnSnUn SnAGN@SnAff = f GN' GN N! , ISh  vN  (       d  f       GN
= f! [&         a'    Ub   e['        S5      nSnU R)                  U5         GN=f = f GN7f)a   
Create a context for writing to the connection from user code.

On entry, :meth:`send_context` checks that the connection is open; on
exit, it writes outgoing data to the socket::

    async with self.send_context():
        self.protocol.send_text(message.encode())

When the connection isn't open on entry, when the connection is expected
to close on exit, or when an unexpected error happens, terminating the
connection, :meth:`send_context` waits until the connection is closed
then raises :exc:`~websockets.exceptions.ConnectionClosed`.

FNT! error while sending datar   zunexpected internal errorz"timed out while closing connection)r4   r`   close_expectedr/   rA   r@   r   	send_datadrainr   r;   r9   r   r   r   r%   r>   r   rH   r!   set_recv_excclose_transportr   )rM   r   wait_for_closeraise_close_excoriginal_excr   s         rN   r   Connection.send_contextB  sQ    , -1==.0#' ==//11%)N
 ))5#22:::.2iinn.>ASAS.S+
'NN$**,&& "N!!-&&.*.))..*:T=O=O*OD'"O 0-d.A.ABB!..)D)DEEE CB   "..!<!<===--))|;	 M '  'zz))*FQU)V &+N&*O#&L'5 "#34  #!!"=!M "'"&"#\ CE CBBB 0 $++++,PQ #'!!,/0 >s   J'H A)J'#F= 5F:6F= :AJ'I0 &I'I0 *$IIII0 II0 #:J'J$J':F= =
H1G=8J'=HJ'I
 I?J'I

J'I0 II0 I-II-(I0 +J'-I0 0-J!J' J!!J'c                   U R                   R                  5        H  nU(       a  U R                  R                  U5        M'  U R                  R	                  5       (       aI  U R
                  (       a  U R                  R                  S5         U R                  R                  5         M  U R
                  (       a  U R                  R                  S5        U R                  R                  5         M     g! [        [        4 a     M  f = f)zL
Send outgoing data.

Raises:
    OSError: When a socket operations fails.

zx half-closing TCP connectionzx closing TCP connectionN)r4   data_to_sendrU   writecan_write_eofr;   r9   	write_eofOSErrorRuntimeErrorrr   r   s     rN   r   Connection.send_data  s     MM..0D$$T* >>//11zz))*IJ002
 zz))*DENN((*% 1 $\2 s   C55D	D	c                ,    U R                   c  Xl         gg)z 
Set recv_exc, if not set yet.

N)rF   )rM   r   s     rN   r   Connection.set_recv_exc  s    
 == M !rQ   c                l    U R                   R                  5         U R                  R                  5         g)z)
Close transport and message assembler.

N)rU   rr   r   rW   s    rN   r   Connection.close_transport  s&    
 	  "rQ   c                    [        [        R                  U5      n[        U R                  UR
                  UR                  S.6U l        UR                  " U R                  6   Xl
        g )N)pauseresume)r   r>   	Transportr&   r0   pause_readingresume_readingr   set_write_buffer_limitsr1   rU   )rM   rU   s     rN   connection_madeConnection.connection_made  sU    **I6	&^^))++

 	))4+;+;<"rQ   c                D   U R                   R                  5         U R                   R                  [        L d   eU R	                  U5        U R
                  R                  5         U R                  5         U R                  b  U R                  R                  5         U R                  R                  S 5        U R                  (       aY  SU l        U R                   HA  nUR                  5       (       a  M  Uc  UR                  S 5        M0  UR                  U5        MC     g g NF)r4   receive_eofr`   r   r   r   rr   r   rE   r   rH   r   rI   rL   r   r   )rM   r   waiters      rN   connection_lostConnection.connection_lost  s     	!!#}}""f,,,# 	  "*&&(
 	##..t4 ;;DK,,{{}}{))$/,,S1 - rQ   c                8    U R                   (       a   eSU l         g )NT)rI   rW   s    rN   pause_writingConnection.pause_writing  s    ;;rQ   c                    U R                   (       d   eSU l         U R                   H+  nUR                  5       (       a  M  UR                  S 5        M-     g r  )rI   rL   r   r   rM   r
  s     rN   resume_writingConnection.resume_writing  s>    {{{((F;;==!!$' )rQ   c                  #    U R                   R                  5       (       a  [        R                  " S5      I S h  vN   U R                  (       a\  U R
                  R                  5       nU R                  R                  U5         UI S h  vN   U R                  R                  U5        g g  Nr N#! U R                  R                  U5        f = f7f)Nr   )
rU   
is_closingr>   r   rI   r@   rG   rL   r   remover  s     rN   r   Connection.drain  s      >>$$&&--""" ;;YY,,.F%%f-2""))&1  # ""))&1s:   9CB.A
CB2 B0B2 C0B2 2CCc                4   U R                   R                  U5        U R                   R                  5       n U R                  5         U R                   R                  5       (       aF  U R                  b9  U R                  c,  U R                  R                  5       U R                  -   U l
        U H  nU R                  U5        M     g ! [         aF  nU R
                  (       a  U R                  R                  SSS9  U R                  U5         S nANS nAff = f)Nr   Tr   )r4   receive_dataevents_receivedr   r   r;   r9   r   r   r/   rA   r@   r   r   )rM   r   eventsr   r   s        rN   data_receivedConnection.data_received"  s    ""4( ..0	#NN =='')) !!-&&.*.))..*:T=O=O*OD'Eu%   	#zz!!">!Nc""	#s   C 
D<DDc                    U R                   R                  5         U R                   R                  5       nU R                  5         U H  nU R	                  U5        M     g rm   )r4   r	  r  r   r   )rM   r  r   s      rN   eof_receivedConnection.eof_received<  sL    !!# ..0 	 Eu% rQ   )rA   r/   rH   r;   rL   rB   r:   rE   rD   r9   r@   r0   rI   r-   r.   rC   r4   rF   r   r<   r=   rU   r1   )r4   r   r-   float | Noner.   r!  r/   r!  r0   z*int | None | tuple[int | None, int | None]r1   zint | tuple[int, int | None]returnNone)r"  r
   )r"  r   )r"  zSubprotocol | None)r"  z
int | None)r"  z
str | None)r"  r'   )rt   ztype[BaseException] | Noneru   BaseException | Nonerv   zTracebackType | Noner"  r#  )r"  AsyncIterator[Data]rm   )r   bool | Noner"  r   )r   r&  r"  r%  )r   z+Data | Iterable[Data] | AsyncIterable[Data]r   r&  r"  r#  )i   )r   r6   r   r   r"  r#  )r"  r#  )r   zData | Noner"  zAwaitable[float])rQ   )r   r   r"  r#  )r   r   r"  r#  )r   r   r"  r#  )r   r   r"  zAsyncIterator[None])r   r$  r"  r#  )rU   zasyncio.BaseTransportr"  r#  )r   zException | Noner"  r#  )+__name__
__module____qualname____firstlineno____doc__rO   propertyrX   r]   r`   rc   rg   rj   ro   rw   r{   rz   r   r   rr   r   r   r   r   r   r   r   r   
contextlibasynccontextmanagerr   r   r   r   r   r  r  r  r  r   r  r  __static_attributes__rn   rQ   rN   r'   r'   '   s   
  ')%'&(@B49S
S
 $	S

 #S
 $S
 >S
 2S
 
S
n 
9 
9 
9 
9 
# 
# ) ) 	( 	( 	* 	*	7,	7 (	7 (		7
 
	7$C9JB9N !VT<VT VT 
	VTp>:4l*66+:"*'FRJ ## !%b< b< 
	b< $b<H+8 ##2@
(2(&4&rQ   c           
        [        U[        5      (       a  SnUR                  5       nO#[        U[        5      (       a  SnO[	        S5      eU(       a$  [
        R                  SS S:  a  [        S5      e/ nU  H  nUR                  R                  [        La  M"  UR                  bA  U(       a  [        S5      nWR                  U5        OUR                  R                  S	5        Mp   [!        UR                  U5      " U5        UR#                  5         M     U(       a  W(       a  [3        SU5      egg! [$         a  nU(       a(  ['        S
5      nXvl        WR                  U5         SnAM  UR                  R                  S[*        R,                  " [/        U5      U5      S   R1                  5       5         SnAGMH  SnAff = f)ay  
Broadcast a message to several WebSocket connections.

A string (:class:`str`) is sent as a Text_ frame. A bytestring or bytes-like
object (:class:`bytes`, :class:`bytearray`, or :class:`memoryview`) is sent
as a Binary_ frame.

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

:func:`broadcast` pushes the message synchronously to all connections even
if their write buffers are overflowing. There's no backpressure.

If you broadcast messages faster than a connection can handle them, messages
will pile up in its write buffer until the connection times out. Keep
``ping_interval`` and ``ping_timeout`` low to prevent excessive memory usage
from slow connections.

Unlike :meth:`~websockets.asyncio.connection.Connection.send`,
:func:`broadcast` doesn't support sending fragmented messages. Indeed,
fragmentation is useful for sending large messages without buffering them in
memory, while :func:`broadcast` buffers one copy per connection as fast as
possible.

:func:`broadcast` skips connections that aren't open in order to avoid
errors on connections where the closing handshake is in progress.

:func:`broadcast` ignores failures to write the message on some connections.
It continues writing to other connections. On Python 3.11 and above, you may
set ``raise_exceptions`` to :obj:`True` to record failures and raise all
exceptions in a :pep:`654` :exc:`ExceptionGroup`.

While :func:`broadcast` makes more sense for servers, it works identically
with clients, if you have a use case for opening connections to many servers
and broadcasting a message to them.

Args:
    websockets: WebSocket connections to which the message will be sent.
    message: Message to send.
    raise_exceptions: Whether to raise an exception in case of failures.

Raises:
    TypeError: If ``message`` doesn't have a supported type.

r   r   zdata must be str or bytesNr   )      z.raise_exceptions requires at least Python 3.11zsending a fragmented messagez/skipped broadcast: sending a fragmented messagezfailed to write messagez.skipped broadcast: failed to write message: %sr   zskipped broadcast)r5   r   r   r   r   sysversion_info
ValueErrorr4   r`   r   rB   r   r   r9   warninggetattrr   r   r   	__cause__rv   format_exception_onlytypestripExceptionGroup)connectionsr   raise_exceptionssend_method
exceptions
connection	exceptionwrite_exceptions           rN   	broadcastrE  ]  s   d '3!.."	GY	'	'#344BQ')MNN&(
!
 $$D0,,8,-KL	!!),!!))E 	 J''5g>  ") "H J0*== '  	()BC	&5#!!),,!!))D33_-' 	  	s   *,D66
G )G/AGGzwebsockets.asyncio.server)F)r>  zIterable[Connection]r   r   r?  boolr"  r#  )9
__future__r   r>   rJ   r.  r7   r   r   r4  rv   uuidcollections.abcr   r   r   r   r   typesr	   typingr
   r   rA  r   r   r   r   framesr   r   r   r   r   http11r   r   r4   r   r   r   r   r   r   r   r   compatibilityr!   r"   r#   r$   r%   messagesr&   __all__r'   rE  r)  rn   rQ   rN   <module>rQ     s    "       
   V V    G F & ; ; 2 2    .g&!! g&r! #d>%d>d> d> 
	d>P 3	 rQ   