
    i8#                     H    d dl Z d dlmZ d dlmZmZmZ  G d d          ZdS )    N)AsyncClient)SocketIOErrorTimeoutErrorDisconnectedErrorc                       e Zd ZdZeZd Zi dddddfdZed             Z	ed	             Z
dd
ZddZddZd Zd Zd ZdS )AsyncSimpleClienta+  A Socket.IO client.

    This class implements a simple, yet fully compliant Socket.IO web client
    with support for websocket and long-polling transports.

    The positional and keyword arguments given in the constructor are passed
    to the underlying :func:`socketio.AsyncClient` object.
    c                     || _         || _        d | _        d| _        t	          j                    | _        d| _        t	          j                    | _        g | _	        d S )N/F)
client_argsclient_kwargsclient	namespaceasyncioEventconnected_event	connectedinput_eventinput_buffer)selfargskwargss      G/usr/local/lib/python3.11/dist-packages/socketio/async_simple_client.py__init__zAsyncSimpleClient.__init__   sQ    #&}"=??    Nr
   z	socket.io   c           	      h   K    j         rt          d          | _        g  _         j                                           j         j        i  j         _	         j	        
                     j                   fd            } j	        
                     j                   fd            }	 j	        
                     j                   fd            }
 j	                            d j                   fd            } j	                            |||||g||           d	{V  d	S )
aH  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 namespace: The namespace to connect to as a string. If not
                          given, the default namespace ``/`` is used.
        :param socketio_path: The endpoint where the Socket.IO server is
                              installed. The default value is appropriate for
                              most cases.
        :param wait_timeout: How long the client should wait for the
                             connection. The default is 5 seconds.

        Note: this method is a coroutine.
        zAlready connectedr   c                  H    d _          j                                         d S )NTr   r   setr   s   r   connectz*AsyncSimpleClient.connect.<locals>.connectD   s%    !DN $$&&&&&r   c                  :     j                                          d S N)r   clearr!   s   r   
disconnectz-AsyncSimpleClient.connect.<locals>.disconnectI   s     &&(((((r   c                  H    d _          j                                         d S )NFr   r!   s   r   __disconnect_finalz5AsyncSimpleClient.connect.<locals>.__disconnect_finalM   s%    "DN $$&&&&&r   *c                 t    j                             | g|           j                                         d S r$   )r   appendr   r    )eventr   r   s     r   on_eventz+AsyncSimpleClient.connect.<locals>.on_eventR   s;    $$e^d^444  """""r   )headersauth
transports
namespacessocketio_pathwait_timeoutN)r   RuntimeErrorr   r   r   r%   client_classr   r   r   r,   onr"   )r   urlr.   r/   r0   r   r2   r3   r"   r&   $_AsyncSimpleClient__disconnect_finalr-   s   `           r   r"   zAsyncSimpleClient.connect   s     B > 	42333"   'd'5!%!35 5 
		T^		4	4	' 	' 	' 	' 
5	4	' 
		T^		4	4	) 	) 	) 	) 
5	4	) 
		T^		4	4	' 	' 	' 	' 
5	4	' 
t~	6	6	# 	# 	# 	# 
7	6	# k!!t
!{-% " ' ' 	' 	' 	' 	' 	' 	' 	' 	' 	'r   c                 R    | j         r| j                             | j                  ndS )zThe session ID received from the server.

        The session ID is not guaranteed to remain constant throughout the life
        of the connection, as reconnections can cause it to change.
        N)r   get_sidr   r!   s    r   sidzAsyncSimpleClient.sid\   s(     7;kKt{""4>222tKr   c                 F    | j         r| j                                         ndS )zThe name of the transport currently in use.

        The transport is returned as a string and can be one of ``polling``
        and ``websocket``.
         )r   	transportr!   s    r   r>   zAsyncSimpleClient.transporte   s$     +/+=t{$$&&&2=r   c                    K   	 | j                                          d{V  | j        st                      	 | j                            ||| j                   d{V S # t          $ r Y nw xY wn)a?  Emit an event to the server.

        :param event: The event name. It can be any string. The event names
                      ``'connect'``, ``'message'`` and ``'disconnect'`` are
                      reserved and should not be used.
        :param data: The data to send to the server. Data can be of
                     type ``str``, ``bytes``, ``list`` or ``dict``. To send
                     multiple arguments, use a tuple where each element is of
                     one of the types indicated above.

        Note: this method is a coroutine.

        This method schedules the event to be sent out and returns, without
        actually waiting for its delivery. In cases where the client needs to
        ensure that the event was received, :func:`socketio.SimpleClient.call`
        should be used instead.
        TNr   )r   waitr   r   r   emitr   r   )r   r,   datas      r   rA   zAsyncSimpleClient.emitn   s      $	&++---------> *')))![--eT8< . H H H H H H H H H    	s   'A! !
A.-A.<   c                    K   	 | j                                          d{V  | j        st                      	 | j                            ||| j        |           d{V S # t          $ r  t          $ r Y nw xY wy)a  Emit an event to the server and wait for a response.

        This method issues an emit and waits for the server to provide a
        response or acknowledgement. If the response does not arrive before the
        timeout, then a ``TimeoutError`` exception is raised.

        :param event: The event name. It can be any string. The event names
                      ``'connect'``, ``'message'`` and ``'disconnect'`` are
                      reserved and should not be used.
        :param data: The data to send to the server. Data can be of
                     type ``str``, ``bytes``, ``list`` or ``dict``. To send
                     multiple arguments, use a tuple where each element is of
                     one of the types indicated above.
        :param timeout: The waiting timeout. If the timeout is reached before
                        the server acknowledges the event, then a
                        ``TimeoutError`` exception is raised.

        Note: this method is a coroutine.
        TN)r   timeout)	r   r@   r   r   r   callr   r   r   )r   r,   rB   rE   s       r   rF   zAsyncSimpleClient.call   s      (	&++---------> *')))![--eT8<6= . ? ? ? ? ? ? ? ? ?         	s   (A" "A98A9c                 
  K   | j         s	 t          j        | j                                        |           d{V  n!# t          j        $ r t                      w xY w| j        st                      	 t          j        | j                                        |           d{V  n!# t          j        $ r t                      w xY w| j        	                                 | j         | j         
                    d          S )a  Wait for an event from the server.

        :param timeout: The waiting timeout. If the timeout is reached before
                        the server acknowledges the event, then a
                        ``TimeoutError`` exception is raised.

        Note: this method is a coroutine.

        The return value is a list with the event name as the first element. If
        the server included arguments with the event, they are returned as
        additional list elements.
        )rE   Nr   )r   r   wait_forr   r@   r   r   r   r   r%   pop)r   rE   s     r   receivezAsyncSimpleClient.receive   s`      # 	%%&t';'@'@'B'B/68 8 8 8 8 8 8 8 8 8 8' % % %"nn$%> *')))%&t'7'<'<'>'>/68 8 8 8 8 8 8 8 8 8 8' % % %"nn$%""$$$ # 	%  $$Q'''s   3? A63B* *Cc                 v   K   | j         r/| j                                         d{V  d| _        d| _         dS dS )zODisconnect from the server.

        Note: this method is a coroutine.
        NF)r   r   r&   r!   s    r   r&   zAsyncSimpleClient.disconnect   sT      
 > 	#+((*********DK"DNNN	# 	#r   c                 
   K   | S r$    r!   s    r   
__aenter__zAsyncSimpleClient.__aenter__   s      r   c                 >   K   |                                   d {V  d S r$   )r&   )r   exc_typeexc_valexc_tbs       r   	__aexit__zAsyncSimpleClient.__aexit__   s.      oor   r$   )NrC   )__name__
__module____qualname____doc__r   r5   r   r"   propertyr;   r>   rA   rF   rJ   r&   rN   rS   rM   r   r   r   r      s          L   *,$4 #;#$?' ?' ?' ?'B L L XL > > X>   8   B( ( ( (:# # #           r   r   )r   socketior   socketio.exceptionsr   r   r   r   rM   r   r   <module>r[      sz                 N N N N N N N N N NP  P  P  P  P  P  P  P  P  P r   