
    i-                         d dl Z d dlZd dlZd dlZd dlZddlmZ ddlmZ  ej        d          Z	g Z
d Zda G d d          ZdS )	    N   )base_namespace)packetzsocketio.clientc                     t           dd         D ]}|j                                         t          t                    rt	          | |          S t          j        | |          S )zSIGINT handler.

    Notify any clients that are in a reconnect loop to abort. Other
    disconnection tasks are handled at the engine.io level.
    N)reconnecting_clients_reconnect_abortsetcallableoriginal_signal_handlersignaldefault_int_handler)sigframeclients      ?/usr/local/lib/python3.11/dist-packages/socketio/base_client.pysignal_handlerr      sj     'qqq) & &##%%%%'(( 6&sE222 )#u555    c                       e Zd Zg dZej        j        Z	 	 	 	 dd
Zd ZddZ	d Z
d ZddZd Zd Zd Zd Zd Zd Zd Zd Zd	S )
BaseClient)connectconnect_error
disconnect__disconnect_finalTr   r            ?FdefaultNc
                 @   |	rSt           Lt          j                    t          j                    k    r$t	          j        t          j        t                    a || _        || _        || _	        || _
        || _        |	| _        |
}|	|d<   |                    dd           }|||d<   |dk    rt          j        | _        n |dk    rddlm} |j        | _        n|| _        ||| j        _        ||d<    |                                 di || _        | j                            d	| j                   | j                            d
| j                   | j                            d| j                   t7          |t8                    s|| _        nt<          | _        | j        j        t@          j!        k    rv|r%| j        "                    t@          j#                   n$| j        "                    t@          j$                   | j        %                    tA          j&                               d | _'        d | _(        d | _)        d | _*        g | _+        d | _,        d | _-        d| _.        i | _/        g | _0        i | _1        i | _2        i | _3        d | _4        d | _5        d | _6        d | _7        d S )Nhandle_sigintengineio_loggerloggerr   msgpackr   )msgpack_packetjsonr   messager   F )8r   	threadingcurrent_threadmain_threadr   SIGINTr   reconnectionreconnection_attemptsreconnection_delayreconnection_delay_maxrandomization_factorr   popr   Packetpacket_class r"   MsgPackPacketr#   _engineio_client_classeioon_handle_eio_connect_handle_eio_message_handle_eio_disconnect
isinstanceboolr    default_loggerlevelloggingNOTSETsetLevelINFOERROR
addHandlerStreamHandlerconnection_urlconnection_headersconnection_authconnection_transportsconnection_namespacessocketio_pathsid	connected
namespacesfailed_namespaceshandlersnamespace_handlers	callbacks_binary_packet_connect_event_reconnect_taskr   )selfr*   r+   r,   r-   r.   r    
serializerr#   r   kwargsengineio_optionsr   r"   s                 r   __init__zBaseClient.__init__&   s   
  	D4<(**i.C.E.EEE&,mFM4B'D 'D#(%:""4&<#$8!*!,9)*../@$GG&)8X&"" &D9$$(((((( . <D *D%)D"'+V$04..00DD3CDDIt7888It7888L$"=>>>&$'' 		@ DKK(DK{ GN22 8K((6666K((777&&w'<'>'>???""&#%)"%'"!!#"$""# $r   c                     dS )NFr%   rU   s    r   is_asyncio_basedzBaseClient.is_asyncio_basedi   s    ur   c                 @     pd fd}||S  ||           dS )a  Register an event handler.

        :param event: The event name. It can be any string. The event names
                      ``'connect'``, ``'message'`` and ``'disconnect'`` are
                      reserved and should not be used. The ``'*'`` event name
                      can be used to define a catch-all event handler.
        :param handler: The function that should be invoked to handle the
                        event. When this parameter is not given, the method
                        acts as a decorator for the handler function.
        :param namespace: The Socket.IO namespace for the event. If this
                          argument is omitted the handler is associated with
                          the default namespace. A catch-all namespace can be
                          defined by passing ``'*'`` as the namespace.

        Example usage::

            # as a decorator:
            @sio.on('connect')
            def connect_handler():
                print('Connected!')

            # as a method:
            def message_handler(msg):
                print('Received message: ', msg)
                sio.send( 'response')
            sio.on('message', message_handler)

        The arguments passed to the handler function depend on the event type:

        - The ``'connect'`` event handler does not take arguments.
        - The ``'disconnect'`` event handler does not take arguments.
        - The ``'message'`` handler and handlers for custom event names receive
          the message payload as only argument. Any values returned from a
          message handler will be passed to the client's acknowledgement
          callback function if it exists.
        - A catch-all event handler receives the event name as first argument,
          followed by any arguments specific to the event.
        - A catch-all namespace event handler receives the namespace as first
          argument, followed by any arguments specific to the event.
        - A combined catch-all namespace and catch-all event handler receives
          the event name as first argument and the namespace as second
          argument, followed by any arguments specific to the event.
        /c                 N    j         vr
i j         <   | j                  <   | S N)rO   )handlerevent	namespacerU   s    r   set_handlerz"BaseClient.on.<locals>.set_handler   s2    --+-i(.5DM)$U+Nr   Nr%   )rU   rb   ra   rc   rd   s   `` ` r   r6   zBaseClient.onl   sX    X $		 	 	 	 	 	 	 ?Gr   c                      t                    dk    rWt                    dk    rDt          d                   r/                      d         j                  d                   S  fd}|S )a  Decorator to register an event handler.

        This is a simplified version of the ``on()`` method that takes the
        event name from the decorated function.

        Example usage::

            @sio.event
            def my_event(data):
                print('Received data: ', data)

        The above example is equivalent to::

            @sio.on('my_event')
            def my_event(data):
                print('Received data: ', data)

        A custom namespace can be given as an argument to the decorator::

            @sio.event(namespace='/test')
            def my_event(data):
                print('Received data: ', data)
        r   r   c                 B      j         | j        gR i |           S r`   )r6   __name__)ra   argsrW   rU   s    r   rd   z%BaseClient.event.<locals>.set_handler   s2    Awtww/A$AAA&AA'JJJr   )lenr
   r6   rg   )rU   rh   rW   rd   s   ``` r   rb   zBaseClient.event   s    0 t99>>c&kkQ..8DG3D3D. -47747+,,T!W555K K K K K K K r   c                    t          |t          j                  st          d          |                                 |                                k    rt          d          |                    |            || j        |j        <   dS )zRegister a namespace handler object.

        :param namespace_handler: An instance of a :class:`Namespace`
                                  subclass that handles all the event traffic
                                  for a namespace.
        zNot a namespace instancez+Not a valid namespace class for this clientN)r:   r   BaseClientNamespace
ValueErrorr\   _set_clientrP   rc   )rU   namespace_handlers     r   register_namespacezBaseClient.register_namespace   s     +(<> > 	97888  ""&7&H&H&J&JJJJKKK%%d+++ 	 1 ;<<<r   c                 :    | j                             |pd          S )a   Return the ``sid`` associated with a connection.

        :param namespace: The Socket.IO namespace. If this argument is omitted
                          the handler is associated with the default
                          namespace. Note that unlike previous versions, the
                          current version of the Socket.IO protocol uses
                          different ``sid`` values per namespace.

        This method returns the ``sid`` for the requested namespace as a
        string.
        r^   )rM   get)rU   rc   s     r   get_sidzBaseClient.get_sid   s     ""9#3444r   c                 4    | j                                         S )zReturn the name of the transport used by the client.

        The two possible values returned by this function are ``'polling'``
        and ``'websocket'``.
        )r5   	transportr[   s    r   rt   zBaseClient.transport   s     x!!###r   c                    d }|| j         v rU|| j         |         v r| j         |         |         }n|| j        vr(d| j         |         v r| j         |         d         }|g|R }ndd| j         v r[|| j         d         v r| j         d         |         }|g|R }n2|| j        vr)d| j         d         v r| j         d         d         }||g|R }||fS N*)rO   reserved_events)rU   rb   rc   rh   ra   s        r   _get_event_handlerzBaseClient._get_event_handler   s	    %%i000-	259d2224=333-	237~~~DM!!c***-,U3!)D))d2224=----,S1y0400}r   c                 t    d }|| j         v r| j         |         }nd| j         v r| j         d         }|g|R }||fS rv   )rP   )rU   rc   rh   ra   s       r   _get_namespace_handlerz!BaseClient._get_namespace_handler  s[     ///-i8GGD+++-c2G%%%D}r   c                     |pd}|| j         vrdt          j        d          i| j         |<   t          | j         |         d                   }|| j         |         |<   |S )z/Generate a unique identifier for an ACK packet.r^   r   r   )rQ   	itertoolscountnext)rU   rc   callbackids       r   _generate_ack_idzBaseClient._generate_ack_id  sc    $	DN**)*IOA,>,>(?DN9%$.+A.//(0y!"%	r   c                     t                      r`   NotImplementedErrorr[   s    r   r7   zBaseClient._handle_eio_connect      !###r   c                     t                      r`   r   )rU   datas     r   r8   zBaseClient._handle_eio_message!  r   r   c                     t                      r`   r   )rU   reasons     r   r9   z!BaseClient._handle_eio_disconnect$  r   r   c                     t                      r`   r   r[   s    r   r4   z!BaseClient._engineio_client_class'  r   r   )	Tr   r   r   r   Fr   NT)NNr`   )rg   
__module____qualname__rx   engineioClientr   rY   r\   r6   rb   ro   rr   rt   ry   r{   r   r7   r8   r9   r4   r%   r   r   r   r   !   s#       - - -O_#F@A>?DM*.A% A% A% A%F  6 6 6 6p! ! !F   5 5 5 5$ $ $  4    $ $ $$ $ $$ $ $$ $ $ $ $r   r   )r}   r>   r   r&   r   r2   r   r   	getLoggerr<   r   r   r   r   r%   r   r   <module>r      s                          ""#455 6 6 6  G$ G$ G$ G$ G$ G$ G$ G$ G$ G$r   