
    if(                     n    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 S\R                  5      rg)	    N   )base_socket)
exceptions)packet)payloadc                   ^    \ rS rSrSrS 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g	)Socket
   zAn Engine.IO socket.c                 2   U R                   R                  5       n U R                  R                  U R                   R                  U R                   R
                  -   S9/nU R                  R                  5         US/:X  a  / $   U R                  R                  SS9nU R                  R                  5         Uc  U R                  R                  S5         U$ UR                  U5        Mh  ! U a    [        R                  " 5       ef = f! U a     U$ f = f)z'Wait for packets to send to the client.)timeoutNF)block)serverget_queue_empty_exceptionqueuegetping_intervalping_timeout	task_doner   
QueueEmptyputappend)selfqueue_emptypacketspkts       L/home/admin/cozy_coffee/venv/lib/python3.13/site-packages/engineio/socket.pypollSocket.poll   s
   kk;;=	*zz~~11DKK4L4LL & N OGJJ  " tfIjjnn5n1

$$&;JJNN4(  s# 	  	*''))	*  s%   AC- AD D -D	DDc           	         UR                   [        [        R                  5      :  a  [        R                  UR                      OSnU R                  R
                  R                  SU R                  U[        UR                  [        5      (       d  UR                  OS5        UR                   [        R                  :X  a  U R                  5         g	UR                   [        R                  :X  aE  U R                  R                  SU R                  UR                  U R                  R                  S9  g	UR                   [        R                   :X  a4  U R#                  [        R$                  " [        R&                  5      5        g	UR                   [        R(                  :X  a0  U R+                  SSU R                  R,                  R.                  S9  g	[0        R2                  " 5       e)
zReceive packet from the client.UNKNOWNz%s: Received packet %s data %s<binary>message	run_asyncFTwaitabortreasonN)packet_typelenr   packet_namesr   loggerinfosid
isinstancedatabytesPONGschedule_pingMESSAGE_trigger_eventasync_handlersUPGRADEsendPacketNOOPCLOSEcloser(   CLIENT_DISCONNECTr   UnknownPacketError)r   r   packet_names      r   receiveSocket.receive#   sI    V%8%8!99 ))#//:?H 	 @ $+0:388U0K0K%/	1 ??fkk) __.KK&&y$((CHH151K1K ' M__.IIfmmFKK01__,JJE"kk00BB  D //11    c                    U R                   (       a  [        R                  " 5       eU R                  (       a  [        R                  " 5       U R                  -
  U R
                  R                  :  a`  U R
                  R                  R                  SU R                  5        U R                  SSU R
                  R                  R                  S9  gg)z2Make sure the client is still responding to pings.z"%s: Client is gone, closing socketFr%   T)closedr   SocketIsClosedError	last_pingtimer   r   r,   r-   r.   r<   r(   PING_TIMEOUTr   s    r   check_ping_timeoutSocket.check_ping_timeout8   s    ;;0022>>		dnn,t{{/G/GGKK##$H$(HH.
 JJE"kk00==  ?rB   c           	      `   U R                  5       (       d  gU R                  R                  U5        U R                  R                  R                  SU R                  [        R                  UR                     [        UR                  [        5      (       d  UR                  5        gS5        g)zSend a packet to the client.Nz%s: Sending packet %s data %sr!   )rJ   r   r   r   r,   r-   r.   r   r+   r)   r/   r0   r1   )r   r   s     r   r8   Socket.sendH   sx    &&((JJNN3 ? $&*=*=coo*N0:388U0K0K	1 &0	1rB   c                 6   UR                  SS5      R                  5       R                  S5       Vs/ s H  nUR                  5       PM     nnUR                  SS5      R                  5       nSU;   aV  XPR                  ;   aG  U R
                  R                  R                  SU R                  U5        [        U SU-   5      " UU5      $ U R                  (       d  U R                  (       a%  [        R                  " [        R                  5      /$  U R                  5       nU$ s  snf ! [         R"                   a[    [$        R&                  " 5       nU R)                  SU R
                  R*                  R,                  S	9  US
   R/                  US   5      ef = f)z2Handle a long-polling GET request from the client.HTTP_CONNECTION ,HTTP_UPGRADEupgradez%%s: Received request to upgrade to %s	_upgrade_F)r&   r(   r      )r   lowersplitstripupgrade_protocolsr   r,   r-   r.   getattr	upgradingupgradedr   r9   r:   r   r   r   sysexc_infor<   r(   TRANSPORT_ERRORwith_traceback)r   environstart_responsesconnections	transportr   excs           r   handle_get_requestSocket.handle_get_requestS   s[    [[!2B7==?EEcJLJ GGIJ 	 L KK399;	#	5K5K(KKK##$K$(HHi94y!89':HJ J>>T]] MM&++.//	0iikG
 'L $$ 	0,,.CJJE$++*<*<*L*LJMa&''A//	0s   D$D) )A/Fc                 L   [        UR                  SS5      5      nX R                  R                  :  a  [        R
                  " 5       eUS   R                  U5      R                  S5      n[        R                  " US9nUR                   H  nU R                  U5        M     g)z3Handle a long-polling POST request from the client.CONTENT_LENGTH0z
wsgi.inputzutf-8)encoded_payloadN)intr   r   max_http_buffer_sizer   ContentTooLongErrorreaddecoder   Payloadr   r@   )r   ra   lengthbodypr   s         r   handle_post_requestSocket.handle_post_requestj   s    W[[!1378KK4440022<(--f5<<WED5AyyS! !rB   Nc                    U R                   (       d  U R                  (       d  SU l        U R                  R                  SU R                  U=(       d     U R                  R
                  R                  SS9  U(       d3  U R                  [        R                  " [        R                  5      5        SU l         U R                  R                  S5        U(       a  U R                  R                  5         gggg)zClose the socket connection.T
disconnectFr#   N)rD   closingr   r5   r.   r(   SERVER_DISCONNECTr8   r   r9   r;   r   r   join)r   r&   r'   r(   s       r   r<   Socket.closeu   s    {{4<<DLKK&&dhh>$++,,>> ' ! 		&--56DKJJNN4 

!  $0{rB   c                 N    U R                   R                  U R                  5        g N)r   start_background_task
_send_pingrI   s    r   r3   Socket.schedule_ping   s    ))$//:rB   c                 R   S U l         U R                  R                  U R                  R                  5        U R                  (       d`  U R
                  (       dN  [        R                  " 5       U l         U R                  [        R                  " [        R                  5      5        g g g r   )rF   r   sleepr   rz   rD   rG   r8   r   r9   PINGrI   s    r   r   Socket._send_ping   s_    $++334||DKK!YY[DNIIfmmFKK01 %0|rB   c                    U R                   (       a  [        S5      eU R                  R                  S   c  U R                  R	                  5       $ U R                  R                  S   " U R
                  U R                  5      nU" X5      $ )z1Upgrade the connection from polling to websocket.z Socket has been upgraded already	websocket)r\   OSErrorr   _async_bad_request_websocket_handler)r   ra   rb   wss       r   _upgrade_websocketSocket._upgrade_websocket   sp    ==<==;;k*2;;++--[[,##T[[2'**rB   c                   ^ ^ U U4S jnS Hy  n[        TU5      (       d  M  [        [        TU5      S5      (       d  M3  [        TU5      R                  T R                  R                  T R                  R
                  -   5        M{     T R                  (       Ga  ST l        U" 5       n[        R                  " US9nUR                  [        R                  :w  d  UR                  S:w  a9  T R                  R                  R                  ST R                  5        ST l        / $ TR!                  [        R                  " [        R"                  SS	9R%                  5       5        T R&                  R)                  [        R                  " [        R*                  5      5        U" 5       n[        R                  " US9nUR                  [        R,                  :w  aA  ST l        T R                  R                  R                  S
T R                  U5        ST l        / $ ST l        ST l        OST l        ST l        U U4S jnT R                  R1                  U5      nT R                  R                  R                  ST R                  5         Sn U" 5       nUc  O([        R                  " US9n T R9                  U5        M6  T R&                  R)                  S5        URC                  5         T RE                  SST R                  RF                  RH                  S9  / $ ! [2         aV  n	T R4                  (       d:  T R                  R                  R                  ST R                  [7        U	5      5         Sn	A	M  Sn	A	ff = f! [:        R<                   a     N[:        R>                   a*    T R                  R                  R                  S5         GM    T R                  R                  RA                  S5         GM;  = f)z*Engine.IO handler for websocket transport.c                     > TR                  5       n U (       a.  [        U 5      TR                  R                  :  a  [	        S5      eU $ )Nzpacket is too large)r&   r*   r   rn   
ValueError)r0   r   r   s    r   websocket_wait1Socket._websocket_handler.<locals>.websocket_wait   s7    779DD	DKK$D$DD !677KrB   )_socksocket
settimeoutT)encoded_packetprobez,%s: Failed websocket upgrade, no PING packetF)r0   zK%s: Failed websocket upgrade, expected UPGRADE packet, received %s instead.c                     >  S n  TR                  5       n U (       d  O+ U  H"  nTR                  UR	                  5       5        M$     MF  TR                  5         g ! [        R                   a     M(  f = f!    M1  = fr   )r   r   r   r8   encoder<   )r   r   r   r   s     r   writer)Socket._websocket_handler.<locals>.writer   sw    "iikG &

-  '  HHJ ",, s   A (A5 A21A25A:z#%s: Upgrade to websocket successfulNz-%s: Unexpected error "%s", closing connectionz!Receive error -- socket is closedzUnknown receive errorr%   )%hasattrrZ   r   r   r   r   	connectedr[   r   r9   r)   r   r0   r,   r-   r.   r8   r2   r   r   r   r:   r7   r\   r   	ExceptionrD   strr@   r   r>   rE   	exceptionr|   r<   r(   TRANSPORT_CLOSE)
r   r   r   attrr   decoded_pktr   writer_taskru   es
   ``        r   r   Socket._websocket_handler   s   	 (Dr4  WWR->%M%MD!,,KK--0H0HHJ (
 >>>!DN "C --s;K&&&++5$$/""''BDHHN!&	GGFMM&++G<CCEFJJNN6==56 "C --s;K&&&..8 %""'',HHc# "'	 DM"DN!DN DM	" kk77?1488	= A	"$ y--q1CS!# : 	

t

T++,,<< 	 	> 	=   {{KK&&++G#a&*  00 11 ""''(KL "",,-DEs1   L .N  
M='AM88M= O<8O<&O<)rD   rz   r   rF   r\   r[   )TFN)__name__
__module____qualname____firstlineno____doc__r   r@   rJ   r8   rg   rv   r<   r3   r   r   r   __static_attributes__ rB   r   r	   r	   
   s=    .2* 	1.	"";2	+grB   r	   )	r]   rG   rP   r   r   r   r   
BaseSocketr	   r   rB   r   <module>r      s+    
     v[## vrB   