Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
websocket.cpython-313.pyc686 linesDownload Raw Back to __pycache__
1�

2��j�����SrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK3r4SSKJr SSK
r
SSKrSSKJrJr SSKJrJrJr SSK5JrJrJr SSKJr SSKJrJr SS	KJrJ r  SS6K!J"r" SSK7J#r# SSK$J%r% SS
K&J'r' SSK(J)r) SSK*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5 SSK6J7r7 \+(a'SSK8J9r9 "SS\95r:"SS\95r;"SS\95r<Sr=\R|"\R~5r@"SS\A5rB"SS\B5rC"SS\A5rD"SS 5rE"S!S"\8R�R�5rHS#\-S$\-S%S4S&jrI"S'S(\R�5rK"S)S*5rL"S+S,5rM"S-S.\K5rN"S/S0\#R�5rPSSSSSS\=SS4	S1\0\Q\R�4S2\.\3S3/S4S4\.\SS5\.\3\0S\Q\T4/S4S6\.\/\Q\-4S7\.\SS8\.\SS9\US:\.\1\QS;\.\"S%S<4S=jjrVg)>a�Implementation of the WebSocket protocol.9 10`WebSockets <http://dev.w3.org/html5/websockets/>`_ allow for bidirectional11communication between the browser and server. WebSockets are supported in the12current versions of all major browsers.13 14This module implements the final version of the WebSocket protocol as15defined in `RFC 6455 <http://tools.ietf.org/html/rfc6455>`_.16 17.. versionchanged:: 4.018   Removed support for the draft 76 protocol version.19�N)�urlparse)�Future�"future_set_result_unless_cancelled)�utf8�20native_str�21to_unicode)�gen�22httpclient�httputil)�IOLoop)�StreamClosedError�IOStream)�gen_log�app_log)�Resolver)�simple_httpclient)�Queue)�	TCPClient)�_websocket_mask)�
TYPE_CHECKING�cast�Any�Optional�Dict�Union�List�	Awaitable�Callable�Tuple�Type)�
TracebackType)�Protocolc�8�\rSrSrS\S\4SjrS\S\4SjrSrg)	�_Compressor�<�data�returnc��g�N���selfr&s  �WD:\code\apps\devtools\python\user_packages\Python313\site-packages\tornado/websocket.py�compress�_Compressor.compress=�����modec��gr)r*)r,r2s  r-�flush�_Compressor.flush@r0r1r*N)	�__name__�23__module__�__qualname__�__firstlineno__�bytesr.�intr4�__static_attributes__r*r1r-r$r$<s(��	��	�5�	�	�c�	�e�	r1r$c�.�\rSrSrSrS\S\S\4SjrSrg)	�
_Decompressor�Cr1r&�24max_lengthr'c��gr)r*)r,r&r@s   r-�25decompress�_Decompressor.decompressFr0r1r*N)	r6r7r8r9�unconsumed_tailr:r;rBr<r*r1r-r>r>Cs!����	�5�	�c�	�e�	r1r>c��\rSrSrSS\\S\\SS4SjjrS\\\	4S\S4S	jr26S27\	SS4SjrS28\	SS4SjrS
\\
\S\\S\\SS4SjrSrg)�_WebSocketDelegate�IN�29close_code�close_reasonr'c��gr)r*�r,rHrIs   r-�on_ws_connection_close�)_WebSocketDelegate.on_ws_connection_closeMs��
r1�messagezAwaitable[None]c��gr)r*�r,rNs  r-�30on_message�_WebSocketDelegate.on_messageRr0r1r&c��gr)r*r+s  r-�on_ping�_WebSocketDelegate.on_pingUr0r1c��gr)r*r+s  r-�on_pong�_WebSocketDelegate.on_pongXr0r1�typ�value�tbc��gr)r*�r,rYrZr[s    r-�
log_exception� _WebSocketDelegate.log_exception[s��
r1r*�NN)r6r7r8r9rr;�strrLrr:rQrTrWr �
BaseExceptionr!r^r<r*r1r-rFrFIs���31SW�	�&�s�m�	�BJ�3�-�	�
�	�32	�e�C��J�&7�	�H�EV�<W�	�	��	�$�	�	��	�$�	�	��$�}�-�.�	��M�*�	���'�		�33�	r1rFi�c��\rSrSrSrg)�WebSocketError�jr*N�r6r7r8r9r<r*r1r-rdrdj���r1rdc��\rSrSrSrSrg)�WebSocketClosedError�nzDRaised by operations on a closed connection.34 35.. versionadded:: 3.236r*N)r6r7r8r9�__doc__r<r*r1r-ririns���37	r1ric��\rSrSrSrg)�_DecompressTooLargeError�wr*Nrfr*r1r-rmrmwrgr1rmc�Z�\rSrSrSS\S4S\\S\\S\S\\\	\384SS439SjjrS	rg)40�_WebSocketParams�{N�
ping_interval�ping_timeout�max_message_size�compression_optionsr'c�4�XlX lX0lX@lgr)�rrrsrtru)r,rrrsrtrus     r-�__init__�_WebSocketParams.__init__|s��+��(�� 0��#6� r1)rurtrrrs)
r6r7r8r9�_default_max_message_sizer�floatr;rrarrxr<r*r1r-rprp{s_��*.�(,� 9�8<�417����427��u�o�437��	447�45&�d�3��8�n�5�467�47�
487�497r1rpc�^�\rSrSrSrS\RRS\RS\50SS4U4SjjrS	\51S\52SS4S53jr\
S\\4Sj5r\
S\\4Sj5r\
S\4S
j5rS-S\\\\\\5444S\SS4SjjrS\\S\\4Sjr\
S\\4Sj5rS\\\\5544SjrS	\S\S\\S4SjrS\\\4S\\S4Sjr S.S\\\4SS4Sjjr!S\SS4Sjr"S\SS4Sjr#S/Sjr$S0S\\S\\SS4Sjjr%S \S\4S!jr&S"\SS4S#jr'S/S$jr(S0S%\\S&\\SS4S'jjr)S/U4S(jjr*S\S)4S*jr+S\,4S+jr-S,r.U=r/$)1�WebSocketHandler�aZSubclass this class to create a basic WebSocket handler.56 57Override `on_message` to handle incoming messages, and use58`write_message` to send messages to the client. You can also59override `open` and `on_close` to handle opened and closed60connections.61 62Custom upgrade response headers can be sent by overriding63`~tornado.web.RequestHandler.set_default_headers` or64`~tornado.web.RequestHandler.prepare`.65 66See http://dev.w3.org/html5/websockets/ for details on the67JavaScript interface.  The protocol is specified at68http://tools.ietf.org/html/rfc6455.69 70Here is an example WebSocket handler that echos back all received messages71back to the client:72 73.. testcode::74 75  class EchoWebSocket(tornado.websocket.WebSocketHandler):76      def open(self):77          print("WebSocket opened")78 79      def on_message(self, message):80          self.write_message(u"You said: " + message)81 82      def on_close(self):83          print("WebSocket closed")84 85WebSockets are not standard HTTP connections. The "handshake" is86HTTP, but after the handshake, the protocol is87message-based. Consequently, most of the Tornado HTTP facilities88are not available in handlers of this type. The only communication89methods available to you are `write_message()`, `ping()`, and90`close()`. Likewise, your request handler class should implement91`open()` method rather than ``get()`` or ``post()``.92 93If you map the handler above to ``/websocket`` in your application, you can94invoke it in JavaScript with::95 96  var ws = new WebSocket("ws://localhost:8888/websocket");97  ws.onopen = function() {98     ws.send("Hello, world");99  };100  ws.onmessage = function (evt) {101     alert(evt.data);102  };103 104This script pops up an alert box that says "You said: Hello, world".105 106Web browsers allow any site to open a websocket connection to any other,107instead of using the same-origin policy that governs other network108access from JavaScript.  This can be surprising and is a potential109security hole, so since Tornado 4.0 `WebSocketHandler` requires110applications that wish to receive cross-origin websockets to opt in111by overriding the `~WebSocketHandler.check_origin` method (see that112method's docs for details).  Failure to do so is the most likely113cause of 403 errors when making a websocket connection.114 115When using a secure websocket connection (``wss://``) with a self-signed116certificate, the connection from a browser may fail because it wants117to show the "accept this certificate" dialog but has nowhere to show it.118You must first visit a regular HTML page using the same certificate119to accept it before the websocket connection will succeed.120 121If the application setting ``websocket_ping_interval`` has a non-zero122value, a ping will be sent periodically, and the connection will be123closed if a response is not received before the ``websocket_ping_timeout``.124Both settings are in seconds; floating point values are allowed.125The default timeout is equal to the interval.126 127Messages larger than the ``websocket_max_message_size`` application setting128(default 10MiB) will not be accepted.129 130.. versionchanged:: 4.5131   Added ``websocket_ping_interval``, ``websocket_ping_timeout``, and132   ``websocket_max_message_size``.133�application�request�kwargsr'Nc�`>�[TU]"X40UD6 SUlSUlSUlSUlg�NF)�superrx�
ws_connectionrHrI�_on_close_called)r,rr�r��	__class__s    �r-rx�WebSocketHandler.__init__�s6���	����8��8�!������ ��� %��r1�argsc��d# �XlX lURRR	SS5R5S:wa;UR
S5 SnURU5 [R"U5 gURRn[SUR	SS5RS55nS	U;a;UR
S5 S134nURU5 [R"U5 gSURR;a&URRR	S5nO&URRR	SS5nUbQURU5(d;UR
S
5 SnURU5 [R"U5 gUR5UlUR(a$URRU5IShv�N gUR
SS5 UR!SS5 gN*7f)N�Upgrade��	websocket�z"Can "Upgrade" only to "WebSocket".c�>�UR5R5$r))�strip�lower)�ss r-�<lambda>�&WebSocketHandler.get.<locals>.<lambda>�s��a�g�g�i�o�o�'r1�135Connection�,�upgradez"Connection" must be "Upgrade".�OriginzSec-Websocket-Origini�z#Cross origin websockets not allowedi�zUpgrade Required�Sec-WebSocket-Versionz7, 8, 13)�	open_args�open_kwargsr��headers�getr��136set_status�finishr�debug�map�split�check_origin�get_websocket_protocolr��accept_connection�137set_header)r,r�r��log_msgr��138connection�origins       r-r��WebSocketHandler.get�s������!���<�<���#�#�I�r�2�8�8�:�k�I��O�O�C� �:�G��K�K�� ��M�M�'�"��139�,�,�&�&���'����\�2�)F�)L�)L�S�)Q�140�141��J�&��O�O�C� �7�G��K�K�� ��M�M�'�"���t�|�|�+�+�+��\�\�)�)�-�-�h�7�F��\�\�)�)�-�-�.D�d�K�F�142��d�&7�&7��&?�&?��O�O�C� �;�G��K�K�� ��M�M�'�"��!�8�8�:�������$�$�6�6�t�<�<�<��O�O�C�!3�4��O�O�3�Z�@�
=�s�HH0�H.�+H0c�:�URRSS5$)aNThe interval for sending websocket pings.143 144If this is non-zero, the websocket will send a ping every145ping_interval seconds.146The client will respond with a "pong". The connection can be configured147to timeout on late pong delivery using ``websocket_ping_timeout``.148 149Set ``websocket_ping_interval = 0`` to disable pings.150 151Default: ``0``152�websocket_ping_intervalN��settingsr��r,s r-rr�WebSocketHandler.ping_intervals���}�}� � �!:�D�A�Ar1c�:�URRSS5$)a�Timeout if no pong is received in this many seconds.153 154To be used in combination with ``websocket_ping_interval > 0``.155If a ping response (a "pong") is not received within156``websocket_ping_timeout`` seconds, then the websocket connection157will be closed.158 159This can help to clean up clients which have disconnected without160cleanly closing the websocket connection.161 162Note, the ping timeout cannot be longer than the ping interval.163 164Set ``websocket_ping_timeout = 0`` to disable the ping timeout.165 166Default: equal to the ``ping_interval``.167 168.. versionchanged:: 6.5.0169   Default changed from the max of 3 pings or 30 seconds.170   The ping timeout can no longer be configured longer than the171   ping interval.172�websocket_ping_timeoutNr�r�s r-rs�WebSocketHandler.ping_timeout)s��.�}�}� � �!9�4�@�@r1c�B�URRS[5$)z�Maximum allowed message size.173 174If the remote peer sends a message larger than this, the connection175will be closed.176 177Default is 10MiB.178�websocket_max_message_size)r�r�rzr�s r-rt�!WebSocketHandler.max_message_sizeBs!���}�}� � �(�*C�179�	180r1rN�binary�Future[None]c��URbURR5(a181[5e[U[5(a[182RRU5nURRXS9$)a�Sends the given message to the client of this Web Socket.183 184The message may be either a string or a dict (which will be185encoded as json).  If the ``binary`` argument is false, the186message will be sent as utf8; in binary mode any byte string187is allowed.188 189If the connection is already closed, raises `WebSocketClosedError`.190Returns a `.Future` which can be used for flow control.191 192.. versionchanged:: 3.2193   `WebSocketClosedError` was added (previously a closed connection194   would raise an `AttributeError`)195 196.. versionchanged:: 4.3197   Returns a `.Future` which can be used for flow control.198 199.. versionchanged:: 5.0200   Consistently raises `WebSocketClosedError`. Previously could201   sometimes raise `.StreamClosedError`.202�r�)	r��203is_closingri�204isinstance�dict�tornado�escape�json_encode�
write_message�r,rNr�s   r-r��WebSocketHandler.write_messageOsh��0���%��);�);�)F�)F�)H�)H�&�(�(��g�t�$�$��n�n�0�0��9�G��!�!�/�/��/�G�Gr1�subprotocolsc��g)a(Override to implement subprotocol negotiation.205 206``subprotocols`` is a list of strings identifying the207subprotocols proposed by the client.  This method may be208overridden to return one of those strings to select it, or209``None`` to not select a subprotocol.210 211Failure to select a subprotocol does not automatically abort212the connection, although clients may close the connection if213none of their proposed subprotocols was selected.214 215The list may be empty, in which case this method must return216None. This method is always called exactly once even if no217subprotocols were proposed so that the handler can be advised218of this fact.219 220.. versionchanged:: 5.1221 222   Previously, this method was called with a list containing223   an empty string instead of an empty list if no subprotocols224   were proposed by the client.225Nr*)r,r�s  r-�select_subprotocol�#WebSocketHandler.select_subprotocolms��.r1c�L�URceURR$)zIThe subprotocol returned by `select_subprotocol`.226 227.. versionadded:: 5.1228)r��selected_subprotocolr�s r-r��%WebSocketHandler.selected_subprotocol�s(���!�!�-�-�-��!�!�6�6�6r1c��g)a}Override to return compression options for the connection.229 230If this method returns None (the default), compression will231be disabled.  If it returns a dict (even an empty one), it232will be enabled.  The contents of the dict may be used to233control the following compression options:234 235``compression_level`` specifies the compression level.236 237``mem_level`` specifies the amount of memory used for the internal compression state.238 239 These parameters are documented in detail here:240 https://docs.python.org/3.13/library/zlib.html#zlib.compressobj241 242.. versionadded:: 4.1243 244.. versionchanged:: 4.5245 246   Added ``compression_level`` and ``mem_level``.247Nr*r�s r-�get_compression_options�(WebSocketHandler.get_compression_options�s��,r1c��g)aPInvoked when a new WebSocket is opened.248 249The arguments to `open` are extracted from the `tornado.web.URLSpec`250regular expression, just like the arguments to251`tornado.web.RequestHandler.get`.252 253`open` may be a coroutine. `on_message` will not be called until254`open` has returned.255 256.. versionchanged:: 5.1257 258   ``open`` may be a coroutine.259Nr*)r,r�r�s   r-�open�WebSocketHandler.open�s��	
r1c��[e)z�Handle incoming messages on the WebSocket260 261This method must be overridden.262 263.. versionchanged:: 4.5264 265   ``on_message`` can be a coroutine.266��NotImplementedErrorrPs  r-rQ�WebSocketHandler.on_message�s267��"�!r1r&c��[U5nURbURR5(a268[5eURR	U5 g)a�Send ping frame to the remote end.269 270The data argument allows a small amount of data (up to 125271bytes) to be sent as a part of the ping message. Note that not272all websocket implementations expose this data to273applications.274 275Consider using the ``websocket_ping_interval`` application276setting instead of sending pings manually.277 278.. versionchanged:: 5.1279 280   The data argument is now optional.281 282N)rr�r�ri�283write_pingr+s  r-�ping�WebSocketHandler.ping�sJ�� �D�z�����%��);�);�)F�)F�)H�)H�&�(�(����%�%�d�+r1c��g)z6Invoked when the response to a ping frame is received.Nr*r+s  r-rW�WebSocketHandler.on_pong����r1c��g)z*Invoked when the a ping frame is received.Nr*r+s  r-rT�WebSocketHandler.on_ping�r�r1c��g)a0Invoked when the WebSocket is closed.284 285If the connection was closed cleanly and a status code or reason286phrase was supplied, these values will be available as the attributes287``self.close_code`` and ``self.close_reason``.288 289.. versionchanged:: 4.0290 291   Added ``close_code`` and ``close_reason`` attributes.292Nr*r�s r-�on_close�WebSocketHandler.on_close�s��	
r1�code�reasonc�l�UR(a#URRX5 SUlgg)a�Closes this Web Socket.293 294Once the close handshake is successful the socket will be closed.295 296``code`` may be a numeric status code, taken from the values297defined in `RFC 6455 section 7.4.1298<https://tools.ietf.org/html/rfc6455#section-7.4.1>`_.299``reason`` may be a textual message about why the connection is300closing.  These values are made available to the client, but are301not otherwise interpreted by the websocket protocol.302 303.. versionchanged:: 4.0304 305   Added the ``code`` and ``reason`` arguments.306N)r��close�r,r�r�s   r-r��WebSocketHandler.close�s.�� ������$�$�T�2�!%�D��r1r�c��[U5nURnUR5nURRRS5nX:H$)a�Override to enable support for allowing alternate origins.307 308The ``origin`` argument is the value of the ``Origin`` HTTP309header, the url responsible for initiating this request.  This310method is not called for clients that do not send this header;311such requests are always allowed (because all browsers that312implement WebSockets support this header, and non-browser313clients do not have the same cross-site security concerns).314 315Should return ``True`` to accept the request or ``False`` to316reject it. By default, rejects all requests with an origin on317a host other than this one.318 319This is a security protection against cross site scripting attacks on320browsers, since WebSockets are allowed to bypass the usual same-origin321policies and don't use CORS headers.322 323.. warning::324 325   This is an important security measure; don't disable it326   without understanding the security implications. In327   particular, if your authentication is cookie-based, you328   must either restrict the origins allowed by329   ``check_origin()`` or implement your own XSRF-like330   protection for websocket connections. See `these331   <https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html>`_332   `articles333   <https://devcenter.heroku.com/articles/websocket-security>`_334   for more.335 336To accept all cross-origin traffic (which was the default prior to337Tornado 4.0), simply override this method to always return ``True``::338 339    def check_origin(self, origin):340        return True341 342To allow connections from any subdomain of your site, you might343do something like::344 345    def check_origin(self, origin):346        parsed_origin = urllib.parse.urlparse(origin)347        return parsed_origin.netloc.endswith(".mydomain.com")348 349.. versionadded:: 4.0350 351�Host)r�netlocr�r�r�r�)r,r��
parsed_origin�hosts    r-r��WebSocketHandler.check_originsI��^!��(�
��%�%��������|�|�#�#�'�'��/���~�r1rZc�X�URceURRU5 g)a�Set the no-delay flag for this stream.352 353By default, small messages may be delayed and/or combined to minimize354the number of packets sent.  This can sometimes cause 200-500ms delays355due to the interaction between Nagle's algorithm and TCP delayed356ACKs.  To reduce this delay (at the expense of possibly increasing357bandwidth usage), call ``self.set_nodelay(True)`` once the websocket358connection is established.359 360See `.BaseIOStream.set_nodelay` for additional details.361 362.. versionadded:: 3.1363N)r��set_nodelay�r,rZs  r-r��WebSocketHandler.set_nodelay8s*���!�!�-�-�-����&�&�u�-r1c���UR(a!URR5 SUlUR(d(SUlUR5 UR	5 gg)NT)r��on_connection_closer�r��
_break_cyclesr�s r-r��$WebSocketHandler.on_connection_closeIsP��������2�2�4�!%�D���$�$�$(�D�!��M�M�O���� �%r1rHrIc�<�XlX lUR5 gr)�rHrIr�rKs   r-rL�'WebSocketHandler.on_ws_connection_closeR���%��(��� � �"r1c�n>�UR5S:wdUR(a[TU]
5 gg�N�e)�364get_statusr�r�r��r,r�s �r-r��WebSocketHandler._break_cyclesYs,����?�?���#�t�'<�'<��G�!�#�(=r1�WebSocketProtocolc���URRRS5nUS;aE[URUR365URUR5S9n[USU5$g)Nr�)�7�8�13rwF)	r�r�r�rprrrsrtr��WebSocketProtocol13)r,�websocket_version�paramss   r-r��'WebSocketHandler.get_websocket_protocolbsl�� �L�L�0�0�4�4�5L�M��� 0�0�%�"�0�0�!�.�.�!%�!6�!6�$(�$@�$@�$B�	�F�'�t�U�F�;�;�r1c�T�SHn[X[5 M UR5$)N)�write�redirectr��366set_cookier�r4r�)�setattr�#_raise_not_supported_for_websockets�detach)r,�methods  r-�_detach_stream�WebSocketHandler._detach_streamns)��367�F�
�D�"E�F�368��{�{�}�r1)r�rHrIr�r�r��F�r1�r'Nr`)0r6r7r8r9rkr��web�Applicationr�HTTPServerRequestrrxr��propertyrr{rrrsr;rtrr:rar�boolr�rr�r�r�rr�rQr�rWrTr�r�r�r�r�rLr�r�rrr<�
__classcell__�r�s@r-r}r}�s����N�`369&��[�[�,�,�370&��+�+�371&��	372&�373374�375&�2A�s�2A�c�2A�d�2A�h�B�x���B��B��A�h�u�o�A��A�0�376377�#�378379��380381�JO�H��U�C��c�3�h��7�8�H�BF�H�	�H�<�t�C�y��X�c�]��2�7�h�s�m�7��7���$�s�C�x�.�)A��0
�#�
��
��)�D�/�1J�
� 	"�%��U�382�"3�	"���4��8Q�	"�,��s�E�z�*�,�T�,�*
�E�
�d�
�
�E�
�d�
�
�&�(�3�-�&���
�&�QU�&�(6�3�6�4�6�p.��.�$�.�"!�OS�#�"�3�-�#�>F�s�m�#�	
�#�$�383��1D�(E�384����r1r}r�r�r'c��[S5e)Nz$Method not supported for Web Sockets)�RuntimeError)r�r�s  r-r
r
}s��385�=�386>�>r1c	�~�\rSrSrSrS"SjrS\S\S	\SS3874SjrS#Sjr	S#S
jr388\RS$S\
\S\
\SS4Sjj5r\RS\4Sj5r\RS\SS4Sj5r\RS%S\\\\\\44S\SS4Sjj5r\\RS\
\4Sj55r\RS\SS4Sj5r\RS\\\4S\R:SS4Sj5r\RS#Sj5r\RS#Sj5r \RS\SS4S j5r!S!r"g)&r�i�z+Base class for WebSocket protocol versions.�handlerr'Nc�:�XlSUlSUlSUlgr�)r�stream�client_terminated�server_terminated�r,rs  r-rx�WebSocketProtocol.__init__�s�������!&���!&��r1�callbackr�r�zOptional[Future[Any]]c�N�U"U0UD6nUbL[R"U5nURceURRR	US5 U$![389a? URR"[R"56 UR5 gf=f)z�Runs the given callback with exception handling.390 391If the callback is a coroutine, returns its Future. On error, aborts the392websocket connection and returns None.393Nc�"�UR5$r))�result)�fs r-r��1WebSocketProtocol._run_callback.<locals>.<lambda>�s394�����r1)r	�convert_yieldedr!�io_loop�395add_future�	Exceptionrr^�sys�exc_info�_abort)r,r&r�r�r)s     r-�
_run_callback�WebSocketProtocol._run_callback�s���	��t�.�v�.�F��!��,�,�V�4���{�{�.�.�.����#�#�.�.�v�7K�L��M���	��L�L�&�&�����7��K�K�M��	�s�A�AB$�#B$c�$�UR5 gr))r2r�s r-r��%WebSocketProtocol.on_connection_close�s�����
r1c��SUlSUlURbURR5 UR5 g)z?Instantly aborts the WebSocket connection by closing the socketTN)r"r#r!r�r�s r-r2�WebSocketProtocol._abort�s5��!%���!%����;�;�"��K�K�����396�397�r1r�r�c��[5er)r�r�s   r-r��WebSocketProtocol.close����!�#�#r1c��[5er)r�r�s r-r��WebSocketProtocol.is_closing�r;r1c��# �[5e7fr)r�r$s  r-r��#WebSocketProtocol.accept_connection�����!�#�#���
rNr�r�c��[5er)r�r�s   r-r��WebSocketProtocol.write_message��
��"�#�#r1c��[5er)r�r�s r-r��&WebSocketProtocol.selected_subprotocol�s
��"�#�#r1r&c��[5er)r�r+s  r-r��WebSocketProtocol.write_ping�r;r1�keyr�c��[5er)r�)r,rIr�s   r-�_process_server_headers�)WebSocketProtocol._process_server_headers�rDr1c��[5er)r�r�s r-�
start_pinging�WebSocketProtocol.start_pinging�r;r1c��# �[5e7fr)r�r�s r-�_receive_frame_loop�%WebSocketProtocol._receive_frame_loop�r@rA�xc��[5er)r��r,rSs  r-r��WebSocketProtocol.set_nodelay�r;r1)r"rr#r!)rrFr'Nrr`r)#r6r7r8r9rkrxrrr3r�r2�abc�abstractmethodrr;rar�rr�r}r�rr:rr�rr�r�r�HTTPHeadersrKrNrQr�r<r*r1r-r�r��s���5�'�� ��),��8;��	 ��*��	���$�(�3�-�$���
�$�QU�$��$�	���$�D�$��$�	���$�/?�$�D�$��$�	���IN�$��S�%��c�3�h��7�8�$�BF�$�	�$��$�398����$�h�s�m�$���$�	���$�u�$��$��$�	���$���e��$�$�/7�/C�/C�$�	
�$��$�399	���$��$�	���$��$�	���$�T�$�d�$��$r1r�c400�f�\rSrSrSS\S\\S\\\\	4SS4Sjjr401S
SjrS	\S\4S402jr
Srg)�_PerMessageDeflateCompressori�N�403persistent�	max_wbitsrur'c��Uc[RnSUs=::a[R::dO [SU[R5eX lUbSU;a*[R404RRUlO405USUlUbSU;aSUl	O406USUl	U(aUR5UlgSUlg)N��.Invalid max_wbits value %r; allowed range 8-%d�compression_level�	mem_level)�zlib�	MAX_WBITS�407ValueError�408_max_wbitsr�r�GZipContentEncoding�409GZIP_LEVEL�_compression_level�410_mem_level�_create_compressor�_compressor)r,r\r]rus    r-rx�%_PerMessageDeflateCompressor.__init__�s��������I��Y�0�$�.�.�0��@������
�411$��
 �'�"�*=�=�&-�k�k�&E�&E�&P�&P�D�#�&9�:M�&N�D�#��&�+�=P�*P��D�O�1�+�>�D�O��#�6�6�8�D��#�D�r1c��[R"UR[RUR*UR4125$r))rc�compressobjri�DEFLATEDrfrjr�s r-rk�/_PerMessageDeflateCompressor._create_compressors3������#�#�T�]�]�T�_�_�4D�d�o�o�413�	414r1r&c���UR=(d UR5nURU5UR[R4155-nUR
S5(deUSS$)N��������)rlrkr.r4rc�Z_SYNC_FLUSH�endswith)r,r&�416compressors   r-r.�%_PerMessageDeflateCompressor.compresssc���%�%�B��)@�)@�)B�417��"�"�4�(�:�+;�+;�D�<M�<M�+N�N���}�}�0�1�1�1�1��C�R�y�r1)rirlrfrjr))r'r$)r6r7r8r9rrr;rrarrxrkr:r.r<r*r1r-r[r[�s\��4189=�	!$��!$��C�=�!$�&�d�3��8�n�5�	!$�419420�!$�F421�422�U��u�r1r[c�j�\rSrSrS
S\S\\S\S\\\\	4SS4423Sjjr424SS	jrS425\S\4Sjr
Srg)�_PerMessageDeflateDecompressoriNr\r]rtrur'c���X0lUc[RnSUs=::a[R::dO [SU[R5eX lU(aUR5UlgSUlg)Nr_r`)�_max_message_sizercrdrerf�_create_decompressor�
_decompressor)r,r\r]rtrus     r-rx�'_PerMessageDeflateDecompressor.__init__
sl��"2�������I��Y�0�$�.�.�0��@������
�426$����)�)�+�
��"&�D�r1c�D�[R"UR*5$r))rc�
decompressobjrfr�s r-r}�3_PerMessageDeflateDecompressor._create_decompressor%s���!�!�4�?�?�"2�3�3r1r&c���UR=(d UR5nURUS-UR5nUR(a427[5eU$)Nrs)r~r}rBr|rDrm)r,r&�decompressorr)s    r-rB�)_PerMessageDeflateDecompressor.decompress(sU���)�)�H�T�-F�-F�-H���(�(��&�&��(>�(>�428���'�'�*�,�,��
r1)r~r|rfr))r'r>)r6r7r8r9rrr;rrarrxr}r:rBr<r*r1r-rzrzse��9=�&��&��C�=�&��	&�429&�d�3��8�n�5�&�430�
&�04��u���r1rzc�`�\rSrSrSrSrSrSrSr\\-\-r	Sr431SrS	S432S\S\
S
S4Sjr\S
\\4Sj5r\R&S\\S
S4Sj5rS	\S
S4SjrS	\S
S4Sjr\S\\\4S
\4Sj5rS	\S
\4SjrS	\S
S4SjrS\R<S
\\ \\!\\444Sjr"S\\\4S\R<S
S4Sjr#S?S\S\!\\$4S\\!\\$4S
\!\\$44Sjjr%S?S\S\!\\$4S\\!\\$4S
S4Sjjr&S@S \S!\'S"\S#\'S
S$4433S%jjr(SAS&\\\\!\\$44S'\S
S$4S(jjr)S"\S
S4S)jr*SBS*jr+S+\'S
\4S,jr,SBS-jr-S!\'S"\S
S.4S/jr.SCS0\\'S1\\S
S4S2jjr/S
\4S3jr0S4\S
S4S5jr1\S
\24S6j5r3\S
\24S7j5r4SBS8jr5\S9\2S:\2S;\2S
\24S<j5r6SBS=jr7S>r8g)Dri2z�Implementation of the WebSocket protocol from RFC 6455.434 435This class supports versions 7 and 8 of the protocol in addition to the436final version 13.437��@� ��NrrF�
mask_outgoingrr'c�r�[RX5 X lX0lSUlSUlSUlSUlSUlSUl	SUl438SUlURUl
SUlSUlSUlSUlSUlSUlSUlSUlSUlSUlSUlg)NFr)r�rxr�r�_final_frame�
_frame_opcode�
_masked_frame�_frame_mask�
_frame_length�_fragmented_message_buffer�_fragmented_message_opcode�_waitingru�_compression_optionsr~rl�_frame_compressed�_message_bytes_in�_message_bytes_out�_wire_bytes_in�_wire_bytes_out�_received_pongrHrI�_ping_coroutine)r,rr�rs    r-rx�WebSocketProtocol13.__init__Cs���	�"�"�4�1�*����!���!���!������!���*.��'�*.��'���
�$*�$>�$>��!�!������!%���"#���"#��� ��� ���#������ ���#��r1c��UR$r)��_selected_subprotocolr�s r-r��(WebSocketProtocol13.selected_subprotocolgs���)�)�)r1rZc��Xlgr)r�r�s  r-r�r�ks��%*�"r1c��# �URU5 UR
U5IShv�N g![a= URS5 SnURU5 [R439"U5 gf=fNO![Ra UR5 g[a( [R440"SSS9 UR5 gf=f7f)Nr��!Missing/Invalid WebSocket headersz$Malformed WebSocket request receivedT�r1)441�_handle_websocket_headersrer�r�rr��_accept_connection�asyncio�CancelledErrorr2)r,rr�s   r-r��%WebSocketProtocol13.accept_connectionos����	��*�*�7�3�	��)�)�'�2�2�2���	����s�#�9�G��N�N�7�#��M�M�'�"��	��
3���%�%�	��K�K�M���	��M�M�@�4�P��K�K�M��	�s_�C�0�A<�A:�A<�C�AA7�4C�6A7�7C�:A<�<$C� C�".C�C�C�Cc�\^�Sn[[U4SjU55(d[S5eg)zzVerifies all invariant- and required headers442 443If a header is missing or have an incorrect value ValueError will be444raised445)r��Sec-Websocket-KeyzSec-Websocket-Versionc�N>�TRRRU5$r))r�r�r�)r*rs �r-r��?WebSocketProtocol13._handle_websocket_headers.<locals>.<lambda>�s������!8�!8�!<�!<�Q�!?r1r�N)�allr�re)r,r�fieldss ` r-r��-WebSocketProtocol13._handle_websocket_headers�s0���H���3�?��H�I�I��@�A�A�Jr1rIc���[R"5nUR[U55 URS5 [	[446R"UR555$)z_Computes the value for the Sec-WebSocket-Accept header,447given the value for Sec-WebSocket-Key.448s$258EAFA5-E914-47DA-95CA-C5AB0DC85B11)�hashlib�sha1�updaterr�base64�	b64encode�digest)rIr�s  r-�compute_accept_value�(WebSocketProtocol13.compute_accept_value�sH��449�|�|�~�����D��I�����;�<��&�*�*�4�;�;�=�9�:�:r1c��[R[[URR450R
S555$)Nr�)rr�rrar�r�r�r$s  r-�_challenge_response�'WebSocketProtocol13._challenge_response�s5��"�7�7���g�o�o�-�-�1�1�2E�F�G�451�	452r1c	��*# �URRRS5nU(a/URS5Vs/sHo3R	5PM nnO/nURU5UlUR(a.URU;deURSUR5 URURR5nUHnUSS:XdMURcMURSUSUR5 SUS;aUSScUSS	URS[R"SUS55  O URS	5 URS4535 URSS5 URS
S5 URSURU55 UR!5 UR#5UlUR'5 UR("UR*0UR,D6nUb454UIShv�N UR95IShv�N gs snfN"![.a5 UR0"[2R4"56 UR75 gf=fNN7f)N�Sec-WebSocket-Protocolr�r�permessage-deflate�server��client_max_window_bits�Sec-WebSocket-ExtensionszContent-Typer�r�r�r�zSec-WebSocket-Accept)r�r�r�r�r�r�r�r��_parse_extensions_headerr��_create_compressorsr�_encode_header�clear_headerr�r�r�rr!rNr�r�r�r/r^r0r1r2rQ)r,r�subprotocol_headerr�r��455extensions�ext�open_results        r-r��&WebSocketProtocol13._accept_connection�sO���$�_�_�4�4�8�8�9Q�R���/A�/G�/G��/L�M�/L�!�G�G�I�/L�L�M�L��L�$+�$>�$>�|�$L��!��$�$��,�,��<�<�<����7��9R�9R�S��2�2�7�?�?�3J�3J�K�456��C��1�v�-�-�$�2K�2K�2W��(�(��3�q�6�4�;T�;T�U�,��A��6��A��7�8�@��A��7�8��"�"�.��+�+�,@�#�a�&�I���!�$	���^�,����3�����9�k�2����<��3����1�4�3K�3K�G�3T�U������,�,�.�������	�!�,�,��(9�(9�Q�W�=P�=P�Q�K��&�!�!�!��&�&�(�(�(��]N�P"���	��!�!�3�<�<�>�2��K�K�M��	��457	)�sb�AJ�I�BJ�*J�9DJ�<.I�*I
�+I�/J�J�458J�
I�<J�J�
J�Jr�c���URSS5nU(aDURS5Vs/sH'n[R"UR	55PM) sn$/$s snf)Nr�r�r�)r�r�r�
_parse_headerr�)r,r�r��es    r-r��,WebSocketProtocol13._parse_extensions_header�sW���[�[�!;�R�@�459��?I�?O�?O�PS�?T�U�?T�!�H�*�*�1�7�7�9�5�?T�U�U��	��Vs�.A c�p�USR5S:XdeUSR5S:XdeURU5nUSU:XdeURU5nUH:nUSS:Xa$URbUR	S	US4605 M0[SU5e UR
SS5Ulg)
z|Process the headers sent by the server to this client connection.461 462'key' is the websocket handshake challenge/response key.463r�r�r�r�zSec-Websocket-Acceptrr�N�clientr�zunsupported extension %rr�)r�r�r�r�r�rer�r�)r,rIr��acceptr�r�s      r-rK�+WebSocketProtocol13._process_server_headers�s����y�!�'�'�)�[�8�8�8��|�$�*�*�,�	�9�9�9��*�*�3�/���-�.�&�8�8�8��2�2�7�;�464��C��1�v�-�-�$�2K�2K�2W��(�(��3�q�6�:� �!;�S�A�A�	�%,�K�K�0H�$�$O��!r1�side�agreed_parametersruc��[US-U;S9nURUS-S5nUc[RUS'O[	U5US'X4S'U$)z\Converts a websocket agreed_parameters set to keyword arguments465for our compressor objects.466�_no_context_takeover)r\�_max_window_bitsNr]ru)r�r�rcrdr;)r,r�r�ru�options�wbits_headers      r-�_get_compressor_options�+WebSocketProtocol13._get_compressor_options�sh����5�5�>O�O�467��)�,�,�T�4F�-F��M����#'�>�>�G�K� �#&�|�#4�G�K� �)<�%�&��r1c	��1SknUHnXT;dM468[SU-5e US:XaSOSn[S0URXU5D6Ul[	SSUR469R0URXbU5D6Ulg)N>r��server_max_window_bits�client_no_context_takeover�server_no_context_takeoverz$unsupported compression parameter %rr�r�rtr*)rer[r�rlrzrrtr~)r,r�r�ru�allowed_keysrI�470other_sides       r-r��'WebSocketProtocol13._create_compressorss���471��%�C��&� �!G�#�!M�N�N�%�#'�(�"2�X��472�7�473��*�*�4�DW�X�474���<�475�!�[�[�9�9�476��*�*��/B��477��r1�fin�opcoder&�flagsr�c��[U5nUS-(a#U(d[S5eUS:�a[S5eU(a
URnOSn[R"SXb-U-5nUR478(aSnOSnUS:aU[R"SXX-5-
nOCUS	::aU[R"S479SU-U5-
nOU[R"SSU-U5-
nUR480(a$[R"S
5n	U	[X�5-nXs-
nU=R[U5-
sl	URRU5$)Nr_z$control frames may not be fragmented�}z/control frame payloads may not exceed 125 bytesr�Br��~i��z!BHz!BQ��)�lenre�FIN�struct�packr��os�urandomrr�r!r	)481r,r�r�r&r��data_len�finbit�frame�mask_bit�masks482          r-�_write_frame� WebSocketProtocol13._write_frames&���t�9���C�<�� �!G�H�H��#�~� �!R�S�S���X�X�F��F����C���5�!8�9������H��H��c�>��V�[�[��h�&9�:�:�E�
��
��V�[�[���h���A�A�E��V�[�[���h���A�A�E�����:�:�a�=�D��/�$�5�5�D�
�
������E�483�*���{�{� � ��'�'r1rNr�c�>^�U(aSnOSn[U[5(a[RR	U5n[RRU5n[U[5(deU=R[U5-
slSnUR(a)URRU5nX@R-nURSX1US9mSU4Sjjn[R "U"55$![a [5ef=f)z9Sends the given message to the client of this Web Socket.�r�rT)r�c��X># �TIShv�N gN![a [5ef=f7fr))r
ri)�futs�r-�wrapper�2WebSocketProtocol13.write_message.<locals>.wrapperWs)����
-��	�	��$�
-�*�,�,�
-�s �*����*��'�*r)r�r�r�r�r�rr:r�r�rlr.�RSV1r�r
rir��
ensure_future)r,rNr�r�r�rrs      @r-r��!WebSocketProtocol13.write_message<s������F��F��g�t�$�$��n�n�0�0��9�G��.�.�%�%�g�.���'�5�)�)�)�)����3�w�<�/��������&�&�/�/��8�G��Y�Y��E�	)��#�#�D�&��#�G�C�	-��$�$�W�Y�/�/��!�	)�&�(�(�	)�s�D�Dc�X�[U[5(deURSSU5 g)zSend ping frame.T�	N)r�r:r�r+s  r-r��WebSocketProtocol13.write_ping_s'���$��&�&�&�&����$��T�*r1c��*# �UR(d+UR5IShv�N UR(dM+URRURUR5 gNH![a UR5 NOf=f7fr))r"�_receive_framer
r2rrLrHrIr�s r-rQ�'WebSocketProtocol13._receive_frame_loopdso���	��,�,��)�)�+�+�+��,�,�,�	
���+�+�D�O�O�T�=N�=N�O�,�� �	��K�K�M�	�s8�B�$A3�A1�A3�1B�1A3�3B�
B�B�B�nc��# �URRU5IShv�NnU=RU-
slU$N7fr))r!�484read_bytesr�)r,rr&s   r-�_read_bytes�WebSocketProtocol13._read_bytesls7����[�[�+�+�A�.�.�����q� ����/�s�?�=�?c��z# �URS5IShv�Nn[R"SU5up#X R-nX R-nX R485-nUS-nURb1US:wa+[XPR-5Ul	XPR)-nU(aUR5 g[US-5nUS-n	U(aU	S:�aUR5 gU	S:aX�lOsU	S:Xa4URS5IShv�Nn[R"SU5Sn	O9U	S:Xa3URS5IShv�Nn[R"S	U5Sn	U	n486URbU487[UR5-
n488X�RR:�a#UR!S489S5 UR5 gU(aURS5IShv�NUlURU	5IShv�NnU(a%UR"ce[%UR"U5nU(aU(dUR5 gO�US:XaiURcUR5 gURR'U5 U(a(UR(n[+UR5nSUlO;URbUR5 gU(dX`l[-U5UlU(a UR/Xa5nUbUIShv�N gggGNGNGN�GNJGN/N7f)
Nr��BBr_rr�r�r�z!Hz!Q��zmessage too bigr�)rr��unpackr��RSV_MASK�OPCODE_MASKr~rrr�r2r�r�r�rrtr�r�r�extendr�r:�	bytearray�_handle_message)r,r&�header�mask_payloadlen�is_final_frame�
reserved_bitsr��opcode_is_control�	is_masked�490payloadlen�new_len�handled_futures            r-r491�"WebSocketProtocol13._receive_frameqs�����%�%�a�(�(��"(�-�-��d�";����(�(�*�����.�
��*�*�*��"�S�L�����)�f��k�&*�-�)�)�*C�%D�D�"��i�i�Z�'�M���K�K�M����4�/�0�	�$�t�+�492���s�!2��K�K�M�����!+��
�3�
��)�)�!�,�,�D����t�T�2�1�5�J�
�3�
��)�)�!�,�,�D����t�T�2�1�5�J����*�*�6��s�4�:�:�;�;�G��[�[�1�1�1��J�J�t�.�/��K�K�M���%)�%5�%5�a�%8�8�D���%�%�j�1�1����#�#�/�/�/�"�4�#3�#3�T�:�D��"����
��"��q�[��.�.�6����
���+�+�2�2�4�8���8�8���T�<�<�=��26��/���.�.�:����
��!�28�/�2;�D�/��/��!�1�1�&�?�N��)�$�$�$�*��Y)�6-�-� 9�1�H%�sl�L;�L*�C:L;�L-�9L;�L0�
BL;�)L3�*L;�L6�DL;�"L9�#L;�-L;�0L;�3L;�6L;�9L;zOptional[Future[None]]c���UR(agUR(a+URceURRU5nUS:XaVU=R[U5-
slURS5nURURRU5$US:XaDU=R[U5-
slURURRU5$US:XavSUl[U5S:�a"[R"S	USS5S493Ul[U5S:�a[#USS5UlURUR 5 gUS:Xa;UR'SSU5 URURR*U5 gUS:Xa-SUlURURR.U5$UR
5 g![a% URSS5 UR
5 gf=f![a UR
5 gf=f![(a UR
5 N�f=f)
z>Execute on_message, returning its Future if it is a coroutine.Nrz#message too big after decompressionr�zutf-8r�r_T�>Hrr�494)r"r�r~rBrmr�r2r�r��decode�UnicodeDecodeErrorr3rrQr�rrHrrIr�r
rTr�rW)r,r�r&�decodeds    r-r�#WebSocketProtocol13._handle_message�s���!�!���!�!��%�%�1�1�1�
��)�)�4�4�T�:���S�=��"�"�c�$�i�/�"�
��+�+�g�.���%�%�d�l�l�&=�&=�w�G�G�
�s�]��"�"�c�$�i�/�"��%�%�d�l�l�&=�&=�t�D�D�
�s�]�%)�D�"��4�y�A�~�"(�-�-��d�2�A�h�"?��"B����4�y�1�}�$.�t�A�B�x�$8��!��J�J�t���'���s�]�
��!�!�$��T�2�
���t�|�|�3�3�T�:��
�s�]�"&�D���%�%�d�l�l�&:�&:�D�A�A��K�K�M���Q,�
��495�496�4�!F�G����
��
��&�
����
��
��*%�
����
�
�s5�G6�4H(�8I�6,H%�$H%�(I�I�I%�$I%r�r�c�Z�UR(dpURR5(dJUcUbSnUcSnO[R"SU5nUbU[U5-
nUR
SSU5 SUlUR(a^URb6URRRUR5 SUl497URR5 OgURcZURRRURRR5S-UR5Ul498UR (a"UR R#5 SUlgg![a UR5 GN.f=f)z Closes the WebSocket connection.Ni�r1r%Tr_�)r#r!�closedr�r�rr�r
r2r"r�r-�remove_timeoutr��add_timeout�timer��cancel)r,r�r��499close_datas    r-r��WebSocketProtocol13.close�sO���%�%��;�;�%�%�'�'��<�F�$6��D��<�!$�J�!'���T�4�!8�J��%��$�v�,�.�J�"��%�%�d�C��<�&*�D�"��!�!��}�}�(����#�#�2�2�4�=�=�A� $��
��K�K����
�]�]�
"�!�K�K�/�/�;�;����#�#�(�(�*�Q�.�����D�M����� � �'�'�)�#'�D� � ��)�"��K�K�M�"�s�(F�F*�)F*c��URR5=(d UR=(d UR$)z�Return ``True`` if this connection is closing.500 501The connection is considered closing if either side has502initiated its closing handshake or if the stream has been503shut down uncleanly.504)r!r-r"r#r�s r-r��WebSocketProtocol13.is_closings-���{�{�!�!�#�W�t�'=�'=�W��AW�AW�Wr1rSc�:�URRU5 gr))r!r�rUs  r-r��WebSocketProtocol13.set_nodelay s��������"r1c�:�URRnUbU$g)Nr)rrr)r,�intervals  r-rr�!WebSocketProtocol13.ping_interval#s���;�;�,�,�����O�r1c	��URRnUbeUR(aRXR:�aC[[R505SUSURSUR35 UR$U$UR$)NzThe websocket_ping_timeout (z5) cannot be longer than the websocket_ping_interval (z").506Setting websocket_ping_timeout=)rrsrr�de_dupe_gen_log�logging�WARNING)r,�timeouts  r-rs� WebSocketProtocol13.ping_timeout*s����+�+�*�*�����!�!�g�0B�0B�&B���O�O�2�7�)�<:�:>�:L�:L�9M�N8�8<�8J�8J�7K�M�	��)�)�)��N��!�!�!r1c��UR(d;URS:�a*[R"UR	55Ulggg)z9Start sending periodic pings to keep the connection aliverN)r�rrr��create_task�
periodic_pingr�s r-rN�!WebSocketProtocol13.start_pinging;sA���$�$��"�"�Q�&�#*�#6�#6�t�7I�7I�7K�#L�D� �'�%r1�last_ping_timer9�nowc�$�[SX-U-5075$)z<Calculate the sleep time until the next ping should be sent.r)�max�rEr9rFs   r-�ping_sleep_time�#WebSocketProtocol13.ping_sleep_timeEs���1�n�/�#�5�6�6r1c��$# �URnURn[R"U5IShv�N SUl[508R"5R5nURS5 [R"U5IShv�N US:�a!UR(dURSS9 g[R"URUU[509R"5R5S95IShv�N M�N�N}N5107f)z�Send a ping and wait for a pong if ping_timeout is configured.511 512Called periodically if the websocket_ping_interval is set and non-zero.513NFr1rzping timed out)r�rI)rrrsr��sleepr�r�currentr0r�r�rJ)r,r9r?�	ping_times    r-rC�!WebSocketProtocol13.periodic_pingJs����514�%�%���#�#���m�m�H�%�%�%��"'�D�����(�-�-�/�I��O�O�C� ��-�-��(�(�(���{�4�#6�#6��515�516�"2�517�3���-�-��$�$�#,�%����(�-�-�/�%���
�
��	&�
)�
�s5�2D�D518�AD�D�A4D�D�D�D�D)r�rlr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r"rHrIr�rr�r#r!r))rrrr`)9r6r7r8r9rkr�r�RSV2�RSV3rrr!rrprxrrrar��setterr}r�r��staticmethodrr:r�r�r�rrYrrrr�rKrr�r�r;r�r�r�rQrr519rr�r�r�r{rrrsrNrJrCr<r*r1r-rr2s�����C��D��D��D��d�{�T�!�H��K�
�F�!$�%�!$��!$�!�	!$�520521�!$�H�*�h�s�m�*��*�� � �+�(�3�-�+�D�+�!�+��/?��D��(B�1A�B�d�B��;�%��U�522�"3�;��;��;�523�+;�524��525�5261)�0@�1)�T�1)�f��+�+��	
�e�C��c�3�h��'�(�	)��P���e��$�P�/7�/C�/C�P�	
�P�29=�	��� ��S��>��&�d�3��8�n�5�	�527528�c�3�h���09=�	529��530� ��S��>�531�&�d�3��8�n�5�	532�533534�535�8AB�(��(�!$�(�,1�(�:=�(�	�(�DJO�!0��S�%��c�3�h��7�8�!0�BF�!0�	�!0�F+�u�+��+�536P��3��5��537Q%�f1�c�1��1�;S�1�f(�(�3�-�(���
�(�QU�(�@X�D�X�#�T�#�d�#���u�����"�e�"��"� M��7�5�7�E�7��7�RW�7��7�r1rc�^�\rSrSrSrSrSSSS\SS4S\RS\	\538\S\\
4/S4S\	\\\4S\	\S\	\S	\S539\	\\S\	\SS4U4S
jjjrS0SjrS1S\	\S\	\SS4SjjrS0U4SjjrS1S\	\S\	\SS4SjjrS\R2SS4SjrS\\R8\R:4S\R<SS4U4SjjrS2S\\\
\\\44S\ SS4Sjjr!S3S\	\540S /S4S\"\S\\
44S!jjr#S\\\
4S\	\"S4S"jr$S\S\\
4S\	\"S4S#jr%S4S$\
SS4S%jjr&S$\
SS4S&jr'S$\
SS4S'jr(S\)4S(jr*\+S\	\4S)j5r,S*S+S,\	\-S-\	\.SS4S.jr/S/r0U=r1$)5�WebSocketClientConnectionilz|WebSocket client connection.541 542This class should not be instantiated directly; use the543`websocket_connect` function instead.544Nr��on_message_callbackrurrrsrtr��resolverr'c	545�>�[5Ul[S5Ul[R546"[R"S55UlX l	SUl547SUl[UUUUS9Ul
URRS5up�nSSS.U	n	X�-U-UlUR R#SS	[%UR5S548S.5 UbSR'U5UR S
'UbSUR S'SUl[+US9Ul[.TU]aSUSUR2SUR,SS5 g)Nr�r�rw�:�http�https)�ws�wssr�r�r)r�r�zSec-WebSocket-Keyr�r�r�z*permessage-deflate; client_max_window_bitsr�F)rXc��gr)r*r*r1r-r��4WebSocketClientConnection.__init__.<locals>.<lambda>�s��Dr1i@i)r�connect_futurer�549read_queuer�r�r�r�rI�_on_message_callbackrHrIrpr�url�	partitionr�r�r�join�follow_redirectsr�550tcp_clientr�rx�_on_http_response)
r,r�rWrurrrsrtr�rX�scheme�sep�restr�s
            �r-rx�"WebSocketClientConnection.__init__usD���%�h�����(����#�#�B�J�J�r�N�3���$7�!���� ���&�'�%�-� 3�	551���$�K�K�1�1�#�6���T��w�/��7���l�T�)��������&�'�%/����%9�)-�	
�	552��#�8;����8N�G�O�O�4�5��*�=�
�O�O�6�7�553$)�� �#�X�6���
�������"�"���O�O���		554r1c�V�URb[R"S[5 gg)Nz"Unclosed WebSocketClientConnection)�protocol�warnings�warn�ResourceWarningr�s r-�__del__�!WebSocketClientConnection.__del__�s"���=�=�$�
�M�M�>��P�
%r1r�r�c�d�URb#URRX5 SUlgg)z�Closes the websocket connection.555 556``code`` and ``reason`` are documented under557`WebSocketHandler.close`.558 559.. versionadded:: 3.2560 561.. versionchanged:: 4.0562 563   Added the ``code`` and ``reason`` arguments.564N)ror�r�s   r-r��WebSocketClientConnection.close�s,���=�=�$��M�M����-� �D�M�%r1c��>�URR5(d#URR[55 UR	S5 UR565R
5 [TU]!5 gr))	ra�done�
set_exceptionr
�_on_messagerhr�r�r�r�s �r-r��-WebSocketClientConnection.on_connection_close�sY����"�"�'�'�)�)����-�-�.?�.A�B������������
��#�%r1rHrIc�<�XlX lUR5 gr)r�rKs   r-rL�0WebSocketClientConnection.on_ws_connection_close�r�r1�responsec���URR5(d\UR(a&URRUR5 gURR[	S55 gg)NzNon-websocket response)rarx�errorryrd)r,r~s  r-ri�+WebSocketClientConnection._on_http_response�sX���"�"�'�'�)�)��~�~��#�#�1�1�(�.�.�A��#�#�1�1�"�#;�<��	*r1�566start_liner�c���># �[U[R5(deURS:wa[TU]X5IShv�N gURb,URRUR5 SUlX l	UR5UlURRURUR5 URR5URl["R$"5R'URR(5 URR+5 SUl[/UR0U5 gGN#7fr�)r�r�ResponseStartLiner�r��headers_received�_timeoutr-r.r�r�rorKrIr�rr!rrN�add_callbackrQrN�final_callbackrra)r,r�r�r�s   �r-r��*WebSocketClientConnection.headers_received�s����567�*�h�&@�&@�A�A�A�A��?�?�c�!��'�*�:�?�?�?���=�=�$��L�L�'�'��
�
�6� �D�M����3�3�5��
��
�
�-�-�d�h�h����E�#���5�5�7��
�
������%�%�d�m�m�&G�&G�H��
�
�#�#�%�#���*�4�+>�+>��E�+
@�s�AE-�E*�D#E-rNr�r�c�d�URc[S5eURRXS9$)aSends a message to the WebSocket server.568 569If the stream is closed, raises `WebSocketClosedError`.570Returns a `.Future` which can be used for flow control.571 572.. versionchanged:: 5.0573   Exception raised on a closed stream changed from `.StreamClosedError`574   to `WebSocketClosedError`.575z!Client connection has been closedr�)rorir�r�s   r-r��'WebSocketClientConnection.write_messages2���=�=� �&�'J�K�K��}�}�*�*�7�*�B�Br1r&zFuture[Union[None, str, bytes]]c��URR5nUb0URR[R576"U5U5 U$)a@Reads a message from the WebSocket server.577 578If on_message_callback was specified at WebSocket579initialization, this function will never return messages580 581Returns a future whose result is the message, or None582if the connection is closed.  If a callback argument583is given it will be called with the future when it is584ready.585)rbr�r-r.r�r)r,r&�	awaitables   r-�read_message�&WebSocketClientConnection.read_messagesA���O�O�'�'�)�	����L�L�#�#�G�$9�$9�)�$D�h�O��r1c�$�URU5$r))rzrPs  r-rQ�$WebSocketClientConnection.on_message%s������(�(r1c�~�UR(aURU5 gURRU5$r))rcrb�putrPs  r-rz�%WebSocketClientConnection._on_message(s3���$�$��%�%�g�.���?�?�&�&�w�/�/r1r&c�~�[U5nURc586[5eURRU5 g)a_Send ping frame to the remote end.587 588The data argument allows a small amount of data (up to 125589bytes) to be sent as a part of the ping message. Note that not590all websocket implementations expose this data to591applications.592 593Consider using the ``ping_interval`` argument to594`websocket_connect` instead of sending pings manually.595 596.. versionadded:: 5.1597 598N)rrorir�r+s  r-r��WebSocketClientConnection.ping1s2���D�z���=�=� �&�(�(��
�
� � ��&r1c��gr)r*r+s  r-rW�!WebSocketClientConnection.on_pongD���r1c��gr)r*r+s  r-rT�!WebSocketClientConnection.on_pingGr�r1c�,�[USURS9$)NT)r�r)rrr�s r-r��0WebSocketClientConnection.get_websocket_protocolJs��"�4�t�D�K�K�P�Pr1c�.�URR$)z?The subprotocol selected by the server.599 600.. versionadded:: 5.1601)ror�r�s r-r��.WebSocketClientConnection.selected_subprotocolMs���}�}�1�1�1r1rYzOptional[Type[BaseException]]rZr[c�F�UceUce[R"SX!X#4S9 g)NzUncaught exception %sr�)rr�r]s    r-r^�'WebSocketClientConnection.log_exceptionUs.������� � � ��
�
�-�u�U�?O�Pr1)rcr�rHrIrar�r�rIrrorbrhrr`rr)r)2r6r7r8r9rkrorzr602�HTTPRequestrrrrar:rrr{r;rrrxrsr�r�rL�HTTPResponserir�RequestStartLiner�rYr�rr�rr�rQrzr�rWrTr�r�rr�rbr!r^r<rrs@r-rVrVls������H�603TX�8<�)-�(,� 9�,0�'+�<604��'�'�<605�&�h��d�C��6F�0G�/H�$�/N�&O�P�<606�&�d�3��8�n�5�	<607�608 ���<609��u�o�
<610��<611��t�C�y�)�<612��8�$�<613�614�<615�<616�|Q�!�(�3�-�!���
�!�QU�!� &�OS�#�"�3�-�#�>F�s�m�#�	
�#��*�*A�*A��d��F��(�3�3�X�5O�5O�O�P�F��%�%�F�617�	F�>JO�C��S�%��c�3�h��7�8�C�BF�C�	�C�$SW���8�%F�$G��$M�N�O��618�5��s�E�)�*�	+��()�%��U�619�"3�)���4��8Q�)�0��T�3��-�.�0�	�)�D�/�	"�0�'��'��'�&
�E�
�d�
�
�E�
�d�
�Q�(9�Q��2�h�s�m�2��2�Q�
,�Q��
�&�Q�
�]�#�	Q�620621�Q�Qr1rVrdr&z!Future[WebSocketClientConnection]�connect_timeoutrWrurrrsrtr�rXz$Awaitable[WebSocketClientConnection]c622� �[U[R5(a-UbeUn623[R"U624R6255U626lO[R"XS9n627[
[R[R"U628[RR55n629[U630UUUUUUU	S9nUbI[R"S[SS9 [R"5RUR U5 UR $)a�Client-side websocket support.631 632Takes a url and returns a Future whose result is a633`WebSocketClientConnection`.634 635``compression_options`` is interpreted in the same way as the636return value of `.WebSocketHandler.get_compression_options`.637 638The connection supports two styles of operation. In the coroutine639style, the application typically calls640`~.WebSocketClientConnection.read_message` in a loop::641 642    conn = yield websocket_connect(url)643    while True:644        msg = yield conn.read_message()645        if msg is None: break646        # Do something with msg647 648In the callback style, pass an ``on_message_callback`` to649``websocket_connect``. In both styles, a message of ``None``650indicates that the connection has been closed.651 652``subprotocols`` may be a list of strings specifying proposed653subprotocols. The selected protocol may be found on the654``selected_subprotocol`` attribute of the connection object655when the connection is complete.656 657.. versionchanged:: 3.2658   Also accepts ``HTTPRequest`` objects in place of urls.659 660.. versionchanged:: 4.1661   Added ``compression_options`` and ``on_message_callback``.662 663.. versionchanged:: 4.5664   Added the ``ping_interval``, ``ping_timeout``, and ``max_message_size``665   arguments, which have the same meaning as in `WebSocketHandler`.666 667.. versionchanged:: 5.0668   The ``io_loop`` argument (deprecated since version 4.1) has been removed.669 670.. versionchanged:: 5.1671   Added the ``subprotocols`` argument.672 673.. versionchanged:: 6.3674   Added the ``resolver`` argument.675 676.. deprecated:: 6.5677   The ``callback`` argument is deprecated and will be removed in Tornado 7.0.678   Use the returned Future instead. Note that ``on_message_callback`` is not679   deprecated and may still be used.680)r�)rWrurrrsrtr�rXzZThe callback argument to websocket_connect is deprecated. Use the returned Future instead.r�)�681stacklevel)r�r682r�rrYr�r�
_RequestProxy�	_DEFAULTSrVrprq�DeprecationWarningrrNr.ra)rdr&r�rWrurrrsrtr�rXr��conns            r-�websocket_connectr�`s���~�#�z�-�-�.�.��&�&�&���#�.�.�w���?����(�(��N������� � ��*�*@�*@�*J�*J�K��G�%��/�/�#�!�)�!��	�D����
�
�
/���		683�	����#�#�D�$7�$7��B����r1)WrkrWr�r��	functoolsr�r=r�r0r�r��urllib.parserrprc�tornado.concurrentrr�tornado.escaperrrr	r684r�tornado.ioloopr�tornado.iostreamr
r�tornado.logrr�tornado.netutilrr�tornado.queuesr�tornado.tcpclientr�tornado.utilr�typingrrrrrrrrrrr �typesr!�typing_extensionsr"r$r>rFrz�	lru_cache�logr<r/rdrirmrpr�RequestHandlerr}r
�ABCr�r[rzr�_HTTPConnectionrVrar�r{r:r;r�r*r1r-�<module>r�so�����
����	�685�
��!���I�7�7�-�-�!�8�(�$�%� �'�(����� ��*��h������X��6-���%�%�g�k�k�2��	�Y�	�	�>�	�	�y�	�7�7�q�w�{�{�1�1�q�h?�s�?�c�?�d�?�X$����X$�v-�-�`#�#�Lw�+�w�tqQ� 1� A� A�qQ�lQU�'+�OS�48�%)�$(�5�(,�#'�]�	�s�J�*�*�*�	+�]��x�!D� E�t� K�L�M�]��e�_�]�"�(�E�$��U�2B�,C�+D�d�+J�"K�L�	]�686"�$�s�C�x�.�1�]��E�?�
]��5�/�]��]��4��9�%�]��x� �]�,�]r1
codekingpro/portable-devtools · Team Ai