+
    j)                     l    R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt  ! R R]P                  4      t
R# )zy
ASGI worker for gunicorn.

Provides native asyncio-based ASGI support using gunicorn's own
HTTP parsing infrastructure.
N)baseASGIProtocolc                      a a ] tR t^t oRtV 3R lt]R 4       tV 3R l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tVtV ;t# )
ASGIWorkerzASGI worker using asyncio event loop.

Supports:
- HTTP/1.1 with keepalive
- WebSocket connections
- Lifespan protocol (startup/shutdown hooks)
- Optional uvloop for improved performance
c                   < \         SV `  ! V/ VB  V P                  P                  V n        R V n        . V n        ^ V n        R V n        / V n        RV n	        R # )NF)
super__init__cfgworker_connectionsloopserversnr_connslifespanstate_quick_shutdown)selfargskwargs	__class__s   &*,K/var/www/idalgo/venv/lib/python3.14/site-packages/gunicorn/workers/gasgi.pyr	   ASGIWorker.__init__   sR    $)&)"&(("="=	
$    c                N    VP                   ^8  d   VP                  R4       R# R# )z'Validate configuration for ASGI worker.zOASGI worker does not use threads configuration. Use worker_connections instead.N)threadswarning)clsr
   logs   &&&r   check_configASGIWorker.check_config)   s%     ;;?KK : ; r   c                D   < V P                  4        \        SV `	  4        R# )zInitialize the worker process.N)_setup_event_loopr   init_process)r   r   s   &r   r"   ASGIWorker.init_process0   s     	 r   c                &   \        V P                  RR4      pVR8X  d    ^ RIpRpVR8X  d7    ^ RIpVP	                  4       V n        V P                  P                  R4       M5\        P                  ! 4       V n        V P                  P                  R4       \        P                  ! V P
                  4       R#   \         d    Rp Li ; i  \         d9    T P                  P                  R4       \        P                  ! 4       T n         Lwi ; i)	zSetup the asyncio event loop.	asgi_loopautoNuvloopasynciozUsing uvloop event loopz-uvloop not available, falling back to asynciozUsing asyncio event loop)getattrr
   r'   ImportErrornew_event_loopr   r   debugr   r(   set_event_loop)r   	loop_typer'   s   &  r   r!   ASGIWorker._setup_event_loop6   s    DHHk6:	&$	  5"113	89
  ..0DIHHNN56tyy)  &%	&  5  !PQ#224	5s#   B: 4C :C
	C
A DDc                &    V P                   P                  4       V n        R#   \         dc   pT P                  P
                  '       g   h T P                  P                  T4       T P                  \        T4      4      T n         Rp?R# Rp?ii ; i)zLoad the ASGI application.N)
appwsgiasgiSyntaxErrorr
   reloadr   	exception_make_error_appstrr   es   & r   	load_wsgiASGIWorker.load_wsgiO   sb    	5DI 	588???HHq!,,SV4DII		5s   # BABBc                   a V3R lpV# )z9Create an error ASGI app for syntax errors during reload.c                   <"   V R ,          R8X  d?   V! R RRRRR./4      G Rj  xL
  V! R RRR	S 2P                  4       /4      G Rj  xL
  R# V R ,          R
8X  dc   V! 4       G Rj  xL
 pVR ,          R8X  d   V! R R/4      G Rj  xL
  V! 4       G Rj  xL
 pVR ,          R8X  d   V! R R/4      G Rj  xL
  R# R# R#  L Lz L] L? L2 L5i)typehttpzhttp.response.startstatusi  headersNzhttp.response.bodybodyzApplication error: r   zlifespan.startupzlifespan.startup.completezlifespan.shutdownzlifespan.shutdown.complete)s   content-types
   text/plain)encode)scopereceivesendmessage	error_msgs   &&& r   	error_app-ASGIWorker._make_error_app.<locals>.error_app[   s     V}&1c @A   
 01)=DDF    v*, '	/6?&88(CDEEE '	/6?&99(DEFFF : -

 *E)Fsi   !CC$C	C
C(C)CC	CC
C7C8CCCC
CC )r   rI   rJ   s   &f r   r7   ASGIWorker._make_error_appY   s    	G$ r   c                   V P                    F(  p\        P                  ! V\        P                  4       K*  	  V P                  P	                  \        P
                  V P                  4       V P                  P	                  \        P                  V P                  4       V P                  P	                  \        P                  V P                  4       V P                  P	                  \        P                  V P                  4       V P                  P	                  \        P                  V P                  4       V P                  P	                  \        P                  V P                  4       R# )z'Initialize signal handlers for asyncio.N)SIGNALSsignalSIG_DFLr   add_signal_handlerSIGQUIThandle_quit_signalSIGTERMhandle_exit_signalSIGINTSIGUSR1handle_usr1_signalSIGWINCHhandle_winch_signalSIGABRThandle_abort_signal)r   ss   & r   init_signalsASGIWorker.init_signalso   s     AMM!V^^,  			$$V^^T5L5LM		$$V^^T5L5LM		$$V]]D4K4KL		$$V^^T5L5LM		$$V__d6N6NO		$$V^^T5M5MNr   c                    RV n         V P                  '       g   R# RV n        V P                  P                  V 4       R# )z+Handle SIGQUIT/SIGINT - immediate shutdown.TNF)r   aliver
   
worker_intr   s   &r   rT   ASGIWorker.handle_quit_signal}   s/    #zzz
D!r   c                    RV n         R# )z#Handle SIGTERM - graceful shutdown.FN)rb   rd   s   &r   rV   ASGIWorker.handle_exit_signal   s	    
r   c                :    V P                   P                  4        R# )z"Handle SIGUSR1 - reopen log files.N)r   reopen_filesrd   s   &r   rY   ASGIWorker.handle_usr1_signal   s    r   c                <    V P                   P                  R4       R# )z$Handle SIGWINCH - ignored in worker.zworker: SIGWINCH ignored.N)r   r,   rd   s   &r   r[   ASGIWorker.handle_winch_signal   s    23r   c                v    RV n         V P                  P                  V 4       \        P                  ! ^4       R# )zHandle SIGABRT - abort.FN)rb   r
   worker_abortsysexitrd   s   &r   r]   ASGIWorker.handle_abort_signal   s&    
d#r   c                    V P                   P                  V P                  4       4       V P                  4        R#   \         d'   pT P                  P                  RT4        Rp?L>Rp?ii ; i  T P                  4        i ; i)z Main entry point for the worker.zWorker exception: %sN)r   run_until_complete_serve	Exceptionr   r6   _cleanupr9   s   & r   runASGIWorker.run   s`    	II((7 MMO  	:HH5q99	: MMOs'   )= A.A)$A1 )A..A1 1Bc           	     2  a "   \        S P                  RR4      pVR8w  dW   ^ RIHp V! S P                  S P
                  S P                  4      S n         S P                  P                  4       G Rj  xL
  S P                  4       pS P                   Fq  p S P                  P                  V 3R	 lVP                   VR
R
R7      G Rj  xL
 pS P"                  P%                  V4       S P
                  P'                  RV4       Ks  	  S P"                  '       g   S P
                  P                  R4       R#  S P(                  '       dr   S P+                  4        S P,                  \.        P0                  ! 4       8w  d   S P
                  P'                  RS 4       M!\2        P4                  ! R4      G Rj  xL
  K   S P9                  4       G Rj  xL
  R#  ELd  \         dX   pTR8X  d#   S P
                  P                  RT4        Rp?R# S P
                  P                  RT4       RS n         Rp?ELRp?ii ; i ELv  \         d)   pS P
                  P                  RYS4        Rp?EK  Rp?ii ; i L  \2        P6                   d     Li ; i L5i)zMain async serving loop.asgi_lifespanr&   off)LifespanManagerNonz ASGI lifespan startup failed: %sz&ASGI lifespan not supported by app: %sc                     < \        S 4      # )Nr   rd   s   r   <lambda>#ASGIWorker._serve.<locals>.<lambda>   s
    L.r   T)socksslreuse_addressstart_servingzASGI server listening on %sz!Failed to create server on %s: %szNo servers could be startedz!Parent changed, shutting down: %s      ?)r)   r
   gunicorn.asgi.lifespanr|   r3   r   r   r   startupru   errorr,   _get_ssl_contextsocketsr   create_serverr   r   appendinforb   notifyppidosgetppidr(   sleepCancelledError	_shutdown)r   lifespan_moder|   r:   ssl_contextr   servers   f      r   rt   ASGIWorker._serve   s      /6BE!>+DIItxxLDM	)mm++--- ++-LLDM#yy66.#"&"&  7    ##F+;TB ! |||HHNN89	*** 99

,HHMM"EtL
 mmC((( " nne . ) D(HHNN#EqI HHNN#KQO$(DMM)  MBDLLM( )%% 		 	s   AJG 3G4G 8J1I	H?
;IJJ9I: AI: JI: 5I86I: <JJJG H<%#H7J#H71J7H<<J?II5I0)J0I55J8I: :JJJJc                  "   V P                   P                  R4       V P                   F  pVP                  4        K  	  V P                  '       gW   V P                   FF  pV P                  '       d    M3 \
        P                  ! VP                  4       RR7      G Rj  xL
  KH  	  V P                  ^ 8  Ed&   V P                  '       Eg   V P                  P                  pV P                   P                  RV P                  4       V P                  P                  4       V,           pV P                  ^ 8  dn   V P                  P                  4       V8  dO   V P                  '       d   V P                   P                  R4       M \
        P                  ! R4      G Rj  xL
  K~  V P                  ^ 8  d'   V P                   P                  RV P                  4       V P                   '       d:   V P                  '       g&    V P                   P#                  4       G Rj  xL
  R# R# R#  EL  \
        P                   d     EK  i ; i L L,  \$         d(   pT P                   P'                  R	T4        Rp?R# Rp?ii ; i5i)
zPerform graceful shutdown.zWorker shutting down...g      ?timeoutNz'Waiting for %d connections to finish...zQuick shutdown requestedg?zForcing close of %d connectionsz ASGI lifespan shutdown error: %s)r   r   r   closer   r(   wait_forwait_closedTimeoutErrorr   r
   graceful_timeoutr   timer   r   r   shutdownru   r   )r   r   r   deadliner:   s   &    r   r   ASGIWorker._shutdown   s    /0 llFLLN # ###,,'''!**6+=+=+?MMM	 ' ==1T%9%9%9#xx88HHMMCT]]Syy~~'*::H--!#		(88(C'''HHMM"<=mmC(((}}q   !BDMMR ===!5!5!5Fmm,,... "6=' N++  ) / FA1EEFs   AJ#J7)H0 H-!H0%(JBJ-5J"I#AJ2JI "I#I 'J-H00I
J	I

JI JI>8J>JJc                    V P                   P                  '       g   R#  ^ RIHp VP	                  V P                   4      #   \
         d(   pT P                  P                  RT4        Rp?R# Rp?ii ; i)zGet SSL context if configured.N)r   z Failed to create SSL context: %s)r
   is_sslgunicornr   r   ru   r   r   )r   r   r:   s   &  r   r   ASGIWorker._get_ssl_context  sU    xx	%##DHH-- 	HHNN=qA	s    A A3A..A3c                    \         P                  ! V P                  4      pV F  pVP                  4        K  	  V'       dw   \         P                  ! VRR/ pV P
                  '       d4    V P                  P                  \         P                  ! VRR7      4       MV P                  P                  V4       V P                  P                  4        V P                   F  p VP                  4        K  	  R#   \         P                   d    T P                  P                  R4        Lri ; i  \         d'   pT P                  P                  RT4        Rp?LRp?ii ; i  \         d     K  i ; i)zClean up resources on exit.return_exceptionsTr   r   z#Timeout waiting for tasks to cancelzCleanup error: %sN)r(   	all_tasksr   cancelgatherr   rs   r   r   r   r,   r   ru   r   )r   pendingtaskr   r:   r^   s   &     r   rv   ASGIWorker._cleanup  s   	3''		2G    IDI'''N		44#,,VSA II008IIOO
 A	  #// N'LMN  	3HHNN.22	3  sT   A D/ 'D/ ,1C9 6D/ #E#90D,)D/ +D,,D/ /E :EE #E21E2)	r   rb   r3   r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r	   classmethodr   r"   r!   r;   r7   r_   rT   rV   rY   r[   r]   rw   rt   r   r   rv   __static_attributes____classdictcell____classcell__)r   __classdict__s   @@r   r   r      sw     % ; ;*25,O" 4:x%FN
 r   r   )r   r(   r   rP   ro   gunicorn.workersr   gunicorn.asgi.protocolr   Workerr   rL   r   r   <module>r      s0   
  	  
 ! /Z Zr   