�
���g�e � �` � d dl Z d dlZddlmZ ddlmZ ddlmZ G d� dej � � ZdS )� N� )�base_client)�
exceptions)�packetc � � e Zd ZdZi dddddddfd�Zd� Zdd �Zd d
�Zd!d�Zd
� Z d� Z
d� Zd"d�Zd� Z
d� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd� ZdS )#�ClientaM A Socket.IO client.
This class implements a fully compliant Socket.IO web client with support
for websocket and long-polling transports.
:param reconnection: ``True`` if the client should automatically attempt to
reconnect to the server after an interruption, or
``False`` to not reconnect. The default is ``True``.
:param reconnection_attempts: How many reconnection attempts to issue
before giving up, or 0 for infinite attempts.
The default is 0.
:param reconnection_delay: How long to wait in seconds before the first
reconnection attempt. Each successive attempt
doubles this delay.
:param reconnection_delay_max: The maximum delay between reconnection
attempts.
:param randomization_factor: Randomization amount for each delay between
reconnection attempts. The default is 0.5,
which means that each delay is randomly
adjusted by +/- 50%.
: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 serializer: The serialization method to use when transmitting
packets. Valid values are ``'default'``, ``'pickle'``,
``'msgpack'`` and ``'cbor'``. Alternatively, a subclass
of the :class:`Packet` class with custom implementations
of the ``encode()`` and ``decode()`` methods can be
provided. Client and server must use compatible
serializers.
: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 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.
The Engine.IO configuration supports the following settings:
:param request_timeout: A timeout in seconds for requests. The default is
5 seconds.
:param http_session: an initialized ``requests.Session`` 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 websocket_extra_options: Dictionary containing additional keyword
arguments passed to
``websocket.create_connection()``.
:param engineio_logger: To enable Engine.IO 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
``engineio_logger`` is ``False``.
Nz socket.ioTr Fc
�V � | j rt j d� � �|| _ || _ || _ || _ || _ || _ |��t t | j � � � � � �
t | j � � � � � � � � � }d|v r|� d� � t! |� � dk rdg}nt# |t$ � � r|g}|| _ i | _ | j �| j � � � | _ n| j � � � | � | j � � }
| � | j � � } | j � |
|||�� � n�# t4 j j $ r�}| j D ]I}
| � d|
t! |j � � dk r
|j d n|j d � � �J| r*| � � � | j j d k rY d}~dS t j |j d � � |�d}~ww xY w|r�| j � |�
� � r_| j � � � t | j � � t | j � � k rn| j � |�
� � �_t | j � � t | j � � k r(| � � � t j d� � �d| _ dS )
a0
Connect to a Socket.IO server.
:param url: The URL of the Socket.IO server. It can include custom
query string parameters if required by the server. If a
function is provided, the client will invoke it to obtain
the URL each time a connection or reconnection is
attempted.
:param headers: A dictionary with custom headers to send with the
connection request. If a function is provided, the
client will invoke it to obtain the headers dictionary
each time a connection or reconnection is attempted.
:param auth: Authentication data passed to the server with the
connection request, normally a dictionary with one or
more string key/value pairs. If a function is provided,
the client will invoke it to obtain the authentication
data each time a connection or reconnection is attempted.
: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 namespaces: The namespaces to connect as a string or list of
strings. If not given, the namespaces that have
registered event handlers are connected.
:param socketio_path: The endpoint where the Socket.IO server is
installed. The default value is appropriate for
most cases.
:param wait: if set to ``True`` (the default) the call only returns
when all the namespaces are connected. If set to
``False``, the call returns as soon as the Engine.IO
transport is connected, and the namespaces will connect
in the background.
:param wait_timeout: How long the client should wait for the
connection. The default is 1 second. This
argument is only considered when ``wait`` is set
to ``True``.
:param retry: Apply the reconnection logic if the initial connection
attempt fails. The default is ``False``.
Example usage::
sio = socketio.Client()
sio.connect('http://localhost:5000')
zAlready connectedN�*r �/)�headers�
transports�
engineio_path�
connect_errorr � connected��timeoutz(One or more namespaces failed to connectT)!r r �ConnectionError�connection_url�connection_headers�connection_auth�connection_transports�connection_namespaces�
socketio_path�list�set�handlers�keys�union�namespace_handlers�remove�len�
isinstance�str�
namespaces�_connect_event�eio�create_event�clear�_get_real_value�connect�engineio�_trigger_event�args�_handle_reconnect�state�wait�
disconnect)�self�urlr �authr
r$ r r0 �wait_timeout�retry�real_url�real_headers�exc�ns �_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/socketio/client.pyr* zClient.connectI sR � �\ �>� B��,�-@�A�A�A�!���")���#���%/��"�%/��"�*������c�$�-�"4�"4�"6�"6�7�7�=�=��D�+�0�0�2�2�3�3�5� 5� 6� 6�J��j� � ��!�!�#�&�&�&��:���!�#�#�!�U�
��
�
�C�
(�
(� &�$��J�%/��"������&�"&�(�"7�"7�"9�"9�D�����%�%�'�'�'��'�'��(;�<�<���+�+�D�,C�D�D��
C��H���X�|�(2�+8�
�
:�
:�
:�
:�� �"�2� C� C� C��/�
G�
G���#�#�#�Q�#&�s�x�=�=�1�#4�#4�C�H�Q�K�K�#�(�1�+�G� G� G� G� �
��&�&�(�(�(��8�>�[�0�0��F�F�F�F�F��,�S�X�a�[�9�9�s�B����� C���� � @��%�*�*�<�*�@�@�
��#�)�)�+�+�+��t��'�'�3�t�/I�+J�+J�J�J�� �%�*�*�<�*�@�@�
� �4�?�#�#�s�4�+E�'F�'F�F�F����!�!�!� �0�>�@� @� @� ����s �<F �I�/A7I�, I�Ic �� � | j � � � | � d� � | j s| j j dk r�GdS | j � � � | j j dk rdS �t)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.
Tr r N)r&