� ���gs����ddlZddlZddlZddlZ ddlZn #e$rdZYnwxYwddlmZddlmZddlm Z ddlm Z da e ��Z d�ZGd �d ej��ZdS) �N�)� base_client)� exceptions)�packet)�payloadFc�D�d�}tj|����dS)z>SIGINT handler. Disconnect all active async clients. c��xK�tjdd�D]0}|���r|����d{V���1d�t j��D��}|D]}|����t j|ddi��d{V��t j��� ��dS)Nc�<�g|]}|tj��u�|��S�)�asyncio� current_task)�.0�tasks �e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/engineio/async_client.py� <listcomp>z:async_signal_handler.<locals>._handler.<locals>.<listcomp>#s<��)�)�)�$���%�'�'�:(�:(��:(�:(�:(��return_exceptionsT) r�connected_clients�is_asyncio_based� disconnectr � all_tasks�cancel�gather�get_running_loop�stop)�c�tasksrs r�_handlerz&async_signal_handler.<locals>._handlers������.�q�q�q�1� %� %�A��!�!�#�#� %��l�l�n�n�$�$�$�$�$�$�$��)�)�'�"3�"5�"5�)�)�)��� � �D� �K�K�M�M�M�M��n�e�<�t�<�<�<�<�<�<�<�<�<�� �"�"�'�'�)�)�)�)�)rN�r � ensure_future)rs r�async_signal_handlerr!s0�� *� *� *� ��(�(�*�*�%�%�%�%�%rc���eZdZdZd�Z dd�Zd�Zd�Zdd �Zd �Z dd �Z d �Z d�Z �fd�Z d�Zd�Zd�Zd�Zd�Z dd�Zd�Zd�Zd�Zd�Z�xZS)� AsyncClienta�An Engine.IO client for asyncio. This class implements a fully compliant Engine.IO web client with support for websocket and long-polling transports, compatible with the asyncio framework on Python 3.5 or newer. :param logger: To enable logging set to ``True`` or pass a logger object to use. To disable logging set to ``False``. The default is ``False``. Note that fatal errors are logged even when ``logger`` is ``False``. :param json: An alternative json module to use for encoding and decoding packets. Custom json modules must have ``dumps`` and ``loads`` functions that are compatible with the standard library versions. :param request_timeout: A timeout in seconds for requests. The default is 5 seconds. :param http_session: an initialized ``aiohttp.ClientSession`` object to be used when sending requests to the server. Use it if you need to add special client options such as proxy servers, SSL certificates, custom CA bundle, etc. :param ssl_verify: ``True`` to verify SSL certificates, or ``False`` to skip SSL certificate verification, allowing connections to servers with self signed certificates. The default is ``True``. :param handle_sigint: Set to ``True`` to automatically handle disconnection when the process is interrupted, or to ``False`` to leave interrupt handling to the calling application. Interrupt handling can only be enabled when the client instance is created in the main thread. :param websocket_extra_options: Dictionary containing additional keyword arguments passed to ``aiohttp.ws_connect()``. :param timestamp_requests: If ``True`` a timestamp is added to the query string of Socket.IO requests as a cache-busting measure. Set to ``False`` to disable. c��dS)NTr ��selfs rrzAsyncClient.is_asyncio_basedRs���trN� engine.ioc���K�|jr�ts�tj��tj��krb t j���tj t��n*#t$r|j � d��YnwxYwda|jdkrtd���ddg�|�7t!|t"��r|g}�fd�|D��}|std ���|p�|_|���|_t+|d |jd z��||pi|���d{V��S) a�Connect to an Engine.IO server. :param url: The URL of the Engine.IO server. It can include custom query string parameters if required by the server. :param headers: A dictionary with custom headers to send with the connection request. :param transports: The list of allowed transports. Valid transports are ``'polling'`` and ``'websocket'``. If not given, the polling transport is connected first, then an upgrade to websocket is attempted. :param engineio_path: The endpoint where the Engine.IO server is installed. The default value is appropriate for most cases. Note: this method is a coroutine. Example usage:: eio = engineio.Client() await eio.connect('http://localhost:5000') zSignal handler is unsupportedT� disconnectedz%Client is not in a disconnected state�polling� websocketNc���g|]}|�v�|�� Sr r )r� transport�valid_transportss �rrz'AsyncClient.connect.<locals>.<listcomp>|s.���<�<�<� �&�*:�:�:�$�:�:�:rzNo valid transports provided� _connect_r)� handle_sigint�async_signal_handler_set� threading�current_thread� main_threadr r�add_signal_handler�signal�SIGINTr!�NotImplementedError�logger�warning�state� ValueError� isinstance�str� transports� create_queue�queue�getattr)r&�url�headersr?� engineio_pathr.s @r�connectzAsyncClient.connectUs������0 � � E�&>� E��(�*�*�i�.C�.E�.E�E�E� E��(�*�*�=�=��M�#7�9�9�9�9��&� E� E� E�� �#�#�$C�D�D�D�D�D� E����#'� � �:�� '� '��D�E�E� E�%�{�3�� � !��*�c�*�*� *�(�\� �<�<�<�<�Z�<�<�<�J�� A� �!?�@�@�@�$�8�(8����&�&�(�(�� �D�W�T�;����1C�#C�D�D� ���B� �/�/�/�/�/�/�/�/� /s�6A2�2$B�Bc��6K�|jr|j�d{V��dSdS)z�Wait until the connection with the server ends. Client applications can use this function to block the main thread during the life of the connection. Note: this method is a coroutine. N)�read_loop_taskr%s r�waitzAsyncClient.wait�s>���� � � &��%� %� %� %� %� %� %� %� %� %� &� &rc��|K�|�tjtj|������d{V��dS)a/Send a message to the server. :param data: The data to send to the server. Data can be of type ``str``, ``bytes``, ``list`` or ``dict``. If a ``list`` or ``dict``, the data will be serialized as JSON. Note: this method is a coroutine. ��dataN)� _send_packetr�Packet�MESSAGE)r&rLs r�sendzAsyncClient.send�sE�������� �f�n�4� H� H� H�I�I�I�I�I�I�I�I�I�I�IrFc��FK�|jdkr�|�tjtj�����d{V��|j�d���d{V��d|_|�d|p |jj d����d{V��|j dkr|j � ���d{V��|s |j �d{V��d|_ tj�|��n#t"$rYnwxYw|����d{V��dS) z�Disconnect from the server. :param abort: If set to ``True``, do not wait for background tasks associated with the connection to end. Note: this method is a coroutine. � connectedN� disconnectingrF�� run_asyncr+r))r;rMrrN�CLOSErA�put�_trigger_event�reason�CLIENT_DISCONNECT�current_transport�ws�closerHrr�remover<�_reset)r&�abortrYs rrzAsyncClient.disconnect�s����� �:�� $� $��#�#�F�M�&�,�$?�$?�@�@� @� @� @� @� @� @� @��*�.�.��&�&� &� &� &� &� &� &� &�(�D�J��%�%�l�&,�&M�� �0M�05�&�7�7� 7� 7� 7� 7� 7� 7� 7��%��4�4��g�m�m�o�o�%�%�%�%�%�%�%�� *��)�)�)�)�)�)�)�)�'�D�J� ��-�4�4�T�:�:�:�:��� � � ��� �����k�k�m�m���������s�C7�7 D�Dc�6�tj||i|����S)amStart a background task. This is a utility function that applications can use to start a background task. :param target: the target function to execute. :param args: arguments to pass to the function. :param kwargs: keyword arguments to pass to the function. The return value is a ``asyncio.Task`` object. r)r&�target�args�kwargss r�start_background_taskz!AsyncClient.start_background_task�s$���$�V�V�T�%<�V�%<�%<�=�=�=rrc��:K�tj|���d{V��S)z[Sleep for the requested amount of time. Note: this method is a coroutine. N)r �sleep)r&�secondss rrgzAsyncClient.sleep�s*���� �]�7�+�+�+�+�+�+�+�+�+rc�N�tj��}tj|_|S)zCreate a queue object.)r �Queue� QueueEmpty�Empty)r&�qs rr@zAsyncClient.create_queue�s�� �M�O�O���$����rc�(�tj��S)zCreate an event object.)r �Eventr%s r� create_eventzAsyncClient.create_event�s���}���rc����K�t�����|js4|jr/|jjs%|j����d{V��dSdSdSdS�N)�superr_� external_http�http�closedr])r&� __class__s �rr_zAsyncClient._reset�s������ ���������!� (��y� (���!1� (��i�o�o�'�'�'�'�'�'�'�'�'�'�'� (� (� (� (� (� (rc�H�|jr�|jjs� tj��}|���r.|�|j�����dS|�|j�����dS#YdSxYwdSdSrr)rurvr �get_event_loop� is_runningr r]�run_until_complete)r&�loops r�__del__zAsyncClient.__del__�s��� �9� �T�Y�-� � ��-�/�/���?�?�$�$�?��&�&�t�y���'8�'8�9�9�9�9�9��+�+�D�I�O�O�,=�,=�>�>�>�>�>�� ������� � � � s�AB�*,B�Bc��VK�t�|j�d��dS|�||d��|_|j�d|jz��|�d|j|���z||j����d{V��}|�t|t��r0|� ���d{V��tj |pd���|jdks |jd krz|� ���d{V�� |����d{V��}n#tj$rd}YnwxYwtj d �|j��|��� t%j|����d{V���d ��� ��}n##t,$rtj d ��d�wxYw|jd}|jt2jkrtj d���|j�dt|j��z��|jd|_|jd|_t=|jd��dz |_t=|jd��dz |_ d|_!|xjd|jzz c_d|_"tFj$�%|��|�&dd����d{V��|jdd�D]}|�'|���d{V���d|jvr(d|j(vr|�)|||���d{V��rdS|�*|j+��|_,|�*|j-��|_.dS)z<Establish a long-polling connection to the Engine.IO server.Nz3aiohttp not installed -- cannot make HTTP requests!r*z!Attempting polling connection to �GET)rD�timeoutz Connection refused by the server���,z,Unexpected status code {} in server response�utf-8��encoded_payloadzUnexpected response from serverrz"OPEN packet not returned by serverz!Polling connection accepted with �sid�upgrades� pingInterval�@�@� pingTimeout�&sid=rRrFFrTrr+)/�aiohttpr9�error�_get_engineio_url�base_url�info� _send_request�_get_url_timestamp�request_timeoutr=r>r_r�ConnectionError�status�json� ClientError�formatr�Payload�read�decoder<�packets� packet_typer�OPENrLr�r��int� ping_interval� ping_timeoutr[r;rr�appendrX�_receive_packetr?�_connect_websocketre� _write_loop�write_loop_task�_read_loop_pollingrH) r&rCrDrE�r�arg�p� open_packet�pkts r�_connect_pollingzAsyncClient._connect_polling�s'���� �?� �K� � �*� +� +� +� �F��.�.�s�M�9�M�M�� � � ���<�t�}�L�M�M�M��$�$� �4�=�4�#:�#:�#<�#<�<�g��(�%�*�*� *� *� *� *� *� *�� �9� �1�c�*�*�9��+�+�-�-� � � � � � � ��,��7�7�9�9� 9� �8�c�>�>�Q�X��_�_��+�+�-�-� � � � � � � � ��F�F�H�H�n�n�n�n�n�n�����&� � � ����� �����,�>�E�E��H���"�$�$� $� =���q�v�v�x�x�������0G�0G��1�1����A�A��� =� =� =��,�1�3�3�8<� =� =�����i��l� � � "�f�k� 1� 1��,�4�6�6� 6� � ��� /�#�k�6F�2G�2G� G� I� I� I��#�E�*���#�(��4�� � ��!1�.�!A�B�B�V�K���� � 0�� ?�@�@�6�I���!*��� � � ��4�8�+�+� � � �� ��%�,�,�T�2�2�2��!�!�)�u�!�=�=�=�=�=�=�=�=�=��9�Q�R�R�=� ,� ,�C��&�&�s�+�+� +� +� +� +� +� +� +� +� �$�-� '� '�K�4�?�,J�,J��,�,�S�'�=�I�I�I�I�I�I�I�I� ���#�9�9�$�:J�K�K���"�8�8� � #�%�%����s�D5�5E �E �:AF;�; Gc��@ K�t�|j�d��dS|�||d��}|jr-|j�d|z��d}|d|jzz }n&d}||_|j�d|z��|j� |jjrtj ��|_i}|� ��D]N\}}|� ��d kr1td �|� d ��D����}||=n�O|jj�|��d |ji} |js0t%j��} d| _t$j| _| | d <|�|j�di����|| d<| �|j�� |jj||���zfi| ���d{V��} nl#tjjtjjtjjf$r4|r|j� d��YdStCj"d���wxYw|�r�tGj$tFj%d����&��} | �'| ���d{V��n@#tP$r3} |j� dtS| ����Yd} ~ dSd} ~ wwxYw | �*���d{V��j+} n@#tP$r3} |j� dtS| ����Yd} ~ dSd} ~ wwxYwtGj$| ���}|j,tFj-ks |j+dkr|j� d��dStGj$tFj.���&��} | �'| ���d{V��n@#tP$r3} |j� dtS| ����Yd} ~ dSd} ~ wwxYwd|_/|j�d���nv | �*���d{V��j+} n6#tP$r)} tCj"dtS| ��z���d} ~ wwxYwtGj$| ���}|j,tFj0krtCj"d���|j�dtS|j+��z��|j+d|_|j+d|_1te|j+d��dz |_3te|j+d��dz |_4d|_/d |_5tlj7�8|��|�9d!d�"���d{V��| |_:|�;|j<��|_=|�;|j>��|_?dS)#z?Establish or upgrade to a WebSocket connection with the server.Nzaiohttp package not installedFr+z Attempting WebSocket upgrade to Tr�z#Attempting WebSocket connection to �cookiec�:�g|]}|�dd����S)�=r)�split)rr�s rrz2AsyncClient._connect_websocket.<locals>.<listcomp>=s&��J�J�J�f�V�\�\�#�q�)�)�J�J�Jrz; r��sslrDz*WebSocket upgrade failed: connection errorzConnection error�proberKz7WebSocket upgrade failed: unexpected send exception: %sz7WebSocket upgrade failed: unexpected recv exception: %s��encoded_packetz(WebSocket upgrade failed: no PONG packetz WebSocket upgrade was successfulzUnexpected recv exception: zno OPEN packetz#WebSocket connection accepted with r�r�r�r�r�rRrFrT)@r�r9r�r�r�r�r�rurv� ClientSession�items�lower�dictr�� cookie_jar�update_cookiesr�� ssl_verifyr��create_default_context�check_hostname� CERT_NONE� verify_mode�update�websocket_extra_options�pop� ws_connectr��client_exceptions�WSServerHandshakeError�ServerConnectionError�ClientConnectionErrorr:rr�rrN�PING�encode�send_str� Exceptionr>�receiverLr��PONG�UPGRADEr[r�r�r�r�r�r;rrr�rXr\rer�r��_read_loop_websocketrH)r&rCrDrE� websocket_url�upgrade�cookies�header�value� extra_options� ssl_contextr\r��er�r�s rr�zAsyncClient._connect_websocket"s����� �?� �K� � �=� >� >� >��5��.�.�s�M�/:�<�<� � �8� G� �K� � �2�]�B� D� D� D��G� �W�t�x�/� /�M�M��G�)�D�M� �K� � �5� �E� G� G� G� �9� �� � 0� ��-�/�/�D�I���$�]�]�_�_� � �M�F�E��|�|�~�~��)�)��J�J�� � �D�8I�8I�J�J�J�L�L���F�O��� *� � ��+�+�G�4�4�4�"�D�$8�9� ��� /��4�6�6�K�).�K� &�&)�m�K� #�#.�M�%� � ���t�3�7�7� �2�F�F�G�G�G�#*� �i� ����T�9�:�:�:� E�+�t�y�+��� 7� 7� 9� 9�9�L�L�=J�L�L�L�L�L�L�L�L�B�B���)�@��)�?��)�?�A� E� E� E�� E�� �#�#�@�B�B�B��u�u� �0�1C�D�D�D� E���� �2 B�� �f�k��8�8�8�?�?�A�A�A� ��k�k�!�n�n�$�$�$�$�$�$�$�$��� � � �� �#�#�M���F�F�����u�u�u�u�u�����  ����  ��:�:�<�<�'�'�'�'�'�'�-����� � � �� �#�#�M���F�F�����u�u�u�u�u�����  ���� �-�q�1�1�1�C���&�+�-�-���W�1D�1D�� �#�#�>�@�@�@��u�� �f�n�-�-�4�4�6�6�A� ��k�k�!�n�n�$�$�$�$�$�$�$�$��� � � �� �#�#�M���F�F�����u�u�u�u�u�����  ���� &1�D� "� �K� � �?� @� @� @� @� <��:�:�<�<�'�'�'�'�'�'�-����� <� <� <� �0�1�C��F�F�:�<�<�<����� <����!�-�q�9�9�9�K��&�&�+�5�5� �0�1A�B�B�B� �K� � �5��K�<L�8M�8M�M� O� O� O�"�'��.�D�H�'�,�Z�8�D�M�!$�[�%5�n�%E�!F�!F��!O�D� � #�K�$4�]�$C� D� D�v� M�D� �%0�D� "�$�D�J� � )� 0� 0�� 6� 6� 6��%�%�i�5�%�A�A� A� A� A� A� A� A� A����#�9�9�$�:J�K�K���"�8�8� � %�'�'����tss�.H�AI,�I,�%K� K>� (K9�9K>�L"�" M�,(M�M�$P� P=� (P8�8P=�$R� R7�$R2�2R7c��K�|jttj��krtj|jnd}|j�d|t |jt��s|jnd��|jtj kr%|� d|jd����d{V��dS|jtj kr?|� tj tj|j�����d{V��dS|jtjkr)|�d|jj����d{V��dS|jtjkrdS|j�d |j��dS) z(Handle incoming packets from the server.�UNKNOWNzReceived packet %s data %s�<binary>�messageTrTN)r`rYz%Received unexpected packet of type %s)r��lenr� packet_namesr9r�r=rL�bytesrOrXr�rMrNr�rVrrY�SERVER_DISCONNECT�NOOPr�)r&r�� packet_names rr�zAsyncClient._receive_packet�s��������V�%8�!9�!9�9�9��)�#�/�:�:�?H� � � ��� (�+�&�s�x��7�7� G�C�H�H�Z� I� I� I� �?�f�n� ,� ,��%�%�i���T�%�J�J� J� J� J� J� J� J� J� J� J� �_�� � +� +��#�#�F�M�&�+�s�x�$H�$H�I�I� I� I� I� I� I� I� I� I� I� �_�� � ,� ,��/�/��)-��)F�"�H�H� H� H� H� H� H� H� H� H� H� �_�� � +� +� �D� �K� � �E�!�o� /� /� /� /� /rc��K�|jdkrdS|j�|���d{V��|j�dt j|jt|j t��s|j nd��dS)z(Queue a packet to be sent to the server.rRNzSending packet %s data %sr�) r;rArWr9r�rr�r�r=rLr�)r&r�s rrMzAsyncClient._send_packet�s����� �:�� $� $� �F��j�n�n�S�!�!�!�!�!�!�!�!�!� � ��� '� � ��� 0�&�s�x��7�7� G�C�H�H�Z� I� I� I� I� Irc��K�|j� |jjrtj��|_t |j|�����} |js)||||tj|���d����d{V��S||||tj|�������d{V��S#tjtj f$r6}|j � d|||��t|��cYd}~Sd}~wwxYw)N)�totalF)rDrLr�r�)rDrLr�z+HTTP %s request to %s failed with error %s.)rurvr�r�rBr�r�� ClientTimeoutr�r � TimeoutErrorr9r�r>)r&�methodrCrD�bodyr�� http_method�excs rr�zAsyncClient._send_request�sn���� �9� �� � 0� ��-�/�/�D�I��d�i������8�8� � ��?� B�(�[���t�#�1��@�@�@�e�M�M�M�M�M�M�M�M�M�M�)�[���t�#�1��@�@�@�B�B�B�B�B�B�B�B�B�B���#�W�%9�:� � � � �K� � �J�#�S�#� /� /� /��s�8�8�O�O�O�O�O�O����� ���s$�/B.�'B.�.C?� +C:�4C?�:C?c��2���K�|�dd��}d}��jv�r�tj�j���dur�|rT�j�j�g��R�}t �|��|�t j��|S �j����d{V��}nE#t$r8�dkr0t���dkr�j����d{V��cYS�wxYw�n#tj $rY�n�j � �dz���dkrYdSYn�xYw|rW���fd �}��|��}t �|��|�t j��|S �j���}n@#t$r3�dkr)t���dkr�j���}n�YnwxYwn-#�j � �d z���dkrYdSYnxYw|S) zInvoke an event handler.rUFNTrrz async handler errorrFc��(�K��j���Srr)�handlers)rc�eventr&s���r� async_handlerz1AsyncClient._trigger_event.<locals>.async_handler�s�����3�t�}�U�3�T�:�:rz handler error)r�r�r �iscoroutinefunctionre�task_reference_holder�add�add_done_callback�discard� TypeErrorr��CancelledErrorr9� exception)r&r�rcrdrU�retrr�s``` rrXzAsyncClient._trigger_event�s���������J�J�{�E�2�2� ��� �D�M� !� !��*�4�=��+?�@�@�D�H�H��)�5�4�5�d�m�E�6J�=�7;�=�=�=�D�)�-�-�d�3�3�3��*�*�+@�+H�I�I�I��K�)� &�(<�� �e�(<�d�(C�"C�"C�"C�"C�"C�"C�C�C��(�&�&�&�$� �4�4�$'��I�I��N�N�.B�T�]�5�-A�-C�-C�'C�'C�'C�'C�'C�'C� C� C� C� %�&���� ��#�1������)�� �-�-�e�6L�.L�M�M�M� �I�-�-�$)�5�5�.�-���� �)�;�;�;�;�;�;�;� �5�5�m�D�D�D�)�-�-�d�3�3�3��*�*�+@�+H�I�I�I��K�)� &�"6�$�-��"6��"=�C�C��(�&�&�&�$� �4�4�$'��I�I��N�N�';�d�m�E�&:�&<�&<��� %�!$�� &������)�� �-�-�e�6F�.F�G�G�G� �I�-�-�$)�5�5�.�-����� sZ�!B8�7C?�8>C:�6C?�8C:�:C?�?D:�$D:�F)�(G*�):G&�#G*�%G&�&G*�*%Hc��K�|jdk�r�|j�r�|j�d|jz��|�d|j|���zt|j|j ��dz����d{V��}|�t|t��r>|j� |pd��|j �d���d{V���n|jdks |jd krA|j� d |j��|j �d���d{V��n� t!j|����d{V���d ��� ��}nJ#t($r=|j� d ��|j �d���d{V��Yn<wxYw|jD]}|�|���d{V���|jdkr|j���|jr'|j�d��|j�d{V��|jdkrs|�d|jjd����d{V�� t4j�|��n#t($rYnwxYw|����d{V��|j�d��dS)z-Read packets by polling the Engine.IO server.rRzSending polling GET request to r��r�N�*Connection refused by the server, abortingr�r��6Unexpected status code %s in server response, abortingr�r�z'Unexpected packet from server, aborting�"Waiting for write loop task to endrFrT�Exiting read loop task)r;r�r9r�r�r�r��maxr�r�r=r>r:rArWr�rr�r�r�r<r�r�rXrY�TRANSPORT_ERRORrrr^r_)r&r�r�r�s rr�zAsyncClient._read_loop_pollings������j�K�'�'�D�,@�'� �K� � �1�D�M�A� C� C� C��(�(��t�}�t�'>�'>�'@�'@�@��D�.��0A�B�B�Q�F�)�H�H�H�H�H�H�H�H�A��y�J�q�#�.�.�y�� �#�#��E�E�G�G�G��j�n�n�T�*�*�*�*�*�*�*�*�*���x�#�~�~���S���� �#�#�%9�:;�(�D�D�D��j�n�n�T�*�*�*�*�*�*�*�*�*�� ��O�1�6�6�8�8�^�^�^�^�^�^�4K�4K��5�5�������� � � �� �#�#�=�?�?�?��j�n�n�T�*�*�*�*�*�*�*�*�*���  ���� �y� 0� 0���*�*�3�/�/�/�/�/�/�/�/�/�/�3�j�K�'�'�D�,@�'�6 � � '� �K� � �A� B� B� B��&� &� &� &� &� &� &� &� �:�� $� $��%�%��d�k�9�U�&�L�L� L� L� L� L� L� L� L� ��-�4�4�T�:�:�:�:��� � � ��� �����+�+�-�-� � � � � � � � � ���1�2�2�2�2�2s&�9AE:�:AG�G�I>�> J � J c���K�|jdk�r�d} tj|j���|j|jz����d{V��}t|jttf��s�|j � d|j tjjtjjfvrdnt|j ��t|j����|j�d���d{V���n�|j}n�#tj$r>|j � d��|j�d���d{V��Y�nJtjj$r=|j �d��|j�d���d{V��Yn�t0$rR}|j �dt|����|j�d���d{V��Yd}~n�d}~wwxYw t3j|� ��}n_#t0$rR}|j �d t|����|j�d���d{V��Yd}~n/d}~wwxYw|�|���d{V��|jdk���|jr'|j �d ��|j�d{V��|jdkrs|�d |jjd ����d{V�� t@j!�"|��n#tF$rYnwxYw|�$���d{V��|j �d��dS)z5Read packets from the Engine.IO WebSocket connection.rRNr�z'Server sent %s packet data %s, abortingr]z*Server has stopped communicating, abortingz4Read loop: WebSocket connection was closed, abortingz1Unexpected error receiving packet: "%s", abortingr�z0Unexpected error decoding packet: "%s", abortingrrFrTr)%r;r �wait_forr\r�r�r�r=rLr>r�r9r:�typer�� WSMsgTyperV�CLOSINGrArWr�r��ServerDisconnectedErrorr�r�rrNr�r�rXrYrrrr^r<r_)r&r�r�r�s rr�z AsyncClient._read_loop_websocket0sA�����j�K�'�'��A� �!�*��G�O�O�%�%� �.��1B�B�D�D�D�D�D�D�D�D�D��"�!�&�3��,�7�7���K�'�'�A�#$�6�g�.?�.E�.5�.?�.G�.I�$I�$I��� ���[�[�#�a�f�+�+� 7�7�7� �*�.�.��.�.�.�.�.�.�.�.�.���F�����'� � � �� �#�#�@�B�B�B��j�n�n�T�*�*�*�*�*�*�*�*�*����,�D� � � �� � � �J�L�L�L��j�n�n�T�*�*�*�*�*�*�*�*�*���� � � �� � � �G���F�F�����j�n�n�T�*�*�*�*�*�*�*�*�*����������  ����  ��m�1�5�5�5����� � � �� � � �F��A���P�P�P��j�n�n�T�*�*�*�*�*�*�*�*�*����������  ���� �&�&�s�+�+� +� +� +� +� +� +� +�M�j�K�'�'�P � � '� �K� � �A� B� B� B��&� &� &� &� &� &� &� &� �:�� $� $��%�%��d�k�9�U�&�L�L� L� L� L� L� L� L� L� ��-�4�4�T�:�:�:�:��� � � ��� �����+�+�-�-� � � � � � � � � ���1�2�2�2�2�2sX�C,D�D�A G>�A G>�# G>�,AG9�9G>�H� I4�"AI/�/I4�L � L-�,L-c��ZK�|jdk�rt|j|j��dz}d} t j|j���|���d{V��g}nM#|jjtj f$r|j � d��Y�nvtj $rY�newxYw|dgkr|j� ��g}nq |�|j�����n#|jj$rYn1wxYw|d�$|dd�}|j� ��n�p|s�n�|jdkr�t#j|���}|�d |j|���d d i|j� ���d{V��}|D]}|j� ���|�t/|t0��r|j �|pd ���n|jdks |jdkr(|j �d|j��d|_n�n� |D]�}|jr3|j�|������d{V��n2|j�|������d{V��|j� ����nA#t@j!j"tFtHf$r|j �%d��YnwxYw|jdk��|j �%d��dS)zhThis background task sends packages to the server as they are pushed to the send queue. rRr�Nzpacket queue is empty, abortingT�����r*)r��POSTz Content-Typez text/plain)r�rDr�r�r�r�r�z5Write loop: WebSocket connection was closed, abortingzExiting write loop task)&r;rr�r�r rrA�getrlr�r9r�r�� task_doner�� get_nowaitr[rr�r�r�r�r�r=r>r:r�r��binaryr\� send_bytesr�r�r�r �BrokenPipeError�OSErrorr�)r&r�r�r�r�r�s rr�zAsyncClient._write_loopgs������j�K�'�'��$�,�d�.?�@�@�1�D�G��G� �!(�!1�$�*�.�.�2B�2B�G�!L�!L�L�L�L�L�L�L�M�����J�$�g�&:�;� � � �� �!�!�"C�D�D�D����)� � � ��� �����4�&� � �� �$�$�&�&�&���������t�z�'<�'<�'>�'>�?�?�?�?���:�+�����������r�{�*�")�#�2�#�,��� �,�,�.�.�.���� ���%��2�2��O�G�4�4�4���,�,��D�M���� � �+�\�:� �0�-�2�2�2�2�2�2�2�2��#�+�+�C��J�(�(�*�*�*�*��9� �1�c� 2� 2�9��K�'�'��I�I�K�K�K���8�c�>�>�Q�X��_�_��K�'�'�)=�>?�h�H�H�H�+/�D�(�� &5� �&�/�/���:�A�"&�'�"4�"4�S�Z�Z�\�\�"B�"B�B�B�B�B�B�B�B�B�"&�'�"2�"2�3�:�:�<�<�"@�"@�@�@�@�@�@�@�@�� �,�,�.�.�.�.� /��  �1�I�'��2�����K�$�$�#�$�$�$��E� ����o�j�K�'�'�z � ���2�3�3�3�3�3s<�3A#�#5B-�B-�,B-�,D�D�D�9B K�;L�L)NNr')FN)r)NNN)�__name__� __module__� __qualname__�__doc__rrFrIrPrrergr@rpr_r}r�r�r�rMr�rXr�r�r�� __classcell__)rws@rr#r#-s��������#�#�H���;?�$/�./�./�./�./�` &� &� &� J� J� J�����4 >� >� >�,�,�,�,���� ���(�(�(�(�(� � � �:%�:%�:%�xq�q�q�f/�/�/�(I�I�I�37������,;�;�;�z(3�(3�(3�T53�53�53�nA4�A4�A4�A4�A4�A4�A4rr#)r r6r�r2r�� ImportError�rrrrr1�setr�r!� BaseClientr#r rr�<module>rs������ � � � � � � � �������N�N�N�N�������G�G�G����������������������������� �� �����&�&�&�*{ 4�{ 4�{ 4�{ 4�{ 4�+�(�{ 4�{ 4�{ 4�{ 4�{ 4s ��!�!
Memory