
    Iis                         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   )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      ;/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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-   aO  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.
: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_basedR   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 R'                  5       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create_queuequeuegetattr)r%   urlheadersr;   engineio_pathvalid_transports	transports          r   connectAsyncClient.connectU   sH    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	E57E A E5	E.E.A(E5>E3?E5%E+(E5*E++	E5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%   rL   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(   )r7   rM   r   rN   CLOSEr=   put_trigger_eventreasonCLIENT_DISCONNECTcurrent_transportwscloserG   r   r   remover8   _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                 Z    [         R                  " 5       n[         R                  Ul        U$ )zCreate a queue object.)r   Queue
QueueEmptyEmpty)r%   qs     r   r<   AsyncClient.create_queue   s    MMO$$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                  (       dQ  U R                  (       a?  U R                  R                  (       d#  U R                  R                  5       I S h  vN   g g g g  N7fN)superr`   external_httphttpclosedr^   )r%   	__class__s    r   r`   AsyncClient._reset   sO     !!yy!1!1iioo''' "2y "'s   A)A7,A5-	A7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rx   )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=rS   rD   FrU   r   r*   )/aiohttpr5   error_get_engineio_urlbase_urlinfo_send_request_get_url_timestamprequest_timeoutr9   r:   r`   r   ConnectionErrorstatusjsonClientErrorformatr   Payloadreaddecoder8   packetspacket_typer   OPENrL   r   r   intping_intervalping_timeoutr\   r7   r   r   appendrY   _receive_packetr;   _connect_websocketrg   _write_loopwrite_loop_task_read_loop_pollingrG   )	r%   r?   r@   rA   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        0 nUR                  5        HW  u  pxUR                  5       S	:X  d  M  [        UR                  S
5       V	s/ s H  oR                  SS5      PM     sn	5      nX'	   O   U R                  R                  R                  U5        SU R                   0n
U R"                  (       d5  [$        R&                  " 5       nSUl        [$        R*                  Ul        XS'   UR/                  U R0                  R3                  S0 5      5        X*S'   U
R/                  U R0                  5         U R                  R4                  " X@R7                  5       -   40 U
D6I Sh  vN nU(       Ga<  [F        RH                  " [F        RJ                  SS9RM                  5       n URO                  U5      I Sh  vN    URU                  5       I Sh  vN RV                  n[F        RH                  " US9nURX                  [F        RZ                  :w  d  URV                  S:w  a  U R                  RA                  S5        g[F        RH                  " [F        R\                  5      RM                  5       n URO                  U5      I Sh  vN   SU l/        U R                  R                  S5        GOI URU                  5       I Sh  vN RV                  n[F        RH                  " US9nURX                  [F        R`                  :w  a  [B        RD                  " S5      eU R                  R                  S[S        URV                  5      -   5        URV                  S   U l        URV                  S   U l1        [e        URV                  S   5      S-  U l3        [e        URV                  S    5      S-  U l4        SU l/        S!U l5        [l        Rn                  Rq                  U 5        U Rs                  S"SS#9I Sh  vN   Xl:        U Rw                  U Rx                  5      U l=        U Rw                  U R|                  5      U l?        gs  sn	f  GN! [         R8                  R:                  [         R8                  R<                  [         R8                  R>                  4 a;    U(       a  U R                  RA                  S5         g[B        RD                  " S5      ef = f GN! [P         a/  nU R                  RA                  S[S        U5      5         SnAgSnAff = f GNC! [P         a/  nU R                  RA                  S[S        U5      5         SnAgSnAff = f GN! [P         a/  nU R                  RA                  S[S        U5      5         SnAgSnAff = f GN! [P         a'  n[B        RD                  " S[S        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 cookiez; =r   r   sslr@   z*WebSocket upgrade failed: connection errorzConnection errorproberK   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   rS   rD   rU   )@r   r5   r   r   r   r   r   r{   r|   ClientSessionitemslowerdictsplit
cookie_jarupdate_cookiesr   
ssl_verifyr   create_default_contextcheck_hostname	CERT_NONEverify_modeupdatewebsocket_extra_optionspop
ws_connectr   client_exceptionsWSServerHandshakeErrorServerConnectionErrorClientConnectionErrorr6   r   r   r   rN   PINGencodesend_str	Exceptionr:   receiverL   r   PONGUPGRADEr\   r   r   r   r   r   r7   r   r   r   rY   r]   rg   r   r   _read_loop_websocketrG   )r%   r?   r@   rA   websocket_urlupgradecookiesheadervaluer   extra_optionsssl_contextr]   r   er   r   s                    r   r   AsyncClient._connect_websocket"  st    ?KK=>..s/:<88KK2]BDGWtxx//MG)MKK5EG 99		 0 0--/DI $]]_MF||~)8=D8IJ8If\\#q)8IJLO - 			++G4"D$8$89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 K&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
CZ,0T& T#T& 
9Z,V8 V5V8 W7 1W42W7  BZ,X6 %X3&X6 *$Z,Y5 "Y2#Y5 1D!Z,Z)AZ,#T& &A3V2Z,V22Z,5V8 8
W1%W,'Z,,W11Z,4W7 7
X0%X+&Z,+X00Z,3X6 6
Y/ %Y*%Z,*Y//Z,2Y5 5
Z&?"Z!!Z&&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>messageTrU   N)ra   rZ   z%Received unexpected packet of type %s)r   lenr   packet_namesr5   r   r9   rL   bytesrO   rY   r   rM   rN   r   rW   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.rS   NzSending packet %s data %sr   )r7   r=   rX   r5   r   r   r   r   r9   rL   r   )r%   r   s     r   rM   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@   rL   r   r   )r@   rL   r   z+HTTP %s request to %s failed with error %s.)r{   r|   r   r   r>   r   r   ClientTimeoutr   r   TimeoutErrorr5   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.rV   FNTr   r   z async handler errorrD   c                  0   >#    TR                   T   " T 6 $ 7frx   )handlers)re   eventr%   s   r   async_handler1AsyncClient._trigger_event.<locals>.async_handler  s     #}}U3T::s   z handler error)r   r   r   iscoroutinefunctionrg   task_reference_holderaddadd_done_callbackdiscard	TypeErrorr   CancelledErrorr5   	exception)r%   r   re   rf   rV   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.rS   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   FrU   Exiting read loop task)r7   r   r5   r   r   r   r   maxr   r   r9   r:   r6   r=   rX   r   r   r   r   r   r8   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.rS   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   FrU   r  )%r7   r   wait_forr]   r   r   r   r9   rL   r:   r   r5   r6   typer   	WSMsgTyperW   CLOSINGr=   rX   r   r   ServerDisconnectedErrorr   r   r   rN   r   r   rY   rZ   r  r   r   r_   r8   r`   )r%   r   r   r   s       r   r    AsyncClient._read_loop_websocket0  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                 P  #    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                  [        R                  4 a    U R                  R                  S5         Mg  [        R                   a     M}  f = f! U R                  R                   a     GMf  f = f GN G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.
rS   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)&r7   r  r   r   r   r  r=   getrp   r   r5   r   r  	task_doner   
get_nowaitr\   r   r   r   r   r   r   r9   r:   r6   r   r   binaryr]   
send_bytesr   r   r   r  BrokenPipeErrorOSErrorr   )r%   r   r   r   r   r   s         r   r   AsyncClient._write_loopg  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JJ$$g&:&:; !!"CD))   ::++ 2( C@11II'2 KK$$#$ s   7N&2K ,K-K 2%N&)L1 BN&MB3N&AM M	1M :M;"M N&0N&K AL.N&L.*N&-L..N&1MN&MN&M M AN#N&"N##N&)r   r\   r{   r   r   r=   rG   r   r7   r;   r   r   r]   )NNz	engine.io)FN)r   )NNN)__name__
__module____qualname____firstlineno____doc__r   rD   rH   rP   r   rg   rj   r<   ru   r`   r   r   r   r   rM   r   rY   r   r   r   __static_attributes____classcell__)r}   s   @r   r    r    -   s    #H ;?$/./`	&	J4>,(
:%xqf/(I 37,;z(3T53nA4 A4r   r    )r   r2   r   r.   r   ImportError r   r   r   r   r-   setr   r   
BaseClientr    r#   r   r   <module>r0     sg      
       
  &*{	4+(( {	4K  Gs   A AA