
    if                     b    S SK r S SKrSSKJr  SSKJr  SSKJr   " S S\R                  5      rg)    N   )base_client)
exceptions)packetc                       \ rS rSrSr0 SSSSSSS4S jrS	 rSS
 jrS S jrS!S jr	S r
S rS rS"S jrS rS rS rS rS rS rS rS rS rS rS rS rS rSrg)#Client
   a  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. This is a process-wide setting, all instantiated
             servers and clients must use the same JSON module.
: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
           	         U R                   (       a  [        R                  " S5      eXl        X l        X0l        X@l        XPl        X`l        Uc  [        [        U R                  R                  5       5      R                  [        U R                  R                  5       5      5      5      nSU;   a  UR                  S5        [!        U5      S:X  a  S/nO[#        U[$        5      (       a  U/nXPl        0 U l        / U l        U R*                  c   U R,                  R/                  5       U l        OU R*                  R1                  5         U R3                  U R                  5      n
U R3                  U R                  5      n U R,                  R5                  XUUS9  U(       Ga	  U R*                  RA                  US
9(       a}  U R*                  R1                  5         [!        U R&                  5      [!        U R(                  5      -   [!        U R                  5      :X  a  O U R*                  RA                  US
9(       a  M}  [        U R&                  5      [        U R                  5      :w  aB  U RC                  5         [        R                  " SSRE                  U R(                  5      -   5      eSU l         g! [6        R                  R                   a  nU R                   HK  nU R9                  SU[!        UR:                  5      S:  a  UR:                  S   OUR:                  S   5        MM     U	(       a/  U R=                  5         U R,                  R>                  S	:X  a   SnAg[        R                  " UR:                  S   5      UeSnAff = f)a  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')
zAlready connectedN*r   /)headers
transportsengineio_pathconnect_errorr   	connectedtimeoutz*One or more namespaces failed to connect: z, T)#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failed_namespaces_connect_eventeiocreate_eventclear_get_real_valueconnectengineio_trigger_eventargs_handle_reconnectstatewait
disconnectjoin)selfurlr   authr   r%   r   r2   wait_timeoutretryreal_urlreal_headersexcns                 L/home/admin/cozy_coffee/venv/lib/python3.13/site-packages/socketio/client.pyr,   Client.connectJ   s   \ >>,,-@AA!")#%/"%/"*c$--"4"4"67==D++00235 6Jj !!#&:!#!U

C(($J%/"!#&"&(("7"7"9D%%'''(;(;<++D,C,CD	CHHX(2+8  : %%**<*@##))+t'#d.D.D*EED6678	 %%**<*@@
 4??#s4+E+E'FF! 00@ii 6 6789 9 / ""22 		C//###Q#&sxx=1#4CHHQK#((1+G 0 &&(88>>[0,,SXXa[9sB		Cs   ?J3 3NBN"$NNc                 $    U R                   R                  5         U R                  S5        U R                  (       d  U R                   R                  S:X  a  MY  gU R                  R                  5         U R                   R                  S:w  a  gM  )zWait until the connection with the server ends.

Client applications can use this function to block the main thread
during the life of the connection.
r   r   N)r(   r2   sleep_reconnect_taskr1   r4   r5   s    r>   r2   Client.wait   sj     HHMMOJJqM''88>>[0   %%'xx~~,     c           	         U=(       d    SnX0R                   ;  a  [        R                  " US-   5      eU R                  R	                  SX5        Ub  U R                  X45      nOSn[        U[        5      (       a  [        U5      nO	Ub  U/nO/ nU R                  U R                  [        R                  UU/U-   US95        g)a  Emit a custom 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.
:param namespace: The Socket.IO namespace for the event. If this
                  argument is omitted the event is emitted to the
                  default namespace.
:param callback: If given, this function will be called to acknowledge
                 the server has received the message. The arguments
                 that will be passed to the function are those provided
                 by the server.

Note: this method is not thread safe. If multiple threads are emitting
at the same time on the same client connection, messages composed of
multiple packets may end up being sent in an incorrect sequence. Use
standard concurrency solutions (such as a Lock object) to prevent this
situation.
r   z is not a connected namespace.zEmitting event "%s" [%s]N)	namespacedataid)r%   r   BadNamespaceErrorloggerinfo_generate_ack_idr#   tupler   _send_packetpacket_classr   EVENT)r5   eventrH   rG   callbackrI   s         r>   emitClient.emit   s    0 $	OO+..<<> >3UF&&y;BB dE"":D6DD$++FLLI274B , H 	IrE   c                 &    U R                  SXUS9  g)a  Send a message to the server.

This function emits an event with the name ``'message'``. Use
:func:`emit` to issue custom event names.

: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 namespace: The Socket.IO namespace for the event. If this
                  argument is omitted the event is emitted to the
                  default namespace.
:param callback: If given, this function will be called to acknowledge
                 the server has received the message. The arguments
                 that will be passed to the function are those provided
                 by the server.
messagerH   rG   rS   N)rT   )r5   rH   rG   rS   s       r>   sendClient.send   s    $ 			)$# 	 	%rE   c                 &  ^^ U R                   R                  5       m/ mUU4S jnU R                  XUUS9  TR                  US9(       d  [        R
                  " 5       e[        TS   5      S:  a  TS   $ [        TS   5      S:X  a  TS   S   $ S$ )a  Emit a custom event to the server and wait for the response.

This method issues an emit with a callback and waits for the callback
to be invoked before returning. If the callback isn't invoked before
the timeout, then a ``TimeoutError`` exception is raised. If the
Socket.IO connection drops during the wait, this method still waits
until the specified timeout.

: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 namespace: The Socket.IO namespace for the event. If this
                  argument is omitted the event is emitted to the
                  default namespace.
: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 not thread safe. If multiple threads are emitting
at the same time on the same client connection, messages composed of
multiple packets may end up being sent in an incorrect sequence. Use
standard concurrency solutions (such as a Lock object) to prevent this
situation.
c                  H   > TR                  U 5        TR                  5         g N)appendr   )r/   callback_argscallback_events    r>   event_callback#Client.call.<locals>.event_callback&  s      & rE   rX   r   r   r   N)r(   r)   rT   r2   r   TimeoutErrorr"   )r5   rR   rH   rG   r   ra   r_   r`   s         @@r>   callClient.call  s    : ..0	! 			%i) 	 	+""7"3))++#&}Q'7#81#<}Q 	(+M!,<(=(Bq!!$		rE   c                     U R                    H0  nU R                  U R                  [        R                  US95        M2     U R
                  R                  5         g)zDisconnect from the server.rG   N)r%   rO   rP   r   
DISCONNECTr(   r3   )r5   r=   s     r>   r3   Client.disconnect2  sO     Ad//!!Q 0 0 1 ! 	rE   c                     U R                   (       a  U R                  5         gU R                  (       a5  U R                  R	                  5         U R                  R                  5         gg)a  Stop the client.

If the client is connected to a server, it is disconnected. If the
client is attempting to reconnect to server, the reconnection attempts
are stopped. If the client is not connected to a server and is not
attempting to reconnect, then this function does nothing.
N)r   r3   rB   _reconnect_abortr   r4   rC   s    r>   shutdownClient.shutdown;  sG     >>OO!!!!%%'  %%' "rE   c                 B    U R                   R                  " U/UQ70 UD6$ )a  Start a background task using the appropriate async model.

This is a utility function that applications can use to start a
background task using the method that is compatible with the
selected async mode.

:param target: the target function to execute.
:param args: arguments to pass to the function.
:param kwargs: keyword arguments to pass to the function.

This function returns an object that represents the background task,
on which the ``join()`` methond can be invoked to wait for the task to
complete.
)r(   start_background_task)r5   targetr/   kwargss       r>   ro   Client.start_background_taskI  s#     xx--fFtFvFFrE   c                 8    U R                   R                  U5      $ )zSleep for the requested amount of time using the appropriate async
model.

This is a utility function that applications can use to put a task to
sleep without having to worry about using the correct call for the
selected async mode.
)r(   rA   )r5   secondss     r>   rA   Client.sleepZ  s     xx~~g&&rE   c                 4    [        U5      (       d  U$ U" 5       $ )zLReturn the actual value, for parameters that can also be given as
callables.)callable)r5   values     r>   r+   Client._get_real_valued  s     LwrE   c                     UR                  5       n[        U[        5      (       a%  U H  nU R                  R	                  U5        M      gU R                  R	                  U5        g)z&Send a Socket.IO packet to the server.N)encoder#   r   r(   rY   )r5   pktencoded_packeteps       r>   rO   Client._send_packetk  sF    nd++$b! % HHMM.)rE   c                 0   U=(       d    SnXR                   ;  a|  U R                  R                  SU S35        U=(       d    0 R                  SU R                  5      U R                   U'   U R                  SUS9  U R                  R                  5         g g )Nr   z
Namespace z is connectedsidr,   rg   )r%   rK   rL   getr   r.   r'   r   r5   rG   rH   s      r>   _handle_connectClient._handle_connectt  s~    $	OO+KKz)MBC*.*")9)9%)JDOOI&	Y?##%	 ,rE   c                 N   U R                   (       d  g U=(       d    SnU R                  SUU R                  R                  5        U R                  SU5        XR                  ;   a  U R                  U	 U R                  (       d"  SU l         U R
                  R                  5         g g )Nr   r3   __disconnect_finalF)r   r.   reasonSERVER_DISCONNECTr%   r(   r3   )r5   rG   s     r>   _handle_disconnectClient._handle_disconnect|  s    ~~$	L) KK99	;0)<'	*"DNHH! rE   c           	      F   U=(       d    SnU R                   R                  SUS   U5        U R                  " US   U/USS  Q76 nUbY  Uc  / nO$[        U[        5      (       a  [        U5      nOU/nU R                  U R                  [        R                  XUS95        g g )Nr   zReceived event "%s" [%s]r   r   )rG   rI   rH   )
rK   rL   r.   r#   rN   r   rO   rP   r   ACK)r5   rG   rI   rH   rs        r>   _handle_eventClient._handle_event  s    $	3T!WiHQ>T!"X>> yAu%%Awsd//

iT 0 C D rE   c                    U=(       d    SnU R                   R                  SU5        S n U R                  U   U   nU R                  U   U	 Ub  U" U6   g g ! [         a    U R                   R	                  S5         N1f = f)Nr   zReceived ack [%s]z$Unknown callback received, ignoring.)rK   rL   	callbacksKeyErrorwarning)r5   rG   rI   rH   rS   s        r>   _handle_ackClient._handle_ack  s    $	,i8	.~~i04H
 y)"-dO    	HKK FG	Hs   A %A?>A?c                    U=(       d    SnU R                   R                  SR                  U5      5        Uc  [        5       nO[	        U[        [
        45      (       d  U4nU R                  " SU/UQ76   U R                  R                  U5        U R                  R                  5         XR                  ;   a  U R                  U	 US:X  a  0 U l        SU l        g g )Nr   z'Connection to namespace {} was rejectedr   F)rK   rL   formatrN   r#   r   r.   r&   r^   r'   r   r%   r   r   s      r>   _handle_errorClient._handle_error  s    $	BII 	<7DD5$-007DOY>>%%i0!'	* DO"DN rE   c                     U R                  XU5      u  pCU(       a   U" U6 $ U R                  X#5      u  pCU(       a  UR                  " U/UQ76 $ g! [         a    US:X  a
  U" USS 6 s $ e f = f)z$Invoke an application event handler.r3   N)_get_event_handler	TypeError_get_namespace_handlertrigger_event)r5   rR   rG   r/   handlers        r>   r.   Client._trigger_event  s     //$G~% 33ID((666   L("D"I..s   A A,*A,c           
         U R                   c  U R                  R                  5       U l         U R                   R                  5         [        R
                  R                  U 5        SnU R                  n UnUS-  nX0R                  :  a  U R                  nX0R                  S[        R                  " 5       -  S-
  -  -  nU R                  R                  SR                  U5      5        U R                   R                  U5      (       a?  U R                  R                  S5        U R                   H  nU R!                  SUS9  M     OzUS-  n U R#                  U R$                  U R&                  U R(                  U R*                  U R                  U R,                  SS	9  U R                  R                  S
5        S U l         [        R
                  R9                  U 5        g ! [0        R2                  [4        4 a     Of = fU R6                  (       aO  XR6                  :  a@  U R                  R                  S5        U R                   H  nU R!                  SUS9  M     M  GM  )Nr      r   z1Connection failed, new attempt in {:.02f} secondszReconnect task abortedr   rg   F)r   r7   r   r%   r   r9   zReconnection successfulz0Maximum reconnection attempts reached, giving up)rk   r(   r)   r*   r   reconnecting_clientsr^   reconnection_delayreconnection_delay_maxrandomization_factorrandomrK   rL   r   r2   r   r.   r,   r   r   r   r   r   rB   r   r   
ValueErrorreconnection_attemptsr!   )r5   attempt_countcurrent_delaydelayr=   s        r>   r0   Client._handle_reconnect  s"     ($(HH$9$9$;D!##%((//5//!EQM22233..!fmmo2E2IJJEKKCJJ $$))%00  !9:33A''(<'J 4QMT00%)%<%<"&"6"6(,(B(B(,(B(B+/+=+=#(  *   !:;'+$ 	((//5 ..
;  ))!%?%??  FH33A''(<'J 4G s   AG$ $H Hc           	      8   U R                   R                  S5        U R                  R                  U l        U R	                  U R
                  5      =(       d    0 nU R                   H0  nU R                  U R                  [        R                  XS95        M2     g)z&Handle the Engine.IO connection event.z Engine.IO connection established)rH   rG   N)rK   rL   r(   r   r+   r   r   rO   rP   r   CONNECT)r5   	real_authr=   s      r>   _handle_eio_connectClient._handle_eio_connect  sx    ;<88<<(()=)=>D"	++Ad//Y 0 = > ,rE   c                    U R                   (       a  U R                   nUR                  U5      (       a  SU l         UR                  [        R                  :X  a2  U R                  UR                  UR                  UR                  5        gU R                  UR                  UR                  UR                  5        ggU R                  US9nUR                  [        R                  :X  a'  U R                  UR                  UR                  5        gUR                  [        R                  :X  a  U R                  UR                  5        gUR                  [        R                  :X  a2  U R                  UR                  UR                  UR                  5        gUR                  [        R                   :X  a2  U R                  UR                  UR                  UR                  5        gUR                  [        R                  :X  d  UR                  [        R"                  :X  a  X l         gUR                  [        R$                  :X  a'  U R'                  UR                  UR                  5        g[)        S5      e)zDispatch Engine.IO messages.N)r}   zUnknown packet type.)_binary_packetadd_attachmentpacket_typer   BINARY_EVENTr   rG   rI   rH   r   rP   r   r   rh   r   rQ   r   
BINARY_ACKCONNECT_ERRORr   r   )r5   rH   r|   s      r>   _handle_eio_messageClient._handle_eio_message  s   %%C!!$''&*#??f&9&99&&s}}cffchhG$$S]]CFFCHHE ( ##4#8C&..0$$S]]CHH=F$5$55''6FLL0""3==#&&#((CFJJ.  AF$7$77OOv'8'88&)#F$8$88""3==#((; !788rE   c                    U R                   R                  S5        U R                  =(       a    U R                  R                  S:H  nU R
                  (       aN  U R                   H0  nU R                  SX15        U(       a  M  U R                  SU5        M2     0 U l        SU l        0 U l        SU l	        SU l
        U(       a3  U R                  (       d!  U R                  U R                  5      U l        ggg)z)Handle the Engine.IO disconnection event.zEngine.IO connection droppedr   r3   r   FN)rK   rL   reconnectionr(   r1   r   r%   r.   r   r   r   rB   ro   r0   )r5   r   will_reconnectr=   s       r>   _handle_eio_disconnectClient._handle_eio_disconnect  s    78**Ltxx~~/L>>__##L!<%~''(<a@ % !DO"DN"$"6"6#'#=#=&&$(D  #7>rE   c                 "    [         R                  $ r]   )r-   r   rC   s    r>   _engineio_client_classClient._engineio_client_class/  s    rE   )r   r'   rk   rB   r   r   r   r   r   r   r   r&   r%   r   r   )NNN)NN)NN<   )r   )__name__
__module____qualname____firstlineno____doc__r,   r2   rT   rY   rd   r3   rl   ro   rA   r+   rO   r   r   r   r   r   r.   r0   r   r   r   r   __static_attributes__ rE   r>   r   r   
   s    >~ $&DT{eeN(*IX%**X(G"'*&"D #"7&+6Z>98($rE   r   )r   r-    r   r   r   
BaseClientr   r   rE   r>   <module>r      s(        f[## frE   