
    iu                         S SK r S SKJr  S SKrS SKrS SKr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K	Jr  Sq\" 5       rS	 r " S
 S\
R$                  5      rg! \ a    Sr NDf = f)    N)SimpleCookie   )base_client)
exceptions)packet)payloadFc                  @    S n [         R                  " U " 5       5        g)z6SIGINT handler.

Disconnect all active async clients.
c                    #    [         R                  S S   H2  n U R                  5       (       d  M  U R                  5       I S h  vN   M4     [        R
                  " 5        Vs/ s H  o[        R                  " 5       Ld  M  UPM      nnU H  nUR                  5         M     [        R                  " USS06I S h  vN   [        R                  " 5       R                  5         g  Ns  snf  N/7f)Nreturn_exceptionsT)r   connected_clientsis_asyncio_based
disconnectasyncio	all_taskscurrent_taskcancelgatherget_running_loopstop)ctasktaskss      R/home/admin/cozy_coffee/venv/lib/python3.13/site-packages/engineio/async_client.py_handler&async_signal_handler.<locals>._handler   s     ..q1A!!##lln$$ 2
 #*"3"3"5 )"5$%%':("5 )DKKM nne<t<<<  "'') %) 	=s:   *C.C.C%C.#C'C'4C.<C,=)C.'C.Nr   ensure_future)r   s    r   async_signal_handlerr      s    
* (*%    c                      ^  \ rS rSrSrS r  SS jrS rS rSS jr	S r
SS	 jrS
 rS rS rU 4S jrS rS rS rS rS r  SS jrS rS rS rS rSrU =r$ )AsyncClient/   a  An Engine.IO client for asyncio.

This class implements a fully compliant Engine.IO web client with support
for websocket and long-polling transports, compatible with the asyncio
framework on Python 3.5 or newer.

: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 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 request_timeout: A timeout in seconds for requests. The default is
                        5 seconds.
:param http_session: an initialized ``aiohttp.ClientSession`` 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 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.
:param websocket_extra_options: Dictionary containing additional keyword
                                arguments passed to
                                ``aiohttp.ws_connect()``.
:param timestamp_requests: If ``True`` a timestamp is added to the query
                           string of Socket.IO requests as a cache-busting
                           measure. Set to ``False`` to disable.
c                     g)NT selfs    r   r   AsyncClient.is_asyncio_basedU   s    r   c                   #    U R                   (       ao  [        (       dd  [        R                  " 5       [        R                  " 5       :X  a8   [
        R                  " 5       R                  [        R                  [        5        SqU R                  S:w  a  [        S5      eSS/nUbC  [!        U["        5      (       a  U/nU Vs/ s H  nXe;   d  M
  UPM     nnU(       d  [        S5      eU=(       d    UU l        ['        U S	U R$                  S
   -   5      " X=(       d    0 U5      I Sh  vN $ ! [         a    U R                  R                  S5         Nf = fs  snf  N47f)a9  Connect to an Engine.IO server.

:param url: The URL of the Engine.IO server. It can include custom
            query string parameters if required by the server.
:param headers: A dictionary with custom headers to send with the
                connection request.
: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 engineio_path: The endpoint where the Engine.IO server is
                      installed. The default value is appropriate for
                      most cases.

Note: this method is a coroutine.

Example usage::

    eio = engineio.Client()
    await eio.connect('http://localhost:5000')
zSignal handler is unsupportedTdisconnectedz%Client is not in a disconnected statepolling	websocketNzNo valid transports provided	_connect_r   )handle_sigintasync_signal_handler_set	threadingcurrent_threadmain_threadr   r   add_signal_handlersignalSIGINTr   NotImplementedErrorloggerwarningstate
ValueError
isinstancestr
transportsgetattr)r&   urlheadersr<   engineio_pathvalid_transports	transports          r   connectAsyncClient.connectX   s8    0 &>&>((*i.C.C.EEE((*==MM#79 $( ::'DEE%{3!*c**(\
5? <Z	&: $ZJ < !?@@$8(8T;1C#CDB/ / 	/ ' E##$CDE<
/sJ   A	E 7D. A E 	EEAE )E*E .%EE E	E c                 \   #    U R                   (       a  U R                   I Sh  vN   gg N7f)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.

Note: this method is a coroutine.
N)read_loop_taskr%   s    r   waitAsyncClient.wait   s'      %%%% %s   !,*,c                    #    U R                  [        R                  " [        R                  US95      I Sh  vN   g N7f)a  Send a message to the server.

:param data: The data to send to the server. Data can be of type
             ``str``, ``bytes``, ``list`` or ``dict``. If a ``list``
             or ``dict``, the data will be serialized as JSON.

Note: this method is a coroutine.
dataN)_send_packetr   PacketMESSAGE)r&   rK   s     r   sendAsyncClient.send   s*      fnn4 HIIIs   6A >A c                   #    U R                   S:X  Ga  U R                  [        R                  " [        R                  5      5      I Sh  vN   U R
                  R                  S5      I Sh  vN   SU l         U R                  SU=(       d    U R                  R                  SS9I Sh  vN   U R                  S:X  a"  U R                  R                  5       I Sh  vN   U(       d  U R                  I Sh  vN   SU l          [        R                  R!                  U 5        U R%                  5       I Sh  vN   g N N N Ne NL! ["         a     N/f = f N7f)	zDisconnect from the server.

:param abort: If set to ``True``, do not wait for background tasks
              associated with the connection to end.

Note: this method is a coroutine.
	connectedNdisconnectingr   F	run_asyncr+   r)   )r8   rL   r   rM   CLOSEqueueput_trigger_eventreasonCLIENT_DISCONNECTcurrent_transportwscloserF   r   r   remover9   _reset)r&   abortrZ   s      r   r   AsyncClient.disconnect   s     ::$##FMM&,,$?@@@**..&&&(DJ%%l&,&M0M0M05 & 7 7 7 %%4ggmmo%%))))'DJ--44T: kkm A&7 &)  s   AE
D<"E-D>.<E*E +1EEE7E8EE #E6E7E>E EEE
EEEEc                 :    [         R                  " U" U0 UD65      $ )a5  Start a background task.

This is a utility function that applications can use to start a
background task.

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

The return value is a ``asyncio.Task`` object.
r   )r&   targetargskwargss       r   start_background_task!AsyncClient.start_background_task   s     $$VT%<V%<==r   c                 J   #    [         R                  " U5      I Sh  vN $  N7f)zKSleep for the requested amount of time.

Note: this method is a coroutine.
N)r   sleep)r&   secondss     r   rj   AsyncClient.sleep   s     
 ]]7++++s   #!#c                 .    [         R                  " U0 UD6$ )zCreate a queue object.)r   Queue)r&   re   rf   s      r   create_queueAsyncClient.create_queue   s    }}d-f--r   c                 "    [         R                  $ )z\Return the queue empty exception raised by queues created by the
``create_queue()`` method.
)r   
QueueEmptyr%   s    r   get_queue_empty_exception%AsyncClient.get_queue_empty_exception   s     !!!r   c                 ,    [         R                  " 5       $ )zCreate an event object.)r   Eventr%   s    r   create_eventAsyncClient.create_event   s    }}r   c                   >#    [         TU ]  5           U R                  R                  5         U R                  R	                  5         M7  ! U R
                   a     Of = fU R                  (       dR  U R                  (       a@  U R                  R                  (       d$  U R                  R                  5       I S h  vN    g g g g 7fN)
superr`   rW   
get_nowait	task_donequeue_emptyexternal_httphttpclosedr^   )r&   	__class__s    r   r`   AsyncClient._reset   s     

%%'

$$&  ## !!yy!1!1iioo''' "2y "s5   C4A
 C
ACAAC:B=;	Cc                 j   U R                   (       a  U R                   R                  (       d   [        R                  " 5       nUR	                  5       (       a*  UR                  U R                   R                  5       5        g UR                  U R                   R                  5       5        g g g !    g = frz   )r   r   r   get_event_loop
is_runningr   r^   run_until_complete)r&   loops     r   __del__AsyncClient.__del__   sx    99TYY----/??$$&&tyy'89++DIIOO,=> .9s   AB. )B. .B2c                   #    [         c  U R                  R                  S5        gU R                  XS5      U l        U R                  R                  SU R                  -   5        U R                  SU R                  U R                  5       -   UU R                  S9I Sh  vN nUb  [        U[        5      (       a7  U R                  5       I Sh  vN   [        R                  " U=(       d    S5      eUR                  S:  d  UR                  S	:  aa  U R                  5       I Sh  vN    UR                  5       I Sh  vN n[        R                  " S
R#                  UR                  5      U5      e [$        R&                  " UR)                  5       I Sh  vN R+                  S5      S9nUR.                  S   nUR0                  [2        R4                  :w  a  [        R                  " S5      eU R                  R                  S[        UR6                  5      -   5        UR6                  S   U l        UR6                  S   U l        [=        UR6                  S   5      S-  U l        [=        UR6                  S   5      S-  U l         SU l!        U =R                  SU R8                  -   -  sl        SU l"        [F        RH                  RK                  U 5        U RM                  SSS9I Sh  vN   UR.                  SS  H  nU RO                  U5      I Sh  vN   M     SU R:                  ;   a0  SU RP                  ;   a   U RS                  XU5      I Sh  vN (       a  gU RU                  U RV                  5      U l,        U RU                  U RZ                  5      U l.        g GN GN GN GNk! [         R                    a    Sn GNf = f GN2! [,         a    [        R                  " S5      Sef = f GN N N7f)z<Establish a long-polling connection to the Engine.IO server.Nz3aiohttp not installed -- cannot make HTTP requests!r*   z!Attempting polling connection to GET)r?   timeoutz Connection refused by the server   ,  z,Unexpected status code {} in server responseutf-8encoded_payloadzUnexpected response from serverr   z"OPEN packet not returned by serverz!Polling connection accepted with sidupgradespingInterval     @@pingTimeout&sid=rR   rC   FrT   r   r+   )/aiohttpr6   error_get_engineio_urlbase_urlinfo_send_request_get_url_timestamprequest_timeoutr:   r;   r`   r   ConnectionErrorstatusjsonClientErrorformatr   Payloadreaddecoder9   packetspacket_typer   OPENrK   r   r   intping_intervalping_timeoutr\   r8   r   r   appendrY   _receive_packetr<   _connect_websocketrg   _write_loopwrite_loop_task_read_loop_pollingrF   )	r&   r>   r?   r@   rargpopen_packetpkts	            r   _connect_pollingAsyncClient._connect_polling   sd    ?KK * +..s9M<t}}LM$$4==4#:#:#<<g(( % * * 9
1c**++-,,779 988c>QXX_++-FFHn ,,>EEHH"$ $	=qvvx0G0G1 A
 iil""fkk1,,46 6/#k6F6F2GG	I##E*#((4 !1!1.!ABVK 0 0 ?@6I!*488++ 
%%,,T2!!)u!===99QR=C&&s+++ ! $--'K4??,J,,S=III#99$:J:JK"88##%c*    $&&  2@ 	=,,138<=	=$ 	> , Js   BO9N! /O9N$AO9&N''O9,N- ?N* N- 0O95#O O
O .D>O9,O2-*O9O5=O9O7AO9$O9'O9*N- -OO9OO9
O "O//O95O97O9c           	      ~  #    [         c  U R                  R                  S5        gU R                  XS5      nU R                  (       a3  U R                  R                  SU-   5        SnUSU R                  -   -  nO&SnX@l        U R                  R                  SU-   5        U R                  b  U R                  R                  (       a  [         R                  " 5       U l        UR                  5        H|  u  pgUR                  5       S	:X  d  M  [        X&   5      nU R                  R                  R                  UR                  5        V	V
s0 s H  u  pXR                  _M     sn
n	5        X&	   O   S
[         R                   " U R"                  S90nU R$                  (       d5  [&        R(                  " 5       nSUl        [&        R,                  Ul        XS'   UR1                  U R2                  R5                  S0 5      5        X+S'   UR1                  U R2                  5         U R                  R6                  " X@R9                  5       -   40 UD6I Sh  vN nU(       Ga<  [H        RJ                  " [H        RL                  SS9RO                  5       n URQ                  U5      I Sh  vN    URW                  5       I Sh  vN RX                  n[H        RJ                  " US9nURZ                  [H        R\                  :w  d  URX                  S:w  a  U R                  RC                  S5        g[H        RJ                  " [H        R^                  5      RO                  5       n URQ                  U5      I Sh  vN   SU l0        U R                  R                  S5        GOI URW                  5       I Sh  vN RX                  n[H        RJ                  " US9nURZ                  [H        Rb                  :w  a  [D        RF                  " S5      eU R                  R                  S[U        URX                  5      -   5        URX                  S   U l        URX                  S   U l2        [g        URX                  S   5      S-  U l4        [g        URX                  S   5      S-  U l5        SU l0        SU l6        [n        Rp                  Rs                  U 5        U Ru                  S SS!9I Sh  vN   Xl;        U Ry                  U Rz                  5      U l>        U Ry                  U R~                  5      U l@        gs  sn
n	f  GN! [         R:                  R<                  [         R:                  R>                  [         R:                  R@                  4 a;    U(       a  U R                  RC                  S5         g[D        RF                  " S5      ef = f GN! [R         a/  nU R                  RC                  S[U        U5      5         SnAgSnAff = f GND! [R         a/  nU R                  RC                  S[U        U5      5         SnAgSnAff = f GN! [R         a/  nU R                  RC                  S[U        U5      5         SnAgSnAff = f GN! [R         a'  n[D        RF                  " S[U        U5      -   5      eSnAff = f GN7f)"z?Establish or upgrade to a WebSocket connection with the server.Nzaiohttp package not installedFr+   z Attempting WebSocket upgrade to Tr   z#Attempting WebSocket connection to cookier   )ws_closesslr?   z*WebSocket upgrade failed: connection errorzConnection errorproberJ   z7WebSocket upgrade failed: unexpected send exception: %sz7WebSocket upgrade failed: unexpected recv exception: %sencoded_packetz(WebSocket upgrade failed: no PONG packetz WebSocket upgrade was successfulzUnexpected recv exception: zno OPEN packetz#WebSocket connection accepted with r   r   r   r   r   rR   rC   rT   )Ar   r6   r   r   r   r   r   r   r   ClientSessionitemslowerr   
cookie_jarupdate_cookiesvalueClientWSTimeoutr   
ssl_verifyr   create_default_contextcheck_hostname	CERT_NONEverify_modeupdatewebsocket_extra_optionspop
ws_connectr   client_exceptionsWSServerHandshakeErrorServerConnectionErrorClientConnectionErrorr7   r   r   r   rM   PINGencodesend_str	Exceptionr;   receiverK   r   PONGUPGRADEr\   r   r   r   r   r   r8   r   r   r   rY   r]   rg   r   r   _read_loop_websocketrF   )r&   r>   r?   r@   websocket_urlupgradeheaderr   ckkmextra_optionsssl_contextr]   r   er   r   s                     r   r   AsyncClient._connect_websocket.  sw    ?KK=>..s/:<88KK2]BDGWtxx//MG)MKK5EG 99		 0 0--/DI %]]_MF||~)!'/2		$$33,.HHJ7JDAQZJ79O - w..8L8LMO446K).K&&)mmK##.%  	t3377	2FG#*i T99:	Eyy++ 7 7 99L=JL LB fkk8??AAkk!n$$::<'-- --q1C&++-W1D##>@fnn-446Akk!n$$ &1D"KK?@<::<'-- !--q9K&&&++5 001ABBKK5K<L<L8MMO"''.DH',,Z8DM!$[%5%5n%E!F!OD #K$4$4]$C Dv MD%0D"$DJ))006%%i5%AAA#99$:J:JK"88%%'m 8&L))@@))??))??A 	E ##@B 001CDD	E % ##MF 	 ( ##MF 	 % ##MF 	 ( < 001CF:< <<  BsC  D	Z=?Z=T.&B>Z=%0T7 T4T7 9Z=W	 (W)W	 .X XX BZ=!Y 5Y6Y :$Z=Z 2Z3Z D!Z="Z:#AZ=4T7 7A3W*Z=,WZ=W	 	
X%W=8Z==XZ=X 
Y%X<7Z=<YZ=Y 
Z %Y;6Z=;Z  Z=Z 
Z7"Z22Z77Z=c                   #    UR                   [        [        R                  5      :  a  [        R                  UR                      OSnU R                  R                  SU[        UR                  [        5      (       d  UR                  OS5        UR                   [        R                  :X  a$  U R                  SUR                  SS9I Sh  vN   gUR                   [        R                  :X  aG  U R                  [        R                  " [        R                  UR                  5      5      I Sh  vN   gUR                   [        R                  :X  a-  U R!                  SU R"                  R$                  S9I Sh  vN   gUR                   [        R&                  :X  a  gU R                  R)                  S	UR                   5        g N N NO7f)
z(Handle incoming packets from the server.UNKNOWNzReceived packet %s data %s<binary>messageTrT   N)ra   rZ   z%Received unexpected packet of type %s)r   lenr   packet_namesr6   r   r:   rK   bytesrN   rY   r   rL   rM   r   rV   r   rZ   SERVER_DISCONNECTNOOPr   )r&   r   packet_names      r   r   AsyncClient._receive_packet  sN     V%8%8!99 ))#//:?H 	(+&sxx77CHHZ	I ??fnn,%%iT%JJJ__+##FMM&++sxx$HIII__,//)-)F)F " H H H__+KKE!oo/ KIHs9   CGG	A$G2G3A
G=G>AGGGc                 H  #    U R                   S:w  a  gU R                  R                  U5      I Sh  vN   U R                  R	                  S[
        R                  UR                     [        UR                  [        5      (       d  UR                  5        gS5        g Nm7f)z(Queue a packet to be sent to the server.rR   NzSending packet %s data %sr   )r8   rW   rX   r6   r   r   r   r   r:   rK   r   )r&   r   s     r   rL   AsyncClient._send_packet  sz     ::$jjnnS!!!'0&sxx77CHH	I >H	I 	"s   0B"B A.B"c           	      >  #    U R                   b  U R                   R                  (       a  [        R                  " 5       U l         [	        U R                   UR                  5       5      n U R                  (       d#  U" X#U[        R                  " US9SS9I S h  vN $ U" X#U[        R                  " US9S9I S h  vN $  N& N! [        R                  [        R                  4 a2  nU R                  R                  SXU5        [        U5      s S nA$ S nAff = f7f)N)totalF)r?   rK   r   r   )r?   rK   r   z+HTTP %s request to %s failed with error %s.)r   r   r   r   r=   r   r   ClientTimeoutr   r   TimeoutErrorr6   r   r;   )r&   methodr>   r?   bodyr   http_methodexcs           r   r   AsyncClient._send_request  s      99		 0 0--/DIdii8	??(t#11@eM M M )t#11@B B B	MB ##W%9%9: 	KKJ##/s8O	sf   A'D*/C C C DC ;C<C ?D C C $D('DDDDDc                 \  ^ ^^#    UR                  SS5      nSnTT R                  ;   Ga  [        R                  " T R                  T   5      SL a{  U(       aV  T R                  " T R                  T   /TQ76 n[
        R                  U5        UR                  [
        R                  5        U$   T R                  T   " T6 I Sh  vN nU$ U(       aO  UUU 4S	 jnT R	                  U5      n[
        R                  U5        UR                  [
        R                  5        U$   T R                  T   " T6 nU$ U$  Nt! [         a6    TS:X  a.  [        T5      S:X  a  T R                  T   " 5       I Sh  vN  s $ e f = f! [        R                   a     U$   T R                  R                  TS-   5        TS:X  a   g U$ = f! [         a.    TS:X  a&  [        T5      S:X  a  T R                  T   " 5       n U$ e f = f!   T R                  R                  TS
-   5        TS:X  a   g U$ = f7f)zInvoke an event handler.rU   FNTr   r   z async handler errorrC   c                  0   >#    TR                   T   " T 6 $ 7frz   )handlers)re   eventr&   s   r   async_handler1AsyncClient._trigger_event.<locals>.async_handler  s     #}}U3T::s   z handler error)r   r  inspectiscoroutinefunctionrg   task_reference_holderaddadd_done_callbackdiscard	TypeErrorr   r   CancelledErrorr6   	exception)r&   r  re   rf   rU   retr   r  s   ```     r   rY   AsyncClient._trigger_event  s6    JJ{E2	DMM!**4==+?@DH55dmmE6J =7;=D)--d3**+@+H+HIK)	&(,e(<d(C"CCX 
5 ;  55mDD)--d3**+@+H+HIK)	&"&--"6"=C 
s
Y #D( &$4$'IN .2]]5-A-C'C'C C %& #11 D 
C)--e6L.LM I- $) .> 
  ) &$4$'IN '+mmE&:&< 
 !&&)--e6F.FG I- $) . 
s   B)H,0D< D:D< 
AH,$G 6H,:D< <6E<2E53E<8E? 9H,:E<<E? ?G H,%G ;H,3G;6G> 7H,9G;;G> >&H)$H,c                   #    U R                   S:X  Ga  U R                  (       Ga  U R                  R                  SU R                  -   5        U R                  SU R                  U R                  5       -   [        U R                  U R                  5      S-   S9I Sh  vN nUb  [        U[        5      (       aH  U R                  R                  U=(       d    S5        U R                  R                  S5      I Sh  vN   OUR                  S:  d  UR                  S	:  aJ  U R                  R                  S
UR                  5        U R                  R                  S5      I Sh  vN   O [         R"                  " UR%                  5       I Sh  vN R'                  S5      S9nUR*                   H  nU R-                  U5      I Sh  vN   M     U R                   S:X  a  U R                  (       a  GM  U R                  (       a/  U R                  R                  S5        U R                  I Sh  vN   U R                   S:X  ae  U R/                  SU R0                  R2                  SS9I Sh  vN    [4        R6                  R9                  U 5        U R;                  5       I Sh  vN   U R                  R                  S5        g GN* GN GNg GN@! [(         aD    U R                  R                  S5        U R                  R                  S5      I Sh  vN     GM*  f = f GN[ N N! [(         a     Nf = f N7f)z-Read packets by polling the Engine.IO server.rR   zSending polling GET request to r      r   N*Connection refused by the server, abortingr   r   6Unexpected status code %s in server response, abortingr   r   z'Unexpected packet from server, aborting"Waiting for write loop task to endr   FrT   Exiting read loop task)r8   r   r6   r   r   r   r   maxr   r   r:   r;   r7   rW   rX   r   r   r   r   r   r9   r   r   rY   rZ   TRANSPORT_ERRORr   r   r_   r`   )r&   r   r   r   s       r   r   AsyncClient._read_loop_polling  s    jjK'D,@,@,@KK1DMMAC((t}}t'>'>'@@D..0A0ABQF ) H HA yJq#..##EEGjjnnT***xx#~S## %9:;((DjjnnT***OO1668^4K4K5  yy**3/// !1 jjK'D,@,@,@6 KKAB&&&&::$%%dkk99U & L L L--44T: ++-12GH +
 + 6D ##=?jjnnT***	 0 'L  s   BL>KAL>=K>A)L>'K(L>.#K KK '#L>
L%)L>7;L>2L(3<L>/L*0L>5L, L>'L<(!L>L>L>K AL"LL"L>!L""L>(L>*L>,
L96L>8L99L>c                   #    U R                   S:X  Gal  Sn [        R                  " U R                  R	                  5       U R
                  U R                  -   S9I Sh  vN n[        UR                  [        [        45      (       d  U R                  R                  SUR                  [        R                  R                   [        R                  R"                  4;   a  SO[        UR                  5      [        UR                  5      5        U R$                  R'                  S5      I Sh  vN   OMUR                  n [2        R4                  " US	9nU R7                  U5      I Sh  vN   U R                   S:X  a  GMl  U R8                  (       a/  U R                  R/                  S5        U R8                  I Sh  vN   U R                   S:X  ae  U R;                  SU R<                  R>                  SS9I Sh  vN    [@        RB                  RE                  U 5        U RI                  5       I Sh  vN   U R                  R/                  S5        g GN GN'! [        R(                   aD    U R                  R                  S5        U R$                  R'                  S5      I Sh  vN     GM.  [        R*                  R,                   aD    U R                  R/                  S5        U R$                  R'                  S5      I Sh  vN     GM  [0         aU  nU R                  R/                  S[        U5      5        U R$                  R'                  S5      I Sh  vN     SnAGM  SnAff = f! [0         aU  nU R                  R/                  S
[        U5      5        U R$                  R'                  S5      I Sh  vN     SnAGMI  SnAff = f GNi GN GN! [F         a     GNf = f GN7f)z5Read packets from the Engine.IO WebSocket connection.rR   Nr  z'Server sent %s packet data %s, abortingr^   z*Server has stopped communicating, abortingz4Read loop: WebSocket connection was closed, abortingz1Unexpected error receiving packet: "%s", abortingr   z0Unexpected error decoding packet: "%s", abortingr  r   FrT   r  )%r8   r   wait_forr]   r   r   r   r:   rK   r;   r   r6   r7   typer   	WSMsgTyperV   CLOSINGrW   rX   r   r   ServerDisconnectedErrorr   r   r   rM   r   r   rY   rZ   r  r   r   r_   r9   r`   )r&   r   r   r   s       r   r    AsyncClient._read_loop_websocket<  s    jjK'A!**GGOO% ..1B1BBD D "!&&3,77KK''A#$66g.?.?.E.E.5.?.?.G.G.I $I [#aff+	7
 **.....FF"mm15 &&s+++M jjK'P KKAB&&&&::$%%dkk99U & L L L--44T: ++-12aD / '' ##@BjjnnT***,,DD   JLjjnnT***   GF jjnnT***    FAPjjnnT***	
 , 'L  s6  O.AI ICI -I.I 2O.3I  M/ O.(O)O. ;O.;O<<O.8O9O.>O O.0O+1 O.I I AM,$J'%M,*O..AM,LM,
O.	M,AM'MM' O.'M,,O./
O9AO	<N?=O	O.	OO.O.O.
O($O.'O((O.c                 &  #    U R                   S:X  Ga  [        U R                  U R                  5      S-   nSn [        R
                  " U R                  R                  5       U5      I Sh  vN /nUS/:X  a  U R                  R                  5         / nOS  UR                  U R                  R                  5       5        US   c   USS nU R                  R                  5         OMR  U(       d  GOU R                   S:X  Ga  ["        R$                  " US9nU R'                  SU R(                  UR+                  5       S	S
0U R,                  S9I Sh  vN nU H  nU R                  R                  5         M     Ub  [/        U[0        5      (       a%  U R                  R3                  U=(       d    S5        OUR4                  S:  d  UR4                  S:  a.  U R                  R3                  SUR4                  5        SU l        OO U H  nUR8                  (       a2  U R:                  R=                  UR+                  5       5      I Sh  vN   O1U R:                  R?                  UR+                  5       5      I Sh  vN   U R                  R                  5         M     U R                   S:X  a  GM  U R                  RK                  S5        g GN`! U R                  [        R                  4 a    U R                  R                  S5         M]  [        R                   a     Ms  f = f! U R                   a     GMR  f = f GN N N! [@        RB                  RD                  [F        [H        4 a    U R                  RK                  S5         M  f = f7f)zXThis background task sends packages to the server as they are
pushed to the send queue.
rR   r  Nzpacket queue is empty, abortingr*   )r   POSTzContent-Typez
text/plain)r   r?   r   r  r   r   r  z5Write loop: WebSocket connection was closed, abortingzExiting write loop task)&r8   r  r   r   r   r  rW   getr~   r   r6   r   r  r}   r   r|   r\   r   r   r   r   r   r   r:   r;   r7   r   r   binaryr]   
send_bytesr   r   r   r  BrokenPipeErrorOSErrorr   )r&   r   r   r   r   r   s         r   r   AsyncClient._write_loops  s     jjK' $,,d.?.?@1DGG!(!1!1$**..2BG!LLM 4& 

$$&tzz'<'<'>? r{*")#2,

,,.  %%2OOG4,,DMM
+\: 00 - 2 2 #CJJ((* #9
1c 2 2KK''IIK88c>QXX_KK'' )=>?hhH+/D(	 &5&::"&''"4"4SZZ\"BBB"&''"2"23::<"@@@

,,.  'c jjK'z 	23m M$$g&:&:; !!"CD))   ++ 2( C@11II'2 KK$$#$ s   7N2K ,K-K 2%N)L' BNL?B3NAM M	1M :M;"M N0NK ;L$
NL$ N#L$$N'L<7N;L<<NM M AN
NNN)r   r\   r   r   r   rF   r   r8   r<   r   r   r]   )NNz	engine.io)FN)r   )NNN)__name__
__module____qualname____firstlineno____doc__r   rC   rG   rO   r   rg   rj   ro   rs   rw   r`   r   r   r   r   rL   r   rY   r   r   r   __static_attributes____classcell__)r   s   @r   r!   r!   /   s    $J ;?$/-/^	&	J4>,."
(
:%xqf/(I 37,;z(3T53nA4 A4r   r!   )r   http.cookiesr   r  r3   r   r/   r   ImportError r   r   r   r   r.   setr  r   
BaseClientr!   r$   r   r   <module>r6     sm     %   
       
  &*E
4+(( E
4K  Gs   A A%$A%