+
    jR9                         R t ^ RIt^ RIt^ RIt^ RIt^ t^t^t^t^	t	^
t
RtRtRtRtRtRtRtR	tR
tRtRtRt ! R R4      tR# )ze
WebSocket protocol handler for ASGI.

Implements RFC 6455 WebSocket protocol for ASGI applications.
Ni  i  i  i  i  i  i  i  i  i  i  s$   258EAFA5-E914-47DA-95CA-C5AB0DC85B11c                      a  ] tR t^*t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tRR ltRtV tR# )WebSocketProtocolzWebSocket connection handler for ASGI applications.

Uses callback-based data feeding instead of StreamReader for efficiency.
Data is fed via feed_data() from the parent protocol's data_received().
c                n   Wn         W n        W0n        W@n        RV n        RV n        RV n        RV n        RV n        RV n	        \        P                  ! 4       V n        . V n        RV n        \        P                  ! 4       V n        \#        4       V n        \        P                  ! 4       V n        RV n        R# )zInitialize WebSocket protocol handler.

Args:
    transport: asyncio transport for writing
    scope: ASGI WebSocket scope dict
    app: ASGI application callable
    log: Logger instance
FN )	transportscopeapplogacceptedclosed
close_codeclose_reason_close_sent_close_receivedasyncioEvent_close_event
_fragments_fragment_opcodeQueue_receive_queue	bytearray_buffer_data_event_eof)selfr   r   r   r	   s   &&&&&L/var/www/idalgo/venv/lib/python3.14/site-packages/gunicorn/asgi/websocket.py__init__WebSocketProtocol.__init__1   s     #
 !$#MMO  $ &mmo !{"==?	    c                    V'       d8   V P                   P                  V4       V P                  P                  4        R# R# )zqFeed incoming data from the parent protocol's data_received().

Args:
    data: bytes received on the connection
N)r   extendr   set)r   datas   &&r   	feed_dataWebSocketProtocol.feed_dataU   s0     LL%  " r   c                H    RV n         V P                  P                  4        R# )z+Signal that the connection has been closed.TN)r   r   r"   r   s   &r   feed_eofWebSocketProtocol.feed_eof_   s    	r   c                *  "   V P                   P                  RR/4      G Rj  xL
  \        P                  ! V P	                  4       4      p V P                  V P                  V P                  V P                  4      G Rj  xL
  V P                  '       g|   V P                  '       dj   V P                  '       gX   V P                  \         R4      G Rj  xL
   \        P"                  ! V P$                  P'                  4       RR7      G Rj  xL
  VP+                  4         VG Rj  xL
  R#  EL L  \         d    T P                  P                  R4        Li ; i L LT  \        P(                   d    RT n         Lpi ; i L]  \        P,                   d     R# i ; i  T P                  '       g   T P                  '       d   T P                  '       g}   T P                  \         R4      G Rj  xL 
   \        P"                  ! T P$                  P'                  4       RR7      G Rj  xL 
  M"  \        P(                   d    RT n         Mi ; iTP+                  4         TG Rj  xL 
  i   \        P,                   d     i i ; i; i5i)	z#Run the WebSocket ASGI application.typezwebsocket.connectNz#Error in WebSocket ASGI applicationzApplication error      @timeoutT)r   putr   create_task_read_framesr   r   _receive_send	Exceptionr	   	exceptionr   r
   r   _send_closeCLOSE_INTERNAL_ERRORwait_forr   waitTimeoutErrorcancelCancelledError)r   	read_tasks   & r   runWebSocketProtocol.rund   s     !!%%v/B&CDDD ''(9(9(;<		((4::t}}djjAAA
 ;;;4===9I9I9I&&';=PQQQ'!**4+<+<+A+A+CSQQQ + 	E B 	FHHDE	F
 R R++ '"&DK'
  ))  ;;;4===9I9I9I&&';=PQQQ'!**4+<+<+A+A+CSQQQ++ '"&DK' )) sS  !JD0(J4D5 D3D5 #J*J<JE!J3E% E#E% J$F	 )F*F	 .J3D5 5&EF% EF% !J#E% %FJFJF	 	F"J!F""J%$J
JJ5G86J<3H6/H20H65J6IJIJ)I5.I1/I54J5J
JJJJc                R   "   V P                   P                  4       G Rj  xL
 #  L5i)zASGI receive callable.N)r   getr'   s   &r   r2   WebSocketProtocol._receive   s      ((,,....s   '%'c                "  "   VR,          pVR8X  d@   V P                   '       d   \        R4      hV P                  V4      G Rj  xL
  RV n         R# VR8X  d   V P                   '       g   \        R4      hV P                  '       d   \        R4      hVP	                  R	4      pVP	                  R
4      pVe0   V P                  \        VP                  R4      4      G Rj  xL
  R# Ve!   V P                  \        V4      G Rj  xL
  R# R# VR8X  d   VP	                  R\        4      pVP	                  RR4      pV P                  WV4      G Rj  xL
   \        P                  ! V P                  P                  4       RR7      G Rj  xL
  V P&                  P)                  4        R# R#  ELi L L Lb L+  \        P                   d@    T P                   P#                  R4       RT n        T P                  P%                  4         L|i ; i5i)zASGI send callable.r+   zwebsocket.acceptzWebSocket already acceptedNTzwebsocket.sendzWebSocket not acceptedzWebSocket closedtextbytesutf-8zwebsocket.closecodereasonr   r,   r-   z!WebSocket close handshake timeout)r
   RuntimeError_send_acceptr   rA   _send_frameOPCODE_TEXTencodeOPCODE_BINARYCLOSE_NORMALr6   r   r8   r   r9   r:   r	   debugr"   r   close)r   messagemsg_typerD   
bytes_datarG   rH   s   &&     r   r3   WebSocketProtocol._send   s    6?))}}}"#?@@##G,,, DM))==="#;<<{{{"#566 ;;v&D W-J&&{DKK4HIII'&&}jAAA ( **;;v|4D[[2.F""4000(&&t'8'8'='='?MMM NN  " +# - JA
 1 N'' (BC"!!%%'(s   "HHF-%H+HAH!F0"#HF2AHF4H3F8 
F6F8 H0H2H4H6F8 8AH	HHHc                2  "   RpV P                   R,           F  w  r4VR8X  g   K  Tp M	  V'       g   \        R4      h\        P                  ! \        P
                  ! V\        ,           4      P                  4       4      P                  R4      pRRRR	V R
2.pVP                  R4      pV'       d   VP                  RV R
24       VP                  R. 4      pV Fj  w  r4\        V\        4      '       d   VP                  R4      p\        V\        4      '       d   VP                  R4      pVP                  V RV R
24       Kl  	  VP                  R
4       V P                  P                  RP                  V4      P!                  R4      4       R# 5i)z)Send WebSocket handshake accept response.Nheaderss   sec-websocket-keyz Missing Sec-WebSocket-Key headerasciiz"HTTP/1.1 101 Switching Protocols
zUpgrade: websocket
zConnection: Upgrade
zSec-WebSocket-Accept: z
subprotocolzSec-WebSocket-Protocol: zlatin-1z: r   )r   rI   base64	b64encodehashlibsha1WS_GUIDdigestdecoderA   append
isinstancerE   r   writejoinrM   )	r   rR   ws_keynamevalue
accept_keyrW   rY   extra_headerss	   &&       r   rJ   WebSocketProtocol._send_accept   sf     ::i00KD++ 1
 ABB %%LL')*113

&/ 	 3$%$ZL5	
 kk-0NN5k]$GH  Ir2(KD$&&{{9-%''Y/NNdV2eWD12 ) 	vRWWW-44Y?@s   FFA?F4C#Fc           	       "    V P                   '       d'   V P                  '       Ed5   V P                  '       Eg"   V P                  4       G Rj  xL
 pVf   EMVw  r#V\        8X  d   V P                  V4      G Rj  xL
  MV\        8X  d!   V P                  \        V4      G Rj  xL
  K  V\        8X  d   K  V\        8X  d9   V P                  P                  RRRVP                  R4      /4      G Rj  xL
  K  V\        8X  d+   V P                  P                  RRRV/4      G Rj  xL
  EK/  V\        8X  g   EK=  V P                  V4      G Rj  xL
  EKY  V P                   '       gI   RV n         V P                  P                  RR	R
V P*                  ;'       g    \,        /4      G Rj  xL
  R# R#  ELj EL? EL L L Lp  \         P"                   d    h \$         d'   pT P&                  P)                  RT4        Rp?LRp?ii ; i L`  T P                   '       gI   RT n         T P                  P                  RR	R
T P*                  ;'       g    \,        /4      G Rj  xL 
  i i ; i5i)z+Read and process incoming WebSocket frames.Nr+   zwebsocket.receiverD   rF   rE   zWebSocket read error: %sTzwebsocket.disconnectrG   )r   r   r   _read_frameOPCODE_CLOSE_handle_closeOPCODE_PINGrK   OPCODE_PONGrL   r   r/   r`   rN   OPCODE_CONTINUATION_handle_continuationr   r<   r4   r	   rP   r   CLOSE_ABNORMAL)r   frameopcodepayloades   &    r   r1   WebSocketProtocol._read_frames   s(    ,	 kkkd&6&6&6t?S?S?S"..00="'\),,W555[(**;@@@{*{*--11 3w 73    },--11 33    2233G<<< ;;;"))--2DOO==~/    G 1 6 A

 =%% 	 	:HHNN5q99	: ;;;"))--2DOO==~/    s  I2G G G G F9G H #G =F<>G H $G 'F?(AG 7G83G +G,G G GG AI2!I20H1I29G <G ?G G G G H'H(H	H 	HH I2AI/I/'I*(I//I2c                  "   V P                  ^4      G Rj  xL
 pV'       g   R# V^ ,          V^,          r2V^,	          ^,          pV^,	          ^,          pV^,	          ^,          pV^,	          ^,          pV^,          pV'       g   V'       g	   V'       d!   V P                  \        R4      G Rj  xL
  R# V^,	          ^,          p	V^,          p
V	'       g!   V P                  \        R4      G Rj  xL
  R# V
^~8X  dC   V P                  ^4      G Rj  xL
 pV'       g   R# \        P                  ! RV4      ^ ,          p
MHV
^8X  dB   V P                  ^4      G Rj  xL
 pV'       g   R# \        P                  ! RV4      ^ ,          p
V P                  ^4      G Rj  xL
 pV'       g   R# V P                  V
4      G Rj  xL
 pVf   R# V P                  W4      pV\        8X  d   V P                  f!   V P                  \        R4      G Rj  xL
  R# V P                  P                  V4       V'       d9   RP                  V P                  4      pV P                  p. V n        RV n        W3# \        R3# V\        \        39   d"   V'       g   Wn        V.V n        \        R3# W3# W3#  EL EL  EL EL EL] EL L L5i)zcRead a single WebSocket frame.

Returns:
    tuple: (opcode, payload) or None if connection closed
NzRSV bits setzFrame not masked!H!QzUnexpected continuationr   )_read_exactr6   CLOSE_PROTOCOL_ERRORstructunpack_unmaskrq   r   r   ra   rd   rL   rN   )r   header
first_bytesecond_bytefinrsv1rsv2rsv3ru   maskedpayload_lenext_lenmasking_keyrv   full_payloadfinal_opcodes   &               r   rl   WebSocketProtocol._read_frame  st     ''**"()VAYKQ!#a1$a1$a1$d" 44""#7HHH"a'!D( ""#79KLLL # ,,Q//G --g6q9KC ,,Q//G --g6q9K !,,Q// ((55? ,,w4 (($$,&&';=VWWWOO""7+"xx8#44"$(,%$33'--]33(.%#*)+S11$$ $$S + I M
 0
 0 0
 6 Xs   KJ.KA+KKK1J12&KK2J43!KJ7K!<KJ:K*4KJ=K+KK AKK(K9AKK1K4K7K:K=K KKc                  "   \        V P                  4      V8  d   V P                  '       d   R# V P                  P	                  4        \        V P                  4      V8  d   MTV P                  P                  4       G Rj  xL
  V P                  '       g   K  \        V P                  4      V8  g   K  R# \        V P                  RV 4      pV P                  RV1 V#  L_5i)zpRead exactly n bytes from internal buffer.

Waits for data via the callback-fed buffer instead of StreamReader.
N)lenr   r   r   clearr9   rE   )r   nr#   s   && r   r|   WebSocketProtocol._read_exactX  s     
 $,,!#yyy""$ 4<< A%""'')))yyyS.2T\\"1%&LL! *s#   ,C%AC%C#C%C%8,C%c                T   a V'       g   V# \        V3R l\        V4       4       4      # )zUnmask WebSocket payload data.c              3   V   <"   T F  w  rVSV^,          ,          ,          x  K   	  R# 5i)   N ).0ibr   s   &  r   	<genexpr>,WebSocketProtocol._unmask.<locals>.<genexpr>r  s&     K8JQQU+++8Js   &))rE   	enumerate)r   rv   r   s   &&fr   r   WebSocketProtocol._unmaskm  s!    NK	'8JKKKr   c                  "   \        V4      ^8  dK   \        P                  ! RVR,          4      ^ ,          V n        VR,          P	                  RRR7      V n        M\        V n        RV n        RV n        V P                  '       g/   V P                  V P                  V P
                  4      G R	j  xL
  RV n
        V P                  P                  4        R	#  L'5i)
zHandle incoming close frame.rz   :N   N:r   NNrF   replace)errorsr   TN)r   r~   r   r   r`   r   CLOSE_NO_STATUSr   r   r6   r   r   r"   r   rv   s   &&r   rn   WebSocketProtocol._handle_closet  s     w<1$mmD'"+>qADO ' 2 279 2 MD-DO "D# ""4??D4E4EFFF Gs   BC)C1C2(Cc                   "   R# 5i)z=Handle continuation frame (already processed in _read_frame).Nr   r   s   &&r   rr   &WebSocketProtocol._handle_continuation  s     s   c                >  "   \        V\        4      '       d   VP                  R4      p\        V4      p\	        4       pVP                  ^V,          4       V^~8  d   VP                  V4       MvVR8  d9   VP                  ^~4       VP                  \        P                  ! RV4      4       M7VP                  ^4       VP                  \        P                  ! RV4      4       VP                  V4       V P                  P                  \        V4      4       R# 5i)zBSend a WebSocket frame.

Server frames are not masked (RFC 6455).
rF   i   rz   r{   N)rb   strrM   r   r   ra   r!   r~   packr   rc   rE   )r   ru   rv   lengthrt   s   &&&  r   rK   WebSocketProtocol._send_frame  s     
 gs##nnW-GW 	TF]# C<LL e^LLLLT623LLLLT623 	WU5\*s   DDc                h  "   V P                   '       d   R# \        P                  ! RV4      pV'       d   W2P                  R4      R,          ,          pV P	                  \
        V4      G Rj  xL
  RV n         V P                  '       d$   RV n        V P                  P                  4        R# R#  LB5i)zSend a close frame.Nrz   rF   :N{   NT)
r   r~   r   rM   rK   rm   r   r   r   r"   )r   rG   rH   rv   s   &&& r   r6   WebSocketProtocol._send_close  s     ++dD)}}W-d33G|W555 DK!!#  	 	6s   3B27B2-B0.B2&B2)r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r	   r   r   N)r   )__name__
__module____qualname____firstlineno____doc__r   r$   r(   r>   r2   r3   rJ   r1   rl   r|   r   rn   rr   rK   r6   __static_attributes____classdictcell__)__classdict__s   @r   r   r   *   sc     "H#
8/&#P(AT.`P%d*L $L+:$ $r   r   )r   r   rZ   r\   r~   rq   rL   rN   rm   ro   rp   rO   CLOSE_GOING_AWAYr}   CLOSE_UNSUPPORTEDr   rs   CLOSE_INVALID_DATACLOSE_POLICY_VIOLATIONCLOSE_MESSAGE_TOO_BIGCLOSE_MANDATORY_EXTr7   r^   r   r   r   r   <module>r      s   
                2K$ K$r   