ó
    ÖÁ“i�ø  ã                  ó°  • 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J3r3J4r4J5r5J6r6J7r7  SSK8J9r9J:r:J;r;  S/r< " S S\Rz                  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)Ú	BytesLikeÚDataÚDataLikeÚ
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( SG     SQS. 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               ól  • 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
        X€l        [        R                  " 5       U l         Uc  [        R                   " S5      n[        R"                  " USU 05      U l         UR'                  [        R(                  5      U l        XÐl        X�l        X l        X°l        XÀl        [        R6                  " US-  US9U l        S	U l        S U l        [>        R@                  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RO                  5       U l(        [R        RT                  " 5       U l+        S U l,        S U l-        S U l.        0 U l/        SU l0         U   S U l1        U   U   g )Nzlegacy_recv is deprecatedé
   zrename timeout to close_timeoutzremove loop argumentzwebsockets.protocolÚ	websocketr   )ÚlimitrA   Fz= connection is CONNECTINGr   )2ÚwarningsÚwarnÚDeprecationWarningÚasyncioÚget_event_loopr6   r7   r8   r9   r:   r;   r<   ÚuuidÚuuid4ÚidÚloggingÚ	getLoggerÚLoggerAdapterr5   ÚisEnabledForÚDEBUGÚdebugrA   Ú_hostÚ_portÚ_securer@   ÚStreamReaderÚreaderÚ_pausedÚ_drain_waiterr!   Ú
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)Úselfr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   s                  ÚW/home/mande/repo/quber/.venv/lib/python3.13/site-packages/websockets/legacy/protocol.pyÚ__init__Ú WebSocketCommonProtocol.__init__ž   s  € ö& Ü�MŠMÐ5Ô7IÔJð ‰?Ø‰Gä�MŠMÐ;Ô=OÔPàÑ Ø#ˆMð ‰<Ü×)Ò)Ó+‰Dä�MŠMÐ0Ô2DÔEà*ÔØ(ÔØ*ÔØ ŒØ"ŒØ$ŒØ&Ôô "ŸZšZ›\ˆŒØBð ‰>Ü×&Ò&Ð'<Ó=ˆFÜ")×"7Ò"7¸ÀÈdÐ@SÓ"TˆŒØ)ð ×(Ñ(¬¯©Ó7ˆŒ
àŒ	àŒ
ØŒ
ØŒØ&Ôô ×*Ò*°¸q±ÀtÑLˆŒð ˆŒØ:>ˆÔô ×%Ñ%ˆŒ
Ø�:�:Ø�K‰K×ÑÐ:Ô;ñ 	Ø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ÚConnectionResetErrorrZ   r[   Ú	cancelledrA   rc   ©rn   Úwaiters     ro   Ú_drain_helperÚ%WebSocketCommonProtocol._drain_helper.  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   )rY   Ú	exceptionÚ	transportÚ
is_closingrJ   Úsleepry   ©rn   Úexcs     ro   Ú_drainÚWebSocketCommonProtocol._drain:  sv   é € Ø�;‰;Ñ"Ø—+‘+×'Ñ'Ó)ˆCØ‰Ø�	Ø�>‰>Ñ%Ø�~‰~×(Ñ(×*Ñ*ô —m’m AÓ&×&Ð&Ø× Ñ Ó"×"Ñ"ñ 'Ù"ù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\   ÚOPENrT   r5   rA   Úcreate_taskÚtransfer_dataÚtransfer_data_taskÚkeepalive_pingÚkeepalive_ping_taskÚclose_connectionÚclose_connection_task©rn   s    ro   Úconnection_openÚ'WebSocketCommonProtocol.connection_openJ  s¡   € ð �z‰zœU×-Ñ-Ò-Ð-Ð-Ü—Z‘ZˆŒ
Ø�:�:Ø�K‰K×ÑÐ4Ô5à"&§)¡)×"7Ñ"7¸×8JÑ8JÓ8LÓ"MˆÔà#'§9¡9×#8Ñ#8¸×9LÑ9LÓ9NÓ#OˆÔ à%)§Y¡Y×%:Ñ%:¸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/   rG   rH   rI   rU   ©rn   Úalternatives     ro   r=   ÚWebSocketCommonProtocol.host]  ó3   € à*.¯.¯.Ñ&¸oˆÜ�Š˜˜[˜MÐ)<Ð=Ô?QÔRØ�z‰zÐ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/   rG   rH   rI   rV   r”   s     ro   r>   ÚWebSocketCommonProtocol.portc  r—   rr   c                óP   • [         R                  " S[        5        U R                  $ )Nzdon't use secure)rG   rH   rI   rW   r�   s    ro   r?   ÚWebSocketCommonProtocol.securei  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_addressp  ó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.   € ð �z‰zœUŸZ™ZÐ'×N°×0GÑ0G×0LÑ0LÓ0NÔ,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   € ð �z‰zœUŸ\™\Ð)Ð)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   é € ð	ØØ ŸI™I›K×'Ó'ñ Ù'øÜ!ó 	Ùð	ü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   rA   rc   rJ   Úwaitrˆ   ÚFIRST_COMPLETEDrt   r@   Úensure_openÚpopleftri   Ú
set_result)rn   Úpop_message_waiterÚmessages      ro   rº   ÚWebSocketCommonProtocol.recvæ  s*  é € ð< ×#Ñ#Ñ/Üð:óð ô �$—-‘-Ó  AÓ%Ø7;·y±y×7NÑ7NÓ7PÐØ'9Ô$ð0ô —l’lØ'×)@Ñ)@Ð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      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                  R3                  S5        SU l        g[	        U[4        5      (       Ga#  [7        [8        [4        [:           /[<        [:           4   [?        U5      R@                  5      " U5      n [7        [8        [<        [:           /[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Nk! [          a     gf = f GNê GN¬ GNŒ! [(        [        R*                  4 a!    U R-                  [.        R0                  5        e f = f! U R                  R3                  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 R-                  [.        R0                  5        e f = f U R                  R3                  S5        SU l        g! U R                  R3                  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   rJ   ÚshieldÚ
isinstancer1   ÚbytesÚ	bytearrayÚ
memoryviewr*   Úwrite_framer   Ú	TypeErrorr   ÚiterÚnextÚStopIterationrA   rc   r   Ú	ExceptionÚCancelledErrorÚfail_connectionr   ÚINTERNAL_ERRORrÅ   r   r   r
   r$   r   Útyper»   r   Ú	__anext__ÚStopAsyncIteration)rn   rÇ   ÚopcodeÚdataÚiter_messageÚfragmentÚconfirm_opcodeÚaiter_messages           ro   ÚsendÚWebSocketCommonProtocol.send4  sì  é € ðl ×ÑÓ × Ð ð ×-Ñ-Ñ9Ü—.’. ×!@Ñ!@ÓA×AÐAð ×-Ñ-Ó9ô �g¤¤U¬I´zÐB×CÑCÜ'¨Ó0‰LˆFØ×"Ñ" 4¨Ó6×6Ñ6ô ˜¤×)Ñ)ÜÐ8Ó9Ð9ô ˜¤×*Ñ*Ü ›=ˆLðÜ Ó-�ô (¨Ó1‰LˆFà.2¯i©i×.EÑ.EÓ.GˆDÔ+ð7à×&Ñ& u¨fÓ;×;Ð;ó !-�HÜ+7¸Ó+AÑ(�NØ%Ó/Ü'Ð(JÓKÐKØ×*Ñ*¨5´'¸4Ó@×@Ò@ñ	 !-ð ×&Ñ& t¬W°cÓ:×:Ñ:ð ×/Ñ/×:Ñ:¸4Ô@Ø26�Õ/ô ˜¤×/Ò/ô !Üœ-¬Ñ1Ð2´MÄ(Ñ4KÐKÑLÜ�W“×'Ñ'ôð óˆMðô "&Üœm¬HÑ5Ð6¼	Ä(Ñ8KÐKÑLÜ˜Ó'×1Ñ1ô"ð  ó"!÷ !�ô (¨Ó1‰LˆFà.2¯i©i×.EÑ.EÓ.GˆDÔ+ð7à×&Ñ& u¨fÓ;×;Ð;ñ '4÷ A˜(Ü+7¸Ó+AÑ(�NØ%Ó/Ü'Ð(JÓKÐKØ×*Ñ*¨5´'¸4Ó@×@Ò@ô  ÐGÓHÐHòI 	!ò
 Bò 7øô !ó Ùðúò <ò Aò ;øäœw×5Ñ5Ð6ó ð ×$Ñ$¤Y×%=Ñ%=Ô>Øð	ûð ×/Ñ/×:Ñ:¸4Ô@Ø26�Õ/úò!øô &ó Ùðúñ <ñAñ Að	 '4ð ×&Ñ& t¬W°cÓ:×:Ò:øäœw×5Ñ5Ð6ó ð ×$Ñ$¤Y×%=Ñ%=Ô>Øð	úð ;ð ×/Ñ/×:Ñ:¸4Ô@Ø26�Õ/øð ×/Ñ/×:Ñ:¸4Ô@Ø26�Õ/üsv  ‚Q–L—4QÁLÁQÁAQÂ&LÂ'AQÃ-L Ã8,QÄ%L- Ä:L$Ä;A L- Å;L'Å<"L- ÆL*ÆL- Æ$A>QÈ#AN É+NÉ,N É0,QÊO Ê2N%Ê3O Ê9N+Ê=N'Ê>N+Ë8O Ë9N)Ë:O Ì QÌQÌQÌ
L!ÌQÌ L!Ì!QÌ$L- Ì'L- Ì*L- Ì-;M(Í(M+ Í+$NÎQÎN Î
N"ÎQÎ!N"Î"QÎ%O Î'N+Î)O Î+O ÏO	ÏO ÏP/ Ï;PÐP/ Ð#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          N²f = f N› N‰ N{! , ISh  v•N  (       d  f       N�= f! [        R
                  [        R                  4 a     N¹f = f N™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. 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   r8   Úwrite_close_framer   rJ   ÚTimeoutErrorrÖ   rˆ   rÕ   rÊ   rŒ   )rn   r±   r¶   s      ro   ÚcloseÚWebSocketCommonProtocol.closeÐ  sü   é € ð8	#Ü& t×'9Ñ'9×:Õ:Ø×,Ñ,¬U°4Ó-@ÓA×AÐA÷ ;×:ð	ô ' t×'9Ñ'9×:Õ:Ø×-Ñ-×-Ð-÷ ;×:ô �nŠn˜T×7Ñ7Ó8×8Ñ8ñ1 ;ÙA÷ ;×:×:Ð:ûä×#Ñ#ó 	#ð × Ñ Ö"ð		#úñ  ;Ù-÷ ;×:×:Ð:ûä×$Ñ$¤g×&<Ñ&<Ð=ó 	Ùð	úñ 	9ùs  ‚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)rJ   rÊ   rd   r�   s    ro   Úwait_closedÚ#WebSocketCommonProtocol.wait_closed  s   é € ô �nŠn˜T×8Ñ8Ó9×9Ó9ùs   ‚$.¦,§.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!Ir4   T)rÃ   r)   rk   r¿   ÚstructÚpackÚrandomÚgetrandbitsrA   rc   ÚtimeÚperf_counterrÏ   r   rJ   rÊ   )rn   rÜ   Úpong_waiterÚping_timestamps       ro   ÚpingÚWebSocketCommonProtocol.ping  sá   é € ðJ ×ÑÓ × Ð àÑÜ Ó%ˆDð —:‘:ÓÜÐNÓOÐOð ‰l˜d§j¡jÓ0Ü—;’;˜t¤V×%7Ò%7¸Ó%;Ó<ˆDð ‹l˜d§j¡jÕ0ð —i‘i×-Ñ-Ó/ˆä×*Ò*Ó,ˆØ'Ð8ˆ�
‰
�4Ñà×Ñ˜t¤W¨dÓ3×3Ð3ä�~Š~˜kÓ*Ð*ñ) 	!ñ$ 	4ùs/   ‚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.pongO  sE   é € ð& ×ÑÓ × Ð ä˜DÓ!ˆà×Ñ˜t¤W¨dÓ3×3Ñ3ñ	 	!ñ 	4ùs!   ‚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_excj  s”   € ð �O‰OÑ'Ø—‘×$Ñ$¬Ó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   rJ   rÊ   rŒ   rý   r¬   ÚCLOSINGr\   r   r�   s    ro   rÃ   Ú#WebSocketCommonProtocol.ensure_open�  sá   é € ð �:‰:œŸ™Ò#ð ×&Ñ&×+Ñ+×-Ñ-Ü—n’n T×%?Ñ%?Ó@×@Ð@Ø×0Ñ0Ó2Ð2àà�:‰:œŸ™Ò%Ø×,Ñ,Ó.Ð.à�:‰:œŸ™Ò&ô —.’. ×!;Ñ!;Ó<×<Ð<Ø×,Ñ,Ó.Ð.ð �z‰zœU×-Ñ-Ò-Ð-Ð-ÜÐ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_messager:   rÀ   rg   rA   rc   ri   rJ   rÊ   Úappendrh   rÅ   rÕ   rm   r   rÖ   r   ÚPROTOCOL_ERRORÚConnectionErrorrå   ÚEOFErrorÚsslÚSSLErrorr°   ÚUnicodeDecodeErrorÚINVALID_DATAr   ÚMESSAGE_TOO_BIGrÔ   r5   Úerrorr×   )rn   rÇ   r�   s      ro   r‡   Ú%WebSocketCommonProtocol.transfer_data£  sø  é € ð=	;ØØ $× 1Ñ 1Ó 3×3�ð ‘?Øð —>‘>Ñ-Ü˜dŸm™mÓ,°·±Ó>Ø37·9±9×3JÑ3JÓ3L˜Ô0ð<Ü")§.¢.°×1IÑ1IÓ"J×JÐJà7;˜DÔ4ô ˜dŸm™mÓ,°·±Õ>ð —‘×$Ñ$ WÔ-ð ×+Ñ+Ñ7Ø×,Ñ,×7Ñ7¸Ô=Ø/3�DÔ,ò- Ù3ñ Køà7;˜DÕ4ûô ×%Ñ%ó 	Ø%(Ô"ð ûäó 	;Ø%(Ô"Ø× Ñ ¤×!9Ñ!9×:Ñ:ûä¤¬x¼¿¹ÐFó 		=ð &)Ô"Ø× Ñ ¤×!;Ñ!;×<Ñ<ûä!ó 	9Ø%(Ô"Ø× Ñ ¤×!7Ñ!7×8Ñ8ûäó 	<Ø%(Ô"Ø× Ñ ¤×!:Ñ!:×;Ñ;ûäó 	;ð �K‰K×ÑÐ4¸tÐÑ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              ƒ  ó¶  ^^^#   • 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R                  [        5      (       a  [        S5      eU(       a  UR                  R                  5       $ [        UR                  5      $ / 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.

)r9   NTFzunexpected opcodez.only compressed outgoing frames use memoryviewz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§^¡^°E·J±JÀÇ	Á	Ó%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  r9   s    €€€ro   r  r    sI   ø€ à×$Ñ$ W§^¡^°E·J±JÀÇ	Á	Ó%JÔKÜ% h´×4Ñ4Ð4Ð4Ø¤ E§J¡J£Ñ/‘Hrr   c                ó<   >• TR                  U R                  5        g rû   )r  rÜ   )r  r  s    €ro   r  r    s   ø€ à×$Ñ$ U§Z¡ZÕ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  r9   s    €€ro   r  r  "  s:   ø€ à×$Ñ$ U§Z¡ZÔ0Ü% h´×4Ñ4Ð4Ð4Ø¤ E§J¡J£Ñ/‘Hrr   zincomplete fragmented messagerµ   rr   )r  r(   ÚreturnÚNone)Úread_data_framer9   rÛ   r   r   r   r  rË   rÜ   rÎ   ÚAssertionErrorr  rÌ   ÚcodecsÚgetincrementaldecoderr   Újoin)rn   r  ÚtextÚdecoder_factoryr  r  r  r9   s        @@@ro   r  Ú$WebSocketCommonProtocol.read_messageé  sœ  úé € ð ×*Ñ*°D·M±MÐ*ÐB×Bˆð ‰=Øà�<‰<œ7Ó"Ø‰DØ�\‰\œYÓ&Ø‰DäÐ 3Ó4Ð4ð �9�9Ü˜%Ÿ*™*¤j×1Ñ1Ü$Ð%UÓVÐVÞ*.�5—:‘:×$Ñ$Ó&ÐE´E¸%¿*¹*Ó4EÐEð %'ˆ	Ø—=‘=ˆÞÜ$×:Ò:¸7ÓCˆOÙ%¨XÑ6ˆGØÑ÷Lñ L÷0ò 0ð Ñ÷1ð 1÷0ð 0ñ 	ˆuŒà—)—)Ø×.Ñ.¸Ð.ÐA×AˆEØ‰}Ü#Ð$CÓDÐDØ�|‰|œwÓ&Ü#Ð$7Ó8Ð8Ù�5ŒMð —)—)‘)ö �×)Ñ)¨)Ó4Ð4 ×)Ñ)¨)Ó4Ð4òA Cñr Bùs)   …G¢G£D;GÅGÅA
GÆ+*GÇG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   OåOäU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   r"  )rn   r9   r  Úpong_timestampÚping_idÚping_idsrò   ró   s           ro   r!  Ú'WebSocketCommonProtocol.read_data_frame4  s¹  é € ð ØŸ/™/¨(Ó3×3ˆEð �|‰|œxÓ'ô #(§+¢+¨e¯j©jÓ"9�”Ø—?‘?Ñ.Ø05�DÔ-ðð ×0Ñ0°·±À%Ç*Á*ÓM×MÐMð à—‘¤Ó(à—:‘:¤§¡Ò+ðØ"Ÿi™i¨¯
©
Ó3×3Ñ3ð ,ð —‘¤Ó(Ø—:‘: §¡Ó+Ü%)×%6Ò%6Ó%8�Nð #�GØ!�HØBFÇ*Á*×BRÑBRÖBTÑ>˜Ñ!> +Ø Ÿ™¨Ô0Ø*×/Ñ/×1Ñ1Ø'×2Ñ2°>Ñ3RÔSØ"§j¡jÕ0Ø+9Ñ+J˜DœLÙ!ñ CUô -Ð-PÓQÐQã#+˜Ø ŸJ™J wÒ/ñ $,øð
 �ò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.

)Úmaskr9   r^   Nz< %s)r(   ÚreadrY   Úreadexactlyr/   r^   rT   r5   )rn   r9   r  s      ro   r*  Ú"WebSocketCommonProtocol.read_frames  sb   é € ô
 —j’jØ�K‰K×#Ñ#Ø—^‘^Ô#ØØ—‘ñ	
÷ 
ˆð �:�:Ø�K‰K×Ñ˜f eÔ,Øˆñ
ù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    rT   r5   Úwriter}   r/   r^   )rn   r  rÛ   rÜ   r  s        ro   Úwrite_frame_syncÚ(WebSocketCommonProtocol.write_frame_sync‚  s[   € Ü�cœ6 &›>¨4Ó0ˆØ�:�:Ø�K‰K×Ñ˜f eÔ,Ø�‰Ø�N‰N× Ñ Ø—‘Ø—‘ð 	ò 	
rr   c              ƒ  ó´   #   •  U R                  5       I S h  v•N   g  N! [         a,    U R                  5         U R                  5       I S h  v•N     g f = f7frû   )r‚   r  rÖ   rÃ   r�   s    ro   ÚdrainÚWebSocketCommonProtocol.drainŒ  sG   é € ð	%à—+‘+“-×ÓøÜó 	%à× Ñ Ô"ð ×"Ñ"Ó$×$Ó$ð	%üs=   ‚A„ —˜ œA� Ÿ-AÁAÁAÁAÁAÁA©Ú_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Ò#ÜØ5°d·j±j·o±oÐ5FÀfÐMóð ð 	×Ñ˜c¨4Ô0Ø�j‰j‹l×Óù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   rT   r5   ra   r`   rb   Ú	serializerÏ   r   )rn   ræ   rÜ   s      ro   rä   Ú)WebSocketCommonProtocol.write_close_frame¢  s’   é € ð �:‰:œŸ™Ò#äŸ™ˆDŒJØ�z�zØ—‘×!Ñ!Ð";Ô<à#ŒOØ�‰Ñ*Ø,0�Ô)Ø‰|Ø—‘Ó(�ð ×"Ñ" 4¬°4ÄÇÁÐ"ÐN×NÑNð $ñ Oùs   ‚B3B>Â5B<Â6B>c              ƒ  óh  #   • U R                   c  g  [        R                  " U R                   5      I Sh  v•N   U R                  (       a  U R                  R                  S5        U R                  5       I Sh  v•N nU R                  be   [        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                  (       a  U R                  R                  S5        Mà   N¼ Nz NP NH N:! , ISh  v•N  (       d  f       NO= 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  )r6   rJ   r   rT   r5   rô   r7   r   rå   rÖ   r   r×   r   rÔ   r  )rn   rò   s     ro   r‰   Ú&WebSocketCommonProtocol.keepalive_ping½  s\  é € ð ×ÑÑ%Øð	FØÜ—m’m D×$6Ñ$6Ó7×7Ð7à—:—:Ø—K‘K×%Ñ%Ð&@ÔAØ$(§I¡I£K×/�à×$Ñ$Ñ0ðÜ#2°4×3DÑ3D×#EÕ#Eð
 #.×-Ð-÷ $F×#Eð  Ÿ:Ÿ:Ø ŸK™K×-Ñ-Ð.IÔJñ! Ù7ñ 0ñ $Fñ
 .÷ $F×#E×#EÐ#Eûô #×/Ñ/ó ØŸ:Ÿ:Ø ŸK™K×-Ñ-Ð.VÔWØ×,Ñ,Ü%×4Ñ4Ø4ôñ ðûô  ó 	Ùäó 	FØ�K‰K×ÑÐ5ÀÐÓEð	FüsÐ   ‚F2’$E= ¶C3·AE= Á:C5Á;E= ÂD Â&C7Â'D Â*C=Â0C9Â1C=Â5D Ã C;Ã0D Ã1E= Ã5E= Ã7D Ã9C=Ã;D Ã=DÄDÄDÄD ÄA E:Å7E= Å8F2Å9E:Å:E= Å=
F/ÆF2Æ	#F/Æ,F2Æ.F/Æ/F2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N¬f = f GNP GN5! [        [        4 a     N²f = 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ˆ   rJ   rÕ   rŠ   Úcancelr/   Úwait_for_connection_lostÚclose_transportrT   r5   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 —:—:Ø—K‘K×%Ñ%Ð&IÔJð �~‰~×+Ñ+×-Ñ-Ø—:—:Ø—K‘K×%Ñ%Ð&EÔFð
Ø—N‘N×,Ñ,Ô.ð ×6Ñ6Ó8×8Õ8Øð ×&Ñ&Ó(×(Ñ(ð —:—:Ø—K‘K×%Ñ%Ð&IÔJð
 ×&Ñ&Ó(×(Ñ(òI 2øÜ×-Ñ-ó Úðúò 9ò4 )øô  ¤Ð.ó Ùðúñ 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~   rT   r5   ræ   rL  Úabortr�   s    ro   rM  Ú'WebSocketCommonProtocol.close_transport"  sÖ   é € ð ×&Ñ&×+Ñ+×-Ñ-°$·.±.×2KÑ2K×2MÑ2MØð �:�:Ø�K‰K×ÑÐ8Ô9Ø�‰×ÑÔà×.Ñ.Ó0×0Õ0ØØ�:�:Ø�K‰K×ÑÐAÔBð �:�:Ø�K‰K×ÑÐ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   r8   rJ   rÊ   rå   r�   s    ro   rL  Ú0WebSocketCommonProtocol.wait_for_connection_lost?  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)a2  
7.1.7. Fail the WebSocket Connection

This requires:

1. Stopping all processing of incoming data, which means canceling
   :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Œ   )rT   r5   rJ  rˆ   rK  r   r°   r]   r!   r…   r   r   r`   ra   r8  r   rD  rA   r†   r‹   rŒ   )rn   r±   r¶   ræ   s       ro   rÖ   Ú'WebSocketCommonProtocol.fail_connectionR  s÷   € ð. �:�:Ø�K‰K×ÑÐAÀ4ÔHô �4Ð-×.Ñ.Ø×#Ñ#×*Ñ*Ô,ð ”9×-Ñ-Ó-°$·*±*ÄÇ
Á
Ò2JÜ˜$Ó'ˆEô Ÿ™ˆDŒJØ�z�zØ—‘×!Ñ!Ð";Ô<ð
 —?‘?Ñ*Ð*Ð*Ø#ŒOà×!Ñ! $¬°%·/±/Ó2CÔDô �tÐ4×5Ñ5Ø)-¯©×)>Ñ)>¸t×?TÑ?TÓ?VÓ)WˆDÕ&ð 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_   € ð �z‰zœUŸ\™\Ò)Ð)Ð)Ø×(Ñ(Ó*ˆà,0¯J©J×,=Ñ,=Ö,?Ñ(ˆ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   rJ   Ú	TransportÚset_write_buffer_limitsr<   r}   rY   Úset_transportr¡   s     ro   Úconnection_madeÚ'WebSocketCommonProtocol.connection_made¤  sC   € ô œ×*Ñ*¨IÓ6ˆ	Ø×)Ñ)¨$×*:Ñ*:Ô;Ø"Œð 	�‰×!Ñ! )Õ,rr   c                ó4  • [         R                  U l        U R                  (       a  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]   rT   r5   r]  rd   rÅ   rY   Úfeed_eofr[  rZ   r[   rt   )rn   r�   rx   s      ro   Úconnection_lostÚ'WebSocketCommonProtocol.connection_lost¹  sÕ   € ô
 —\‘\ˆŒ
Ø�:�:Ø�K‰K×ÑÐ6Ô7à×ÑÔð
 	×#Ñ#×.Ñ.¨tÔ4àà�{‰{Ñ&Ø‘;Ø—K‘K×(Ñ(Õ*à—K‘K×-Ñ-¨cÔ2ð —<—<ØØ×'Ñ'ˆFØ‰~ØØ!%ˆDÔØ�{‰{�}‰}ØØ‰{Ø×!Ñ! $Õ'à×$Ñ$ SÕ)rr   c                ó8   • U R                   (       a   eSU l         g )NT)rZ   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)rZ   r[   rt   rÅ   rw   s     ro   Úresume_writingÚ&WebSocketCommonProtocol.resume_writingä  sQ   € Ø�|�|Ðˆ|ØˆŒà×#Ñ#ˆØÑØ!%ˆDÔØ—;‘;—=‘=Ø×!Ñ! $Õ'ð !ð rr   c                ó:   • U R                   R                  U5        g rû   )rY   Ú	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)rY   rf  r�   s    ro   Úeof_receivedÚ$WebSocketCommonProtocol.eof_receivedñ  s   € ð 	�‰×ÑÕrr   )$r[   rj   rU   rZ   rh   rV   ri   rW   rŒ   r`   rb   ra   r8   rd   rT   r^   rN   rŠ   rl   r@   r5   rA   r:   r9   rg   r6   r7   rk   r;   rY   r]   r_   rm   rˆ   r}   r<   )r5   zLoggerLike | Noner6   úfloat | Noner7   rv  r8   rv  r9   ú
int | Noner:   rw  r;   r  r<   r  r=   ú
str | Noner>   rw  r?   úbool | Noner@   r.   rA   z asyncio.AbstractEventLoop | NonerB   rv  r  r   )r  r   )r  rx  )r  rw  )r  ry  )r  r	   )r  r.   )r  zAsyncIterator[Data])r  r#   )rÇ   z7DataLike | Iterable[DataLike] | AsyncIterable[DataLike]r  r   )r±   r  r¶   r1   r  r   rû   )rÜ   zDataLike | Noner  zAwaitable[float])rr   )rÜ   r$   r  r   )r  r   )r  zData | None)r9   rw  r  zFrame | None)r9   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BytesLike | Noner  r   )r}   zasyncio.BaseTransportr  r   )r�   zException | Noner  r   )rÜ   rÌ   r  r   )8Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__r2   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Ø $ñ#M7ð "ðM7ð $ð	M7ð
 #ðM7ð $ðM7ð ðM7ð ðM7ð ðM7ð ðM7ð ðM7ð ðM7ð ðM7ð ðM7ð  /ð!M7ð" ð#M7ð$ 
õ%M7ô`	ô#ô Tð& óó ðð
 óó ðð
 óó ðð ó8ó ð8ð& ó8ó ð8ð& óOó ðOð ó*ó ð*ð ó(ó ð(ð" ó*ó ð*ô"ô"Lð\ZIàHðZIð 
ôZIð| ×,Ñ,Øð59àð59ð ð59ð 
õ	59ôn:ö9+öv4ô6ô. IôDD;ôLI5ôV=ô~ô
ô	%ð INÏ
É
ñ	Øð	Ø!$ð	Ø,5ð	ØBEð	à	õ	ð 6:ðOØðOØ"2ðOà	õOô6-Fô^4)ôl.ô:2ð* ×.Ñ.Øð<Xàð<Xð ð<Xð 
õ	<Xô|!ô(-ô*%*ôNô(ô$÷rr   c                ó.  • [        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  [1        SU5      egg! [&         a|  nU(       a(  [        S	5      nX‡l        WR                  U5         SnAMÜ  UR                   R#                  S
[*        R,                  " U5      S   R/                  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Ë   r1   rÌ   rÍ   rÎ   rÐ   ÚsysÚversion_infoÚ
ValueErrorr*   r]   r!   r…   rj   r¿   r  r5   Úwarningr8  rÔ   rü   Ú	tracebackÚformat_exception_onlyÚstripÚExceptionGroup)	Ú
websocketsrÇ   Úraise_exceptionsÚ
exceptionsrÛ   rÜ   rE   r|   Úwrite_exceptions	            ro   Ú	broadcastr“    s^  € ôd �g¤¤U¬I´zÐB×CÑCÜÐ8Ó9Ð9æÜ×Ñ˜B˜QÐ 'Ó)ÜÐMÓNÐNØˆ
ä Ó(�L€Fãˆ	Ø�?‰?¤%§*¡*Ò,Ùà×/Ñ/Ñ;ÞÜ(Ð)GÓH�	Ø×!Ñ! )Õ,à× Ñ ×(Ñ(ØEôñ ð	Ø×&Ñ& t¨VÖ:ñ  ö6 žJÜÐ0°*Ó=Ð=ð 'Ðøô ó 		ÞÜ(Ð)BÓC�	Ø&5Ô#Ø×!Ñ! )×,Ò,à× Ñ ×(Ñ(ØDÜ×3Ò3°OÓDÀQÑG×MÑMÓO÷ó ûð		ús   ÃDÄ
FÄ)FÅAFÆFzwebsockets.legacy.server)F)r�  z!Iterable[WebSocketCommonProtocol]rÇ   r$   r�  r.   r  r   )AÚ
__future__r   rJ   r#  re   rO   rî   r
  rì   r‡  rð   r‹  rL   rG   Ú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$   r%   r&   Úframingr(   r)   r*   Ú__all__ÚProtocolr+   r“  r{  rƒ  rr   ro   Ú<module>rž     sÊ   ðÝ "ã Û Û Û Û Û 
Û Û 
Û Û Û Û ß VÕ Vß -Ó -å 3Ý $÷÷ õ #÷÷ ÷ õ ß GÕ Gß 6Ñ 6ð %Ð
%€ôH˜g×.Ñ.ô Hðh. #ðX>Ø1ðX>àðX>ð ðX>ð 
õ	X>ðx 2€	Õ rr   