
    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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JrJr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#  SS	K$J%r%  SS
K&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0  SSK1J2r2  SSKJ3r3J4r4J5r5  SSK6J7r7J8r8J9r9  S/r: " S S\Rv                  5      r< S       SS jjr=S\=l>        g)    )annotationsN)AsyncIterableAsyncIterator	AwaitableIterableMapping)AnyCallableDequecast   )asyncio_timeout)Headers)ConnectionClosedConnectionClosedErrorConnectionClosedOKInvalidStatePayloadTooBigProtocolError)	Extension)
OK_CLOSE_CODES	OP_BINARYOP_CLOSEOP_CONTOP_PINGOP_PONGOP_TEXTClose	CloseCodeOpcode)State)Data
LoggerLikeSubprotocol   )Frameprepare_ctrlprepare_dataWebSocketCommonProtocolc                     \ rS rSr% SrS\S'   SrS\S'   SS	S	SS
SSSSSSSSSS.                             S<S jjrS=S jrS=S jr	S=S jr
\S>S j5       r\S?S j5       r\S@S j5       r\SAS j5       r\SAS j5       r\SBS j5       r\SBS j5       r\S?S j5       r\S>S j5       rSCS jrSDS jr    SES jr\R2                  S4     SFS  jjrS=S! jrSGSHS" jjrSISJS# jjrSKS$ jrS=S% jrS=S& jr SLS' jr!SMS( jr"SNS) jr#SOS* jr$S=S+ jr%\&RN                  S,.         SPS- jjr(SGSQS. jjr)S=S/ jr*S=S0 jr+S=S1 jr,SBS2 jr-\R\                  S4     SFS3 jjr/S=S4 jr0SRS5 jr1SSS6 jr2S=S7 jr3S=S8 jr4STS9 jr5S=S: jr6S;r7g)Ur)   6   u)  
WebSocket connection.

:class:`WebSocketCommonProtocol` provides APIs shared between WebSocket
servers and clients. You shouldn't use it directly. Instead, use
:class:`~websockets.legacy.client.WebSocketClientProtocol` or
:class:`~websockets.legacy.server.WebSocketServerProtocol`.

This documentation focuses on low-level details that aren't covered in the
documentation of :class:`~websockets.legacy.client.WebSocketClientProtocol`
and :class:`~websockets.legacy.server.WebSocketServerProtocol` for the sake
of simplicity.

Once the connection is open, a Ping_ frame is sent every ``ping_interval``
seconds. This serves as a keepalive. It helps keeping the connection open,
especially in the presence of proxies with short timeouts on inactive
connections. Set ``ping_interval`` to :obj:`None` to disable this behavior.

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

If the corresponding Pong_ frame isn't received within ``ping_timeout``
seconds, the connection is considered unusable and is closed with code 1011.
This ensures that the remote endpoint remains responsive. Set
``ping_timeout`` to :obj:`None` to disable this behavior.

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

See the discussion of :doc:`keepalive <../../topics/keepalive>` for details.

The ``close_timeout`` parameter defines a maximum wait time for completing
the closing handshake and terminating the TCP connection. For legacy
reasons, :meth:`close` completes in at most ``5 * close_timeout`` seconds
for clients and ``4 * close_timeout`` for servers.

``close_timeout`` is a parameter of the protocol because websockets usually
calls :meth:`close` implicitly upon exit:

* on the client side, when using :func:`~websockets.legacy.client.connect`
  as a context manager;
* on the server side, when the connection handler terminates.

To apply a timeout to any other API, wrap it in :func:`~asyncio.timeout` or
:func:`~asyncio.wait_for`.

The ``max_size`` parameter enforces the maximum size for incoming messages
in bytes. The default value is 1 MiB. If a larger message is received,
:meth:`recv` will raise :exc:`~websockets.exceptions.ConnectionClosedError`
and the connection will be closed with code 1009.

The ``max_queue`` parameter sets the maximum length of the queue that
holds incoming messages. The default value is ``32``. Messages are added
to an in-memory queue when they're received; then :meth:`recv` pops from
that queue. In order to prevent excessive memory consumption when
messages are received faster than they can be processed, the queue must
be bounded. If the queue fills up, the protocol stops processing incoming
data until :meth:`recv` is called. In this situation, various receive
buffers (at least in :mod:`asyncio` and in the OS) will fill up, then the
TCP receive window will shrink, slowing down transmission to avoid packet
loss.

Since Python can use up to 4 bytes of memory to represent a single
character, each connection may use up to ``4 * max_size * max_queue``
bytes of memory to store incoming messages. By default, this is 128 MiB.
You may want to lower the limits, depending on your application's
requirements.

The ``read_limit`` argument sets the high-water limit of the buffer for
incoming bytes. The low-water limit is half the high-water limit. The
default value is 64 KiB, half of asyncio's default (based on the current
implementation of :class:`~asyncio.StreamReader`).

The ``write_limit`` argument sets the high-water limit of the buffer for
outgoing bytes. The low-water limit is a quarter of the high-water limit.
The default value is 64 KiB, equal to asyncio's default (based on the
current implementation of ``FlowControlMixin``).

See the discussion of :doc:`memory usage <../../topics/memory>` for details.

Args:
    logger: Logger for this server.
        It defaults to ``logging.getLogger("websockets.protocol")``.
        See the :doc:`logging guide <../../topics/logging>` for details.
    ping_interval: Interval between keepalive pings in seconds.
        :obj:`None` disables keepalive.
    ping_timeout: Timeout for keepalive pings in seconds.
        :obj:`None` disables timeouts.
    close_timeout: Timeout for closing the connection in seconds.
        For legacy reasons, the actual timeout is 4 or 5 times larger.
    max_size: Maximum size of incoming messages in bytes.
        :obj:`None` disables the limit.
    max_queue: Maximum number of incoming messages in receive buffer.
        :obj:`None` disables the limit.
    read_limit: High-water mark of read buffer in bytes.
    write_limit: High-water mark of write buffer in bytes.

bool	is_client	undefinedstrsideN   i       i   F)loggerping_intervalping_timeoutclose_timeoutmax_size	max_queue
read_limitwrite_limithostportsecurelegacy_recvlooptimeoutc                  U(       a  [         R                  " S[        5        Uc  SnO[         R                  " S[        5        Uc  UnUc  [        R                  " 5       nO[         R                  " S[        5        X l        X0l        X@l        XPl        X`l	        Xpl
        Xl        [        R                  " 5       U l         Uc  [        R                   " S5      n[        R"                  " USU 05      U l         UR'                  [        R(                  5      U l        Xl        Xl        Xl        Xl        Xl        [        R6                  " US-  US9U l        S	U l        S U l        [        R>                  " 5       U l         [B        RD                  U l#        U R*                  (       a  U R$                  R+                  S
5        U    U    U    / U l$        S U l%         S U l&        S U l'        S U l(        URS                  5       U l*        [V        RX                  " 5       U l-        S U l.        S U l/        S U l0        0 U l1        SU l2         U   S U l3        U   U   g )Nzlegacy_recv is deprecated
   zrename timeout to close_timeoutzremove loop argumentzwebsockets.protocol	websocketr   )limitr?   Fz= connection is CONNECTINGr   )4warningswarnDeprecationWarningasyncioget_event_loopr4   r5   r6   r7   r8   r9   r:   uuiduuid4idlogging	getLoggerLoggerAdapterr3   isEnabledForDEBUGdebugr?   _host_port_securer>   StreamReaderreader_paused_drain_waiterLock_drain_lockr!   
CONNECTINGstate
extensionssubprotocol
close_rcvd
close_sentclose_rcvd_then_sentcreate_futureconnection_lost_waitercollectionsdequemessages_pop_message_waiter_put_message_waiter_fragmented_message_waiterpingslatencytransfer_data_exc)selfr3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   s                  Z/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/websockets/legacy/protocol.py__init__ WebSocketCommonProtocol.__init__   s   & MM57IJ ?GMM;=OP #M <))+DMM02DE*(* "$& "ZZ\B >&&'<=F")"7"7d@S"T) ((7
	

& **qtL :>"<<> %%
::KK:; 	401 ,./31 )-(,15! =A<N<N<P# &1%6%6%8@D @D  HL' HJ

	 	 8< 	 	    c                (  #    U R                   R                  5       (       a  [        S5      eU R                  (       d  g U R                  nUb  UR                  5       (       d   eU R                  R                  5       nXl        UI S h  vN   g  N7f)NzConnection lost)rd   doneConnectionResetErrorrX   rY   	cancelledr?   rc   rn   waiters     ro   _drain_helper%WebSocketCommonProtocol._drain_helper0  ss     &&++--&'899||##~!1!1!3!333((*#s   BB
BBc                0  #    U R                   b  U R                   R                  5       nUb  UeU R                  b=  U R                  R                  5       (       a  [        R
                  " S5      I S h  vN   U R                  5       I S h  vN   g  N N7f)Nr   )rW   	exception	transport
is_closingrH   sleepry   rn   excs     ro   _drainWebSocketCommonProtocol._drain<  sv     ;;"++'')C	>>%~~((** mmA&&&  """ '"s$   A2B4B5BBBBc                   U R                   [        R                  L d   e[        R                  U l         U R                  (       a  U R
                  R	                  S5        U R                  R                  U R                  5       5      U l	        U R                  R                  U R                  5       5      U l        U R                  R                  U R                  5       5      U l        g)zt
Callback when the WebSocket opening handshake completes.

Enter the OPEN state and start the data transfer phase.

z= connection is OPENN)r]   r!   r\   OPENrR   r3   r?   create_tasktransfer_datatransfer_data_taskkeepalive_pingkeepalive_ping_taskclose_connectionclose_connection_taskrn   s    ro   connection_open'WebSocketCommonProtocol.connection_openL  s     zzU-----ZZ
::KK45"&))"7"78J8J8L"M#'99#8#89L9L9N#O %)YY%:%:4;P;P;R%S"rr   c                    U R                   (       a  SOSn[        R                  " SU S3[        5        U R                  $ )Nremote_addresslocal_addressuse z[0] instead of host)r-   rE   rF   rG   rS   rn   alternatives     ro   r;   WebSocketCommonProtocol.host_  3    *...&o[M)<=?QRzzrr   c                    U R                   (       a  SOSn[        R                  " SU S3[        5        U R                  $ )Nr   r   r   z[1] instead of port)r-   rE   rF   rG   rT   r   s     ro   r<   WebSocketCommonProtocol.porte  r   rr   c                P    [         R                  " S[        5        U R                  $ )Nzdon't use secure)rE   rF   rG   rU   r   s    ro   r=   WebSocketCommonProtocol.securek  s    (*<=||rr   c                ^     U R                   nUR                  S5      $ ! [         a     gf = f)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`.

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

socknameNr}   get_extra_infoAttributeErrorrn   r}   s     ro   r   %WebSocketCommonProtocol.local_addressr  7    	8I ++J77  		    
,,c                ^     U R                   nUR                  S5      $ ! [         a     gf = f)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`.

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

peernameNr   r   s     ro   r   &WebSocketCommonProtocol.remote_address  r   r   c                    U R                   [        R                  L =(       a    U R                  R	                  5       (       + $ )aK  
:obj:`True` when the connection is open; :obj:`False` otherwise.

This attribute may be used to detect disconnections. However, this
approach is discouraged per the EAFP_ principle. Instead, you should
handle :exc:`~websockets.exceptions.ConnectionClosed` exceptions.

.. _EAFP: https://docs.python.org/3/glossary.html#term-eafp

)r]   r!   r   r   rt   r   s    ro   openWebSocketCommonProtocol.open  s.     zzUZZ'N0G0G0L0L0N,NNrr   c                :    U R                   [        R                  L $ )z
:obj:`True` when the connection is closed; :obj:`False` otherwise.

Be aware that both :attr:`open` and :attr:`closed` are :obj:`False`
during the opening and closing sequences.

)r]   r!   CLOSEDr   s    ro   closedWebSocketCommonProtocol.closed  s     zzU\\))rr   c                    U R                   [        R                  La  gU R                  c  [        R
                  $ U R                  R                  $ )z
WebSocket close code, defined in `section 7.1.5 of RFC 6455`_.

.. _section 7.1.5 of RFC 6455:
    https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5

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

N)r]   r!   r   r`   r   ABNORMAL_CLOSUREcoder   s    ro   
close_code"WebSocketCommonProtocol.close_code  s=     ::U\\)__$---??'''rr   c                    U R                   [        R                  La  gU R                  c  gU R                  R                  $ )z
WebSocket close reason, defined in `section 7.1.6 of RFC 6455`_.

.. _section 7.1.6 of RFC 6455:
    https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.6

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

N )r]   r!   r   r`   reasonr   s    ro   close_reason$WebSocketCommonProtocol.close_reason  s4     ::U\\)__$??)))rr   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 exits normally when the connection is closed with the close
code 1000 (OK) or 1001 (going away) or without a close code.

It raises a :exc:`~websockets.exceptions.ConnectionClosedError`
exception when the connection is closed with any other code.

N)recvr   r   s    ro   	__aiter__!WebSocketCommonProtocol.__aiter__  s5     	 IIK'' '! 		s    4$ "
$ 
1414c                  #    U R                   b  [        S5      e[        U R                  5      S::  a  U R                  R                  5       nXl          [        R                  " XR                  /[        R                  S9I Sh  vN   SU l         UR                  5       (       d*  U R                  (       a  gU R                  5       I Sh  vN   [        U R                  5      S::  a  M  U R                  R                  5       nU R                  b"  U R                  R                  S5        SU l        U$  N! SU l         f = f Nx7f)a  
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
connection 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 the next
message. The next invocation of :meth:`recv` will return it.

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

Returns:
    A string (:class:`str`) for a Text_ frame. 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

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

NzPcannot call recv while another coroutine is already waiting for the next messager   )return_when)rh   RuntimeErrorlenrg   r?   rc   rH   waitr   FIRST_COMPLETEDrt   r>   ensure_openpopleftri   
set_result)rn   pop_message_waitermessages      ro   r   WebSocketCommonProtocol.recv  s*    < ##/:  $-- A%7;yy7N7N7P'9$0 ll')@)@A ' 7 7  
 ,0(
 &**,,## **,,,- $-- A%2 --'') ##/$$//5'+D$5
 ,0( -sD   AE1D9 D7D9 AEEE,AE7D9 9	EEc                  #    U R                  5       I Sh  vN   U R                  b7  [        R                  " U R                  5      I Sh  vN   U R                  b  M7  [	        U[
        [        [        [        45      (       a(  [        U5      u  p#U R                  SX#5      I Sh  vN   g[	        U[        5      (       a  [        S5      e[	        U[        5      (       a  [        [        [           U5      n[!        U5      n [#        U5      n[        U5      u  p#U R&                  R)                  5       U l         U R                  SX#5      I Sh  vN   U H?  n[        U5      u  pcXb:w  a  [        S5      eU R                  S[*        U5      I Sh  vN   MA     U R                  S[*        S5      I Sh  vN    U R                  R7                  S5        SU l        g[	        U[8        5      (       Ga#  [        [:        [8        [           /[<        [           4   [?        U5      R@                  5      " U5      n [        [:        [<        [           /[B        [           4   [?        U5      RD                  5      " U5      I Sh  vN n[        U5      u  p#U R&                  R)                  5       U l         U R                  SX#5      I Sh  vN   U  Sh  vN n[        U5      u  pcXb:w  a  [        S5      eU R                  S[*        U5      I Sh  vN   MG  [        S5      e GN GN GN! [$         a     gf = f GN GN GN! [,        [        R.                  4 a!    U R1                  [2        R4                  5        e f = f! U R                  R7                  S5        SU l        f = f GN'! [F         a     gf = f N N N
 U R                  S[*        S5      I Sh  vN    O>! [,        [        R.                  4 a!    U R1                  [2        R4                  5        e f = f U R                  R7                  S5        SU l        g! U R                  R7                  S5        SU l        f = f7f)a*  
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

: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 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.

NTzdata is a dict-like objectFz data contains inconsistent typesrr   z)data must be str, bytes-like, or iterable)$r   rj   rH   shield
isinstancer/   bytes	bytearray
memoryviewr(   write_framer   	TypeErrorr   r   r"   iternextStopIterationr?   rc   r   	ExceptionCancelledErrorfail_connectionr   INTERNAL_ERRORr   r   r
   r   typer   r   	__anext__StopAsyncIteration)rn   r   opcodedataiter_messagefragmentconfirm_opcodeaiter_messages           ro   sendWebSocketCommonProtocol.send6  s    l     --9..!@!@AAA --9 gUIzBCC'0LF""4666 ))899 **8D>73G=L- (1LF.2ii.E.E.GD+7&&uf;;; !-H+7+A(N%/'(JKK**5'4@@@	 !- &&tWc::: //::4@26/ // !--.d0CCDW'' M "&mD12IdOCD'11"  "! ! (1LF.2ii.E.E.GD+7&&uf;;; '4 A(+7+A(N%/'(JKK**5'4@@@  GHHO 	!
 B 7  !  < A ;w556  $$Y%=%=>	 //::4@26/! &  <A A	 '4 &&tWc:::w556  $$Y%=%=>	 ; //::4@26/ //::4@26/sv  Q-L"4Q-L%Q-AQ-&L('AQ-L+ ,Q-<M L;A M L>"M 5M6M ;A>Q-:AN, N)N, ,Q-4O$ 	N<
O$ ON>O8O$ O O$ Q-%Q-(Q-+
L85Q-7L88Q-;M >M M ;M??N $N&&Q-)N, ,
N96Q-8N99Q-<O$ >O O$ O$ O O$ #Q $;PQ ##Q-$Q**Q-r   c                  #     [        U R                  5       ISh  vN   U R                  [        X5      5      I Sh  vN   SSS5      ISh  vN    [        U R                  5       ISh  vN   U R                  I Sh  vN   SSS5      ISh  vN   [        R                  " U R                  5      I Sh  vN   g N N Nt! , ISh  vN  (       d  f       N= f! [        R
                   a    U R                  5          Nf = f N N N{! , ISh  vN  (       d  f       N= f! [        R
                  [        R                  4 a     Nf = f N7f)a  
Perform the closing handshake.

:meth:`close` waits for the other end to complete the handshake and
for the TCP connection to terminate. As a consequence, there's no need
to await :meth:`wait_closed` after :meth:`close`.

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

Wrapping :func:`close` in :func:`~asyncio.create_task` is safe, given
that errors during connection termination aren't particularly useful.

Canceling :meth:`close` is discouraged. If it takes too long, you can
set a shorter ``close_timeout``. If you don't want to wait, let the
Python process exit, then the OS will take care of closing the TCP
connection.

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

N)r   r6   write_close_framer   rH   TimeoutErrorr   r   r   r   r   )rn   r   r   s      ro   closeWebSocketCommonProtocol.close  s     8	#&t'9'9::,,U4-@AAA ;:	 't'9'9::---- ;: nnT778881 ;A ;:::## 	#   "		#  ;- ;:::$$g&<&<= 		 	9s  EC  C C  CC CC  CC  D* .D
/D* 2DDDD* DD* #E:E;E C  CC  CCCC  EC   $DEDE
D* DD* D'DD'#D* &E'D* *$EEEEc                `   #    [         R                  " U R                  5      I Sh  vN   g N7f)a	  
Wait until the connection is closed.

This coroutine is identical to the :attr:`closed` attribute, except it
can be awaited.

This can make it easier to detect connection termination, regardless
of its cause, in tasks that interact with the WebSocket connection.

N)rH   r   rd   r   s    ro   wait_closed#WebSocketCommonProtocol.wait_closed  s      nnT88999s   $.,.c                   #    U R                  5       I Sh  vN   Ub  [        U5      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[        R                  " 5       nX#4U R                  U'   U R                  S[        U5      I Sh  vN   [        R                  " U5      $  N N7f)a  
Send a Ping_.

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

A ping may serve as a keepalive, as a check that the remote endpoint
received all messages up to this point, or to measure :attr:`latency`.

Canceling :meth:`ping` is discouraged. If :meth:`ping` doesn't return
immediately, it means the write buffer is full. If you don't want to
wait, you should close the connection.

Canceling the :class:`~asyncio.Future` returned by :meth:`ping` has no
effect.

Args:
    data: Payload of the ping. A string 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.
    RuntimeError: If another ping was sent with the same data and
        the corresponding pong wasn't received yet.

Nz-already waiting for a pong with the same dataz!Ir2   T)r   r'   rk   r   structpackrandomgetrandbitsr?   rc   timeperf_counterr   r   rH   r   )rn   r   pong_waiterping_timestamps       ro   pingWebSocketCommonProtocol.ping  s     J    %D ::NOO ldjj0;;tV%7%7%;<D ldjj0 ii--/**,'8

4tWd333~~k**) 	!$ 	4s/   DD
A,DDAD/D0DDc                   #    U R                  5       I Sh  vN   [        U5      nU R                  S[        U5      I Sh  vN   g N/ N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.

Canceling :meth:`pong` is discouraged. If :meth:`pong` doesn't return
immediately, it means the write buffer is full. If you don't want to
wait, you should close the connection.

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

Raises:
    ConnectionClosed: When the connection is closed.

NT)r   r'   r   r   rn   r   s     ro   pongWebSocketCommonProtocol.pongT  sE     &    D!tWd333	 	! 	4s!   A
A)A
 AA
A
c                   U R                   bu  U R                   R                  [        ;   aW  U R                  bJ  U R                  R                  [        ;   a,  [	        U R                   U R                  U R
                  5      nO+[        U R                   U R                  U R
                  5      nU R                  Ul        U$ N)	r`   r   r   ra   r   rb   r   rm   	__cause__r   s     ro   connection_closed_exc-WebSocketCommonProtocol.connection_closed_exco  s     OO'$$6+$$6$))C ())C ..
rr   c                T  #    U R                   [        R                  L aX  U R                  R	                  5       (       a8  [
        R                  " U R                  5      I Sh  vN   U R                  5       egU R                   [        R                  L a  U R                  5       eU R                   [        R                  L a8  [
        R                  " U R                  5      I Sh  vN   U R                  5       eU R                   [        R                  L d   e[        S5      e N N@7f)zr
Check that the WebSocket connection is open.

Raise :exc:`~websockets.exceptions.ConnectionClosed` if it isn't.

Nz*WebSocket connection isn't established yet)r]   r!   r   r   rt   rH   r   r   r   r   CLOSINGr\   r   r   s    ro   r   #WebSocketCommonProtocol.ensure_open  s      ::# &&++--nnT%?%?@@@0022::%,,..::& ..!;!;<<<,,.. zzU-----GHH' A =s%   A D("D$#BD(%D&&?D(&D(c                  #      U R                  5       I Sh  vN nUc  gU R                  b  [        U R                  5      U R                  :  at  U R                  R                  5       U l         [        R                  " U R                  5      I Sh  vN   SU l        [        U R                  5      U R                  :  a  Mt  U R                  R                  U5        U R                  b"  U R                  R                  S5        SU l
        GM   N N! SU l        f = f! [        R                   a  nX l        e SnAf[         a/  nX l        U R                  [         R"                  5         SnAgSnAf[$        [&        [(        [*        R,                  4 a/  nX l        U R                  [         R.                  5         SnAgSnAf[0         a/  nX l        U R                  [         R2                  5         SnAgSnAf[4         a/  nX l        U R                  [         R6                  5         SnAgSnAf[8         aI  nU R:                  R=                  SSS9  X l        U R                  [         R>                  5         SnAgSnAff = f7f)zy
Read incoming messages and put them in a queue.

This coroutine runs in a task until the closing handshake is started.

TNzdata transfer failedexc_info) read_messager8   r   rg   r?   rc   ri   rH   r   appendrh   r   r   rm   r   r   r   PROTOCOL_ERRORConnectionErrorr   EOFErrorsslSSLErrorr   UnicodeDecodeErrorINVALID_DATAr   MESSAGE_TOO_BIGr   r3   errorr   )rn   r   r   s      ro   r   %WebSocketCommonProtocol.transfer_data  s    =	; $ 1 1 33 ? >>-dmm,>37993J3J3L0<")..1I1I"JJJ7;D4 dmm,> $$W- ++7,,77=/3D,- 3 K7;D4 %% 	%("  	;%("  !9!9::xF 		= &)"  !;!;<<! 	9%("  !7!788 	<%("  !:!:;; 	; KK4tD%("  !9!9::	;s   JD" DD" JAD" 1#D DD *D" AD" D 	DD" "J	6D==J	
%E4/J4'J	%G JJ	%G<7J<J		%H3.J3J	 ?J?JJ		Jc                P  ^^^#    U R                  U R                  S9I Sh  vN nUc  gUR                  [        :X  a  SnO"UR                  [        :X  a  SnO[        S5      eUR                  (       a-  U(       a  UR                  R                  5       $ UR                  $ / mU R                  mU(       a4  [        R                  " S5      nU" SS9mTc
  SUU4S	 jjnO SUUU4S
 jjnOTc	  SU4S jjnO	SUU4S jjnU" U5        UR                  (       d_  U R                  TS9I Sh  vN nUc  [        S5      eUR                  [        :w  a  [        S5      eU" U5        UR                  (       d  M_  U(       a  SR                  T5      $ SR                  T5      $  GN Nx7f)z
Read a single message from the connection.

Re-assemble data frames if the message is fragmented.

Return :obj:`None` when the closing handshake is started.

)r7   NTFzunexpected opcodezutf-8strict)errorsc                p   > TR                  TR                  U R                  U R                  5      5        g r   )r  decoder   fin)framedecoder	fragmentss    ro   r  4WebSocketCommonProtocol.read_message.<locals>.append  s$    $$W^^EJJ		%JKrr   c                   > TR                  TR                  U R                  U R                  5      5        [	        T[
        5      (       d   eT[        U R                  5      -  mg r   )r  r  r   r  r   intr   )r  r  r  r7   s    ro   r  r    sI    $$W^^EJJ		%JK%h4444EJJ/Hrr   c                <   > TR                  U R                  5        g r   )r  r   )r  r  s    ro   r  r    s    $$UZZ0rr   c                   > TR                  U R                  5        [        T[        5      (       d   eT[	        U R                  5      -  mg r   )r  r   r   r  r   )r  r  r7   s    ro   r  r  %  s:    $$UZZ0%h4444EJJ/Hrr   zincomplete fragmented messager   rr   )r  r&   returnNone)read_data_framer7   r   r   r   r   r  r   r  codecsgetincrementaldecoderr   join)rn   r  textdecoder_factoryr  r  r  r7   s        @@@ro   r  $WebSocketCommonProtocol.read_message  sz     **DMM*BB =<<7"D\\Y&D 344 99*.5::$$&>EJJ> !#	==$::7CO%X6GL L0 0 1 10 0 	u))...AAE}#$CDD||w&#$7885M ))) )))44)))44} Cn Bs)   F&F!DF&+F$,A
F&8*F&$F&c                  #     U R                  U5      I Sh  vN nUR                  [        :X  ai  [        R                  " UR
                  5      U l        U R                  b  SU l         U R                  U R                  UR
                  5      I Sh  vN   gUR                  [        :X  aC  U R                  [        R                  L a%   U R                  UR
                  5      I Sh  vN   OOUR                  [         :X  a  UR
                  U R"                  ;   a  [$        R&                  " 5       nSn/ nU R"                  R)                  5        H[  u  nu  pgUR+                  U5        UR-                  5       (       d  UR/                  X7-
  5        XBR
                  :X  d  MR  X7-
  U l          O   [3        S5      eU H  nU R"                  U	 M     OU$ GM   GN GNG! [         a     gf = f GN! [         a     N(f = f7f)z
Read a single data frame from the connection.

Process control frames received before the next data frame.

Return :obj:`None` if a close frame is encountered before any data frame.

NFz!solicited pong not found in pings)
read_framer   r   r   parser   r`   ra   rb   r   r   r   r]   r!   r   r   r   rk   r   r   itemsr  rt   r   rl   AssertionError)rn   r7   r  pong_timestampping_idping_idsr   r   s           ro   r!  'WebSocketCommonProtocol.read_data_frame7  s     //(33E ||x' #(++ejj"9??.05D- 00%**MMM (::+"ii

333 , (::+%)%6%6%8N #G!HBF**BRBRBT>!>+ 0*//11'22>3RS"jj0+9+JDL! CU --PQQ#+ JJw/ $,
 g 3 N'  4+ s   HGAH+)G GG 2HG1 *G.+G1 /B1H$5HG 
G+(H*G++H.G1 1
G>;H=G>>Hc                  #    [         R                  " U R                  R                  U R                  (       + UU R
                  S9I Sh  vN nU R                  (       a  U R                  R                  SU5        U$  N37f)z+
Read a single frame from the connection.

)maskr7   r^   Nz< %s)r&   readrW   readexactlyr-   r^   rR   r3   )rn   r7   r  s      ro   r)  "WebSocketCommonProtocol.read_framev  sb     
 jjKK##^^#	
 
 ::KKfe,
s   AB 
A>4B c                    [        U[        U5      U5      nU R                  (       a  U R                  R                  SU5        UR	                  U R
                  R                  U R                  U R                  S9  g )Nz> %s)r2  r^   )r&   r    rR   r3   writer}   r-   r^   )rn   r  r   r   r  s        ro   write_frame_sync(WebSocketCommonProtocol.write_frame_sync  s[    c6&>40::KKfe,NN   	 	
rr   c                :  #     U R                    IS h  vN   U R                  5       I S h  vN   S S S 5      IS h  vN   g  N- N N	! , IS h  vN  (       d  f       g = f! [         a,    U R                  5         U R	                  5       I S h  vN     g f = f7fr   )r[   r   r  r   r   r   s    ro   drainWebSocketCommonProtocol.drain  ss     	% '''kkm## (''# ('''  	%  " ""$$$	%s   BA" AA" AAAA" AA" BA" AA" AAAA" BA" "-BBBBBB_statec                  #    U R                   ULa#  [        SU R                   R                   S35      eU R                  XU5        U R	                  5       I S h  vN   g  N7f)Nz#Cannot write to a WebSocket in the z state)r]   r   namer8  r;  )rn   r  r   r   r>  s        ro   r   #WebSocketCommonProtocol.write_frame  sV      ::V#5djjoo5FfM  	c40jjls   AA"A A"c                  #    U R                   [        R                  L a  [        R                  U l         U R                  (       a  U R
                  R	                  S5        Xl        U R                  b  SU l        Uc  UR                  5       nU R                  S[        U[        R                  S9I Sh  vN   gg N7f)z
Write a close frame if and only if the connection state is OPEN.

This dedicated coroutine must be used for writing close frames to
ensure that at most one close frame is sent on a given connection.

= connection is CLOSINGNTr=  )r]   r!   r   r   rR   r3   ra   r`   rb   	serializer   r   )rn   r   r   s      ro   r   )WebSocketCommonProtocol.write_close_frame  s      ::#DJzz!!";<#O*,0)|( ""44"NNN $ Os   B3B>5B<6B>c                $  #    U R                   c  g  [        R                  " U R                   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   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                   aO    U R                  (       a  U R                  R	                  S5        U R                  [        R                  S5         gf = f! [         a     g[         a    U R                  R                  SSS9   gf = f7f)	a  
Send a Ping frame and wait for a Pong frame at regular intervals.

This coroutine exits when the connection terminates and one of the
following happens:

- :meth:`ping` raises :exc:`ConnectionClosed`, or
- :meth:`close_connection` cancels :attr:`keepalive_ping_task`.

NTz% sending keepalive pingz% received keepalive pongz&- timed out waiting for keepalive pongzkeepalive ping timeoutzkeepalive ping failedr  )r4   rH   r   r3   rR   r   r5   r   r   r   r   r   r   r   r  )rn   r   s     ro   r   &WebSocketCommonProtocol.keepalive_ping  sN     %	FmmD$6$6777!!"<=$(IIK/$$0#243D3D#E#E
 #.-- $F#E ))*EF 7 0 $F
 . $F#E#E#E #// :: KK--.VW,,%444    	 	FKK5E	Fs   F$E C2E )C*E <C5 CC5 CC C$C5 /C0C5 E E C5 CC5 C2!C$"C2.C5 5A EE FEE 
F%F'#F
FFFc                8  #     [        U S5      (       a   U R                  I Sh  vN   [        U S5      (       a  U R                  R                  5         U R                  (       at  [        U S5      (       ac  U R                  5       I Sh  vN (       a   U R                  5       I Sh  vN   gU R                  (       a  U R                  R                  S5        U R                  R                  5       (       a  U R                  (       a  U R                  R                  S5         U R                  R                  5         U R                  5       I Sh  vN (       a   U R                  5       I Sh  vN   gU R                  (       a  U R                  R                  S5        U R                  5       I Sh  vN   g GN! [        R                   a     GNf = f GNP GN5! [        [        4 a     Nf = f N N NC! U R                  5       I Sh  vN    f = f7f)aZ  
7.1.1. Close the WebSocket Connection

When the opening handshake succeeds, :meth:`connection_open` starts
this coroutine in a task. It waits for the data transfer phase to
complete then it closes the TCP connection cleanly.

When the opening handshake fails, :meth:`fail_connection` does the
same. There's no data transfer phase in that case.

r   Nr   !- timed out waiting for TCP closezx half-closing TCP connection)hasattrr   rH   r   r   cancelr-   wait_for_connection_lostclose_transportrR   r3   r}   can_write_eof	write_eofOSErrorr   r   s    ro   r   (WebSocketCommonProtocol.close_connection  s    (	)t1221111
 t233((//1 ~~'$0D"E"E668882 &&(((1 ::KK%%&IJ ~~++--::KK%%&EF
NN,,. 66888 &&((( ::KK%%&IJ
 &&(((I 2--  94 )  .  9 )$&&(((s   HG< F? F<F? A G< 
G	G< H(G)H.A7G< &G   G< G6	G< H1G82H7,G< #H6G:7H<F? ?GG< GG< H G30G< 2G33G< 8H:H<HHHHc                n  #    U R                   R                  5       (       a   U R                  R                  5       (       a  gU R                  (       a  U R
                  R	                  S5        U R                  R                  5         U R                  5       I Sh  vN (       a  gU R                  (       a  U R
                  R	                  S5        U R                  (       a  U R
                  R	                  S5        U R                  R                  5         U R                  5       I Sh  vN   g N N7f)z
Close the TCP connection.

Nzx closing TCP connectionrI  zx aborting TCP connection)	rd   rt   r}   r~   rR   r3   r   rL  abortr   s    ro   rM  'WebSocketCommonProtocol.close_transport%  s      &&++--$..2K2K2M2M ::KK89..000::KKAB ::KK9: ++--- 1 	.s%   BD5D1BD5+D3,D53D5c                  #    U R                   R                  5       (       dW   [        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 R                   R                  5       $  NV N0 N"! , ISh  vN  (       d  f       N7= f! [        R                   a     NPf = f7f)z
Wait until the TCP connection is closed or ``self.close_timeout`` elapses.

Return :obj:`True` if the connection is closed and :obj:`False`
otherwise.

N)rd   rt   r   r6   rH   r   r   r   s    ro   rL  0WebSocketCommonProtocol.wait_for_connection_lostB  s      **//11*4+=+=>>!..)D)DEEE ?> **//11 ?E ?>>>'' s    CB3 BB3  $B$B%B)B3 4B5B3 9CB3 BB3 B0B" B0,B3 /C0B3 3C
C	C

Cc                   U R                   (       a  U R                  R                  SU5        [        U S5      (       a  U R                  R	                  5         U[
        R                  :w  a  U R                  [        R                  L a  [        X5      n[        R                  U l        U R                   (       a  U R                  R                  S5        U R                  b   eX0l        U R                  S[        UR!                  5       5        [        U S5      (       d/  U R"                  R%                  U R'                  5       5      U l        gg)a3  
7.1.7. Fail the WebSocket Connection

This requires:

1. Stopping all processing of incoming data, which means cancelling
   :attr:`transfer_data_task`. The close code will be 1006 unless a
   close frame was received earlier.

2. Sending a close frame with an appropriate code if the opening
   handshake succeeded and the other side is likely to process it.

3. Closing the connection. :meth:`close_connection` takes care of
   this once :attr:`transfer_data_task` exits after being canceled.

(The specification describes these steps in the opposite order.)

z!! failing connection with code %dr   rC  NTr   )rR   r3   rJ  r   rK  r   r   r]   r!   r   r   r   r`   ra   r8  r   rD  r?   r   r   r   )rn   r   r   r   s       ro   r   'WebSocketCommonProtocol.fail_connectionU  s    . ::KKA4H 4-..##**, 9---$**

2J$'E DJzz!!";<
 ??***#O!!$%//2CD t455)-)>)>t?T?T?V)WD& 6rr   c                    U R                   [        R                  L d   eU R                  5       nU R                  R                  5        H&  u  p#UR                  U5        UR                  5         M(     g)zr
Raise ConnectionClosed in pending keepalive pings.

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

N)r]   r!   r   r   rk   valuesset_exceptionrK  )rn   r   r   _ping_timestamps       ro   abort_pings#WebSocketCommonProtocol.abort_pings  s_     zzU\\)))((*,0JJ,=,=,?(K%%c*
   -@rr   c                    [        [        R                  U5      nUR                  U R                  5        Xl        U R                  R                  U5        g)a  
Configure write buffer limits.

The high-water limit is defined by ``self.write_limit``.

The low-water limit currently defaults to ``self.write_limit // 4`` in
:meth:`~asyncio.WriteTransport.set_write_buffer_limits`, which should
be all right for reasonable use cases of this library.

This is the earliest point where we can get hold of the transport,
which means it's the best point for configuring it.

N)r   rH   	Transportset_write_buffer_limitsr:   r}   rW   set_transportr   s     ro   connection_made'WebSocketCommonProtocol.connection_made  sC     **I6	))$*:*:;" 	!!),rr   c                   [         R                  U l        U R                  R	                  S5        U R                  5         U R                  R                  S5         U R                  b9  Uc  U R                  R                  5         OU R                  R                  U5        U R                  (       d  gU R                  nUc  gSU l        UR                  5       (       a  gUc  UR                  S5        gUR                  U5        g)z-
7.1.4. The WebSocket Connection is Closed.

z= connection is CLOSEDN)r!   r   r]   r3   rR   r]  rd   r   rW   feed_eofr[  rX   rY   rt   )rn   r   rx   s      ro   connection_lost'WebSocketCommonProtocol.connection_lost  s    
 \\
23
 	##..t4{{&;KK((*KK--c2 <<''F~!%D{{}}{!!$'$$S)rr   c                8    U R                   (       a   eSU l         g )NT)rX   r   s    ro   pause_writing%WebSocketCommonProtocol.pause_writing  s    <<rr   c                    U R                   (       d   eSU l         U R                  nUb/  S U l        UR                  5       (       d  UR                  S 5        g g g )NF)rX   rY   rt   r   rw   s     ro   resume_writing&WebSocketCommonProtocol.resume_writing  sQ    |||##!%D;;==!!$' ! rr   c                :    U R                   R                  U5        g r   )rW   	feed_datar   s     ro   data_received%WebSocketCommonProtocol.data_received  s    d#rr   c                8    U R                   R                  5         g)ar  
Close the transport after receiving EOF.

The WebSocket protocol has its own closing handshake: endpoints close
the TCP or TLS connection after sending and receiving a close frame.

As a consequence, they never need to write after receiving EOF, so
there's no reason to keep the transport open by returning :obj:`True`.

Besides, that doesn't work on TLS connections.

N)rW   rf  r   s    ro   eof_received$WebSocketCommonProtocol.eof_received  s     	rr   )%r[   rY   rj   rS   rX   rh   rT   ri   rU   r   r`   rb   ra   r6   rd   rR   r^   rL   r   rl   r>   r3   r?   r8   r7   rg   r4   r5   rk   r9   rW   r]   r_   rm   r   r}   r:   )r3   zLoggerLike | Noner4   float | Noner5   rv  r6   rv  r7   
int | Noner8   rw  r9   r  r:   r  r;   
str | Noner<   rw  r=   bool | Noner>   r,   r?   z asyncio.AbstractEventLoop | Noner@   rv  r  r   )r  r   )r  rx  )r  rw  )r  ry  )r  r	   )r  r,   )r  zAsyncIterator[Data])r  r"   )r   z+Data | Iterable[Data] | AsyncIterable[Data]r  r   )r   r  r   r/   r  r   r   )r   Data | Noner  zAwaitable[float])rr   )r   r"   r  r   )r  r   )r  rz  )r7   rw  r  zFrame | None)r7   rw  r  r&   )r  r,   r   r  r   r   r  r   )
r  r,   r   r  r   r   r>  r  r  r   )r   r   r   zbytes | Noner  r   )r}   zasyncio.BaseTransportr  r   )r   zException | Noner  r   )r   r   r  r   )8__name__
__module____qualname____firstlineno____doc____annotations__r0   rp   ry   r   r   propertyr;   r<   r=   r   r   r   r   r   r   r   r   r   r   NORMAL_CLOSUREr   r   r   r   r   r   r   r  r!  r)  r8  r;  r!   r   r   r   r   r   rM  rL  r   r   r]  rc  rg  rj  rm  rq  rt  __static_attributes__ rr   ro   r)   r)   6   s   _H OD#
 %)&(%'&*$ $ "!15 $#O7 "O7 $	O7
 #O7 $O7 O7 O7 O7 O7 O7 O7 O7 O7  /!O7" #O7$ 
%O7d	# T&  
  
   8 8& 8 8& O O * * ( (" * *""L\]I<]I 
]IB ,,5959 59 
	59n:9+v46. IDD;LG5R=~
%  EJJJ		!$	,1	>A			O2+FZ4)l.:2* ..<X<X <X 
	<X|!(-*$*L($rr   c           
     B   [        U[        [        [        [        45      (       d  [        S5      eU(       a$  [        R                  SS S:  a  [        S5      e/ n[        U5      u  pEU  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%                  SXE5        M     U(       a  W(       a  [3        SU5      egg! [&         a  nU(       a(  [        S	5      nXl        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M.  SnAff = f)a  
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.legacy.protocol.WebSocketCommonProtocol.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.

zdata must be str or bytes-likeNr   )      z.raise_exceptions requires at least Python 3.11zsending a fragmented messagez/skipped broadcast: sending a fragmented messageTzfailed to write messagez.skipped broadcast: failed to write message: %sr   zskipped broadcast)r   r/   r   r   r   r   sysversion_info
ValueErrorr(   r]   r!   r   rj   r   r  r3   warningr8  r   r   	tracebackformat_exception_onlyr   stripExceptionGroup)	
websocketsr   raise_exceptions
exceptionsr   r   rC   r|   write_exceptions	            ro   	broadcastr  	  sn   d gUIzBCC899BQ')MNN
(LF	??%**,//;()GH	!!),  ((E 	&&tV:  > J0*== '  	()BC	&5#!!),,  ((D33_-' 	  	s   D
F)FAFFzwebsockets.legacy.server)F)r  z!Iterable[WebSocketCommonProtocol]r   r"   r  r,   r  r   )?
__future__r   rH   r"  re   rM   r   r
  r   r  r   r  rJ   rE   collections.abcr   r   r   r   r   typingr	   r
   r   r   asyncio.compatibilityr   datastructuresr   r  r   r   r   r   r   r   r^   r   framesr   r   r   r   r   r   r   r   r   r    protocolr!   r"   r#   r$   framingr&   r'   r(   __all__Protocolr)   r  r|  r  rr   ro   <module>r     s    "      
  
     V V - - 3 $  #    2 2 6 6 %
%Jg.. Jl. #\>1\>\> \> 
	\>@ 2	 rr   