
    i8#                     @    S SK r S SKJr  S SKJrJrJr   " S S5      rg)    N)AsyncClient)SocketIOErrorTimeoutErrorDisconnectedErrorc                       \ rS rSrSr\rS r0 SSSSS4S jr\	S	 5       r
\	S
 5       rSS jrSS jrSS jrS rS rS rSrg)AsyncSimpleClient   a  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                     Xl         X l        S U l        SU l        [        R
                  " 5       U l        SU l        [        R
                  " 5       U l        / U l	        g )N/F)
client_argsclient_kwargsclient	namespaceasyncioEventconnected_event	connectedinput_eventinput_buffer)selfargskwargss      Y/home/admin/cozy_coffee/venv/lib/python3.13/site-packages/socketio/async_simple_client.py__init__AsyncSimpleClient.__init__   sG    #&}}"==?    Nr   z	socket.io   c           
        ^ #    T R                   (       a  [        S5      eUT l        / T l        T R                  R                  5         T R                  " T R                  0 T R                  D6T l	        T R                  R                  T R                  S9U 4S j5       nT R                  R                  T R                  S9U 4S j5       n	T R                  R                  T R                  S9U 4S j5       n
T R                  R                  ST R                  S9U 4S j5       nT R                  R                  XX4U/UUS9I S	h  vN   g	 N7f)
ap  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   > ST l         T R                  R                  5         g )NTr   r   setr   s   r   connect*AsyncSimpleClient.connect.<locals>.connectD   s    !DN  $$&r   c                  :   > T R                   R                  5         g N)r   clearr#   s   r   
disconnect-AsyncSimpleClient.connect.<locals>.disconnectI   s      &&(r   c                  H   > ST l         T R                  R                  5         g )NFr!   r#   s   r   __disconnect_final5AsyncSimpleClient.connect.<locals>.__disconnect_finalM   s    "DN  $$&r   *c                 v   > TR                   R                  U /UQ5        TR                  R                  5         g r'   )r   appendr   r"   )eventr   r   s     r   on_event+AsyncSimpleClient.connect.<locals>.on_eventR   s/    $$e^d^4  "r   )headersauth
transports
namespacessocketio_pathwait_timeoutN)r   RuntimeErrorr   r   r   r(   client_classr   r   r   r1   onr$   )r   urlr4   r5   r6   r   r8   r9   r$   r)   $_AsyncSimpleClient__disconnect_finalr2   s   `           r   r$   AsyncSimpleClient.connect   s?    B >>233" ''5!%!3!35 
		T^^		4	' 
5	' 
		T^^		4	) 
5	) 
		T^^		4	' 
5	' 
t~~	6	# 
7	# kk!!t!{-% " ' 	' 	's   EEEEc                 r    U R                   (       a%  U R                   R                  U R                  5      $ 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   sidAsyncSimpleClient.sid\   s(     7;kkt{{""4>>2KtKr   c                 \    U R                   (       a  U R                   R                  5       $ 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   rF   AsyncSimpleClient.transporte   s"     +/++t{{$$&=2=r   c                   #     U R                   R                  5       I Sh  vN   U R                  (       d
  [        5       e U R                  R                  XU R                  S9I Sh  vN $  NL N! [         a     Of = fM  7f)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.
Nr   )r   waitr   r   r   emitr   r   )r   r1   datas      r   rJ   AsyncSimpleClient.emitn   s     $ &&++--->>'))![[--e8< . H H H	 .H   sE   BA.B'A2 )A0*A2 -B0A2 2
A?<B>A??Bc                 "  #     U R                   R                  5       I Sh  vN   U R                  (       d
  [        5       e U R                  R                  XU R                  US9I Sh  vN $  NM N! [         a    e [         a     Of = fM  7f)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.
N)r   timeout)	r   rI   r   r   r   callr   r   r   )r   r1   rK   rN   s       r   rO   AsyncSimpleClient.call   s     ( &&++--->>'))![[--e8<6= . ? ? ?	 .?      sE   BA/B(A3 *A1+A3 .B1A3 3B
B	B

Bc                 Z  #    U R                   (       d   [        R                  " U R                  R	                  5       US9I Sh  vN   U R                  (       d
  [        5       e [        R                  " U R                  R	                  5       US9I Sh  vN   U R                  R                  5         U R                   (       d  M  U R                   R                  S5      $  N! [        R
                   a    [        5       ef = f Np! [        R
                   a    [        5       ef = f7f)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.
)rN   Nr   )r   r   wait_forr   rI   r   r   r   r   r(   pop)r   rN   s     r   receiveAsyncSimpleClient.receive   s     ##%&&t';';'@'@'B/68 8 8 >>'))%&&t'7'7'<'<'>/68 8 8 ""$ ###   $$Q''8'' %"n$%
8'' %"n$%s^   D+0C% C#C% 
D+&0D	 DD	 +D+D+#C% %DD+D	 	D((D+c                    #    U R                   (       a1  U R                  R                  5       I Sh  vN   SU l        SU l         gg N7f)z?Disconnect from the server.

Note: this method is a coroutine.
NF)r   r   r)   r#   s    r   r)   AsyncSimpleClient.disconnect   s:     
 >>++((***DK"DN *s   /AAAc                    #    U $ 7fr'    r#   s    r   
__aenter__AsyncSimpleClient.__aenter__   s
     s   c                 @   #    U R                  5       I S h  vN   g  N7fr'   )r)   )r   exc_typeexc_valexc_tbs       r   	__aexit__AsyncSimpleClient.__aexit__   s     oos   )r   r   r   r   r   r   r   r   r'   )N<   )__name__
__module____qualname____firstlineno____doc__r   r;   r   r$   propertyrB   rF   rJ   rO   rT   r)   rZ   r`   __static_attributes__rY   r   r   r   r      ss     L *,$4 #;#$?'B L L > >8B(:# r   r   )r   socketior   socketio.exceptionsr   r   r   r   rY   r   r   <module>rl      s       N NP  P r   