+
    i  c                   sR   R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^RIHt ^RIHt ^RIHt ^RIHt ^RIHt ^RIHt ^RIHt ^R	IHt ^R
IHt ^RIHt ^RIHt R t]
P6                  R8X  d	   ]! R4      hR tR t ! R R]P>                  4      t  ! R R]PB                  4      t" ! R R]PF                  ]PH                  4      t% ! R R]PL                  4      t' ! R R4      t( ! R R4      t)R t* ! R R]PV                  4      t,] t-],t.]-t/R# )!z2Selector event loop for Unix with signal handling.N)base_events)base_subprocess)	constants)
coroutines)events)
exceptions)futures)selector_events)tasks)
transports)loggerZwin32z+Signals are not really supported on Windowsc                s    R# )zDummy signal handler.N )signumZframe   &&,/usr/lib64/python3.14/asyncio/unix_events.py_sighandler_noopr   '   s        c                 sV     \         P                  ! V 4      #   \         d    T u # i ; iN)oswaitstatus_to_exitcode
ValueError)status   &r   r   r   ,   s.    ((00  	s    ((c                   s   a a ] tR t^6t oRtRV 3R lltV 3R ltR tR tR t	R t
R	 tR R
 ltR R ltRR ltR tRRRRRRRRRRR/R lltRRRR^dRRRRRRRRRR/R lltR tR tR tR tV 3R ltRtVtV ;t# )!_UnixSelectorEventLoopz\Unix event loop.

Adds signal handling and UNIX Domain Socket support to SelectorEventLoop.
Nc                s   < \         SV `  V4       / V n        / V n        \	        4       '       d   \        4       V n        R # \        4       V n        R # r   )super__init___signal_handlers_unix_server_socketscan_use_pidfd_PidfdChildWatcher_watcher_ThreadedChildWatcher)selfselector	__class__s   &&r   r   Z_UnixSelectorEventLoop.__init__<   s;    " "$&!??.0DM13DMr   c                sX  < \         SV `  4        \        P                  ! 4       '       g0   \	        V P
                  4       F  pV P                  V4       K  	  R# V P
                  '       d?   \        P                  ! R V : R2\        V R7       V P
                  P                  4        R# R# )zClosing the loop z@ on interpreter shutdown stage, skipping signal handlers removalZsourceN)r   closesysZis_finalizinglistr   remove_signal_handlerwarningswarnResourceWarningclear)r    sigr"   s   & r   r$   Z_UnixSelectorEventLoop.closeE   s      ""D112**3/ 3 $$$ 1$ :H I .%)	+
 %%++- %r   c                sN    V F  pV'       g   K  V P                  V4       K   	  R # r   )_handle_signal)r    datar      && r   _process_self_dataZ)_UnixSelectorEventLoop._process_self_dataS   s     F'	 r   c                s   \         P                  ! V4      '       g   \         P                  ! V4      '       d   \        R4      hV P	                  V4       V P                  4         \        P                  ! V P                  P                  4       4       \        P                  ! Y#T R4      pYPP                   T&    \        P                  ! T\"        4       \        P$                  ! TR4       R#   \        \        3 d   p\        \        T4      4      hRp?ii ; i  \         d   pT P                   T T P                   '       gN    \        P                  ! R4       M5  \        \        3 d"   p\&        P(                  ! RT4        Rp?MRp?ii ; iTP*                  \*        P,                  8X  d   \        RT R24      hh Rp?ii ; i)zAdd a handler for a signal.  UNIX only.

Raise ValueError if the signal number is invalid or uncatchable.
Raise RuntimeError if there is a problem setting up the handler.
z3coroutines cannot be used with add_signal_handler()NFset_wakeup_fd(-1) failed: %ssig  cannot be caught)r   ZiscoroutineZ_iscoroutinefunction	TypeError_check_signalZ_check_closedsignalset_wakeup_fdZ_csockfilenor   OSErrorRuntimeErrorZstrr   ZHandler   r   Zsiginterruptr
   infoerrnoEINVAL)r    r,   callbackargsexchandleZnexcs   &&&*   r   add_signal_handlerZ)_UnixSelectorEventLoop.add_signal_handlerZ   sv    ""8,,//99 8 9 93	)
   !3!3!56 xtT:%+c"	 MM#/0 U+ G$ 	)s3x((	)  	%%c*(((F((,"G, FKK >EEF yyELL("T#.?#@AA	sZ   &.C/ ;2D /D DDG'GEGF/FGF2GGc                s    V P                   P                  V4      pVf   R# VP                  '       d   V P                  V4       R# V P	                  V4       R# )z2Internal helper that is the actual signal handler.N)r   ZgetZ
_cancelledr'   Z_add_callback_signalsafe)r    r,   rB   r/   r   r-   Z%_UnixSelectorEventLoop._handle_signal   sH    &&**3/>&&s+))&1r   c                sH   V P                  V4        V P                  V T\        P                  8X  d   \        P
                  pM\        P                  p \        P                  ! Y4       T P                  '       g    \        P                  ! R4       R# R#   \         d     R# i ; i  \         d5   pTP                  \        P                  8X  d   \        RT R24      hh Rp?ii ; i  \        \        3 d#   p\        P                  ! RT4        Rp?R# Rp?ii ; i)zgRemove a handler for a signal.  UNIX only.

Return True if a signal handler was removed, False if not.
Fr2   r3   Nr1   Tr4   )r6   r   ZKeyErrorr7   ZSIGINTZdefault_int_handlerZSIG_DFLr:   r=   r>   r;   r8   r   r
   r<   )r    r,   ZhandlerrA      &&  r   r'   Z,_UnixSelectorEventLoop.remove_signal_handler   s    
 	3	%%c* &--00GnnG	MM#' $$$A$$R( -  		  	yyELL("T#.?#@AA		 ( A:C@@AsA   B B,  C. B)(B),C+7/C&&C+.D!?DD!c                s    \        V\        4      '       g   \        RV: 24      hV\        P                  ! 4       9  d   \        RV 24      hR# )zInternal helper to validate a signal.

Raise ValueError if the signal number is invalid or uncatchable.
Raise RuntimeError if there is a problem setting up the handler.
zsig must be an int, not zinvalid signal number N)
isinstanceZintr5   r7   Zvalid_signalsr   )r    r,   r   r   r6   Z$_UnixSelectorEventLoop._check_signal   sM     #s##6sg>??f**,,5cU;<< -r   c                    \        WW#V4      # r   )_UnixReadPipeTransportr    pipeprotocolwaiterextra   &&&&&r   _make_read_pipe_transportZ0_UnixSelectorEventLoop._make_read_pipe_transport   s    %d(EJJr   c                rF   r   )_UnixWritePipeTransportrH   rM   r   _make_write_pipe_transportZ1_UnixSelectorEventLoop._make_write_pipe_transport   s    &t8UKKr   c	           
     sp  "   V P                   p
V P                  4       p\        WW#WEWg3R VRV/V	B pV
P                  VP	                  4       V P
                  V4        VG Rj  xL
  V#  L  \        \        3 d    h \         d,    TP                  4        TP                  4       G Rj  xL 
  h i ; i5i)rK   rL   N)r   create_future_UnixSubprocessTransportadd_child_handlerZget_pid_child_watcher_callback
SystemExitKeyboardInterruptBaseExceptionr$   Z_wait)r    rJ   r@   shellstdinstdoutstderrbufsizerL   kwargsZwatcherrK   transps   &&&&&&&&&,   r   _make_subprocess_transportZ1_UnixSelectorEventLoop._make_subprocess_transport   s      --##%)$$(-v2/52=B2 +12 	!!&.."2 $ < <f	F	LL  -. 	 	LLN,,.  	sB   AB6A, #A*$A, (B6*A, ,B3$B3+B.,B33B6c                s>    V P                  VP                  V4       R # r   )call_soon_threadsafeZ_process_exited)r    pid
returncoder^      &&&&r   rT   Z._UnixSelectorEventLoop._child_watcher_callback   s    !!&"8"8*Er   sslsockserver_hostnamessl_handshake_timeoutssl_shutdown_timeoutc          	     s  "   V'       d   Vf   \        R4      hM-Ve   \        R4      hVe   \        R4      hVe   \        R4      hVe   Ve   \        R4      h\        P                  ! V4      p\        P                  ! \        P                  \        P
                  ^ 4      p VP                  R4       V P                  WB4      G R j  xL
  MmVf   \        R4      hVP                  \        P                  8w  g    VP                  \        P
                  8w  d   \        RV: 24      hVP                  R4       V P                  WAW5VVR	7      G R j  xL
 w  rW3#  L   TP                  4        h ; i L!5i)
Nz/you have to pass server_hostname when using sslz+server_hostname is only meaningful with ssl1ssl_handshake_timeout is only meaningful with ssl0ssl_shutdown_timeout is only meaningful with ssl3path and sock can not be specified at the same timeFzno path and sock were specified.A UNIX Domain Stream Socket was expected, got )rg   rh   )r   r   fspathsocketAF_UNIXSOCK_STREAMsetblockingZsock_connectr$   familytypeZ_create_connection_transport)
r    protocol_factorypathrd   re   rf   rg   rh   	transportrJ   s
   &&&$$$$$  r   create_unix_connectionZ-_UnixSelectorEventLoop.create_unix_connection   s     & EG G ' * !NOO$0 GI I#/ FH H  IK K 99T?D==1C1CQGD  '''333 | !BCCv~~-II!3!33 DTHMO OU#$($E$EC"7!5 %F %7 7	 ""% 4

7s=   B#E:&%E" E E" BE:E8	E: E" "E55E:backlogstart_servingTcleanup_socketc          	     s  "   \        V\        4      '       d   \        R 4      hVe   V'       g   \        R4      hVe   V'       g   \        R4      hVe   Ve   \        R4      h\        P
                  ! V4      p\        P                  ! \        P                  \        P                  4      pV^ ,          R9  dR    \        P                  ! \        P                  ! V4      P                  4      '       d   \        P                  ! V4        VP#                  V4       M\Vf   \        R4      hVP*                  \        P                  8w  g    VP,                  \        P                  8w  d   \        R	V: 24      hV	'       dM   VP/                  4       pV^ ,          R9  d/    \        P                  ! V4      P0                  V P2                  V&   VP5                  R
4       \6        P8                  ! W.VWTVV4      pV'       d/   VP;                  4        \<        P>                  ! ^ 4      G Rj  xL
  V#   \         d     EL5\         d#   p
\        P                   ! RY*4        Rp
?
EL\Rp
?
ii ; i  \         dX   pTP%                  4        TP&                  \&        P(                  8X  d#   RT: R2p\        \&        P(                  T4      Rhh Rp?i TP%                  4        h ; i  \         d     EL%i ; i L5i)z*ssl argument must be an SSLContext or NoneNri   rj   rk   z2Unable to check or remove stale UNIX socket %r: %rzAddress z is already in usez-path was not specified, and no sock specifiedrl   F)    Z ) rE   Zboolr5   r   r   rm   rn   ro   rp   statS_ISSOCKst_modeZremoveFileNotFoundErrorr:   r
   errorZbindr$   r=   Z
EADDRINUSErr   rs   getsocknamest_inor   rq   r    ZServerZ_start_servingr   Zsleep)r    rt   ru   re   rx   rd   rg   rh   ry   rz   errrA   ZmsgZservers   &&&$$$$$$$    r   create_unix_serverZ)_UnixSelectorEventLoop.create_unix_server  s     c4  HII ,SCE E  +CBD D  IK K 99T?D==1C1CDD Awk)6}}RWWT]%:%:;;		$		$ | CE E v~~-II!3!33 DTHMO O ##%DAwk)68ggdm6J6JD--d3 	##D&2B$'2G$8: !!# ++a.  e )  6LL "*+/6 66  

99 0 00 %TH,>?C!%"2"2C8dB

" )  !s   -K;K;A5K;=9H4 7H4 I1 A$K;K;#-K' AK;-K9.K;4I.?K;I.I.I)#K;)I..K;1K$<AKK$$K;'K62K;5K66K;c           
     s&  "    \         P                    TP                  4       p \         P                  ! T4      P                  pT'       d   TMTpT'       g   ^ # T P                  4       p	T P                  T	RYY4T^ 4       T	G Rj  xL
 #   \         d    \        P                  ! R 4      hi ; i  \        \        P                  3 d   p\        P                  ! R4      hRp?ii ; i  \         d    \        P                  ! R4      hi ; i L5i)zos.sendfile() is not availableznot a regular fileN)r   sendfileZAttributeErrorr   SendfileNotAvailableErrorr9   ioZUnsupportedOperationfstatZst_sizer:   rQ   _sock_sendfile_native_impl)
r    re   Zfileoffsetcountr9   r   Zfsize	blocksizefuts
   &&&&&     r   _sock_sendfile_nativeZ,_UnixSelectorEventLoop._sock_sendfile_nativeb  s     	2KK	M[[]F	MHHV$,,E #E	  "''T4(.y!	Ey%  	26602 2	2
  7 78 	M667KLL	M  	M667KLL	M sb   DB B1  C* DD-DDD"B..D1C'C""C''D*"DDc	                sR   VP                  4       p	Ve   V P                  V4       VP                  4       '       d   V P                  WEV4       R # V'       d5   Wh,
          pV^ 8:  d&   V P                  WEV4       VP	                  V4       R # \        V\        P                  ^,          ^,           4      p \        P                  ! WWW4      p
V
^ 8X  d&   V P                  WEV4       VP	                  V4       R # WZ,          pW,          pVf   V P                  W4       V P                  WP                  VWVWVWx4
       R #   \        \        3 d:    Tf   T P                  Y4       T P                  YP                  TYTYVYx4
        R # \         d   pTeU   TP                   \         P"                  8X  d6   \%        T4      \&        Jd#   \'        R\         P"                  4      pYn        TpT^ 8X  d@   \*        P,                  ! R4      pT P                  YET4       TP/                  T4        R p?R # T P                  YET4       TP/                  T4        R p?R # R p?i\0        \2        3 d    h \4         d/   pT P                  YET4       TP/                  T4        R p?R # R p?ii ; i)Nzsocket is not connectedzos.sendfile call failed)r9   remove_writer	cancelled_sock_sendfile_update_fileposZ
set_resultZminr%   Zmaxsizer   r   _sock_add_cancellation_callbackZ
add_writerr   BlockingIOErrorInterruptedErrorr:   r=   ZENOTCONNrs   ZConnectionErrorZ	__cause__r   r   Zset_exceptionrU   rV   rW   )r    r   Zregistered_fdre   r9   r   r   r   
total_sentfdZsentrA   Znew_excr   s   &&&&&&&&&     r   r   Z1_UnixSelectorEventLoop._sock_sendfile_native_imply  sA   [[]$
 }-==??..vzJ*IA~226:Nz* 	3;;>A#56	1	F;;r6=DJ qy226:Nz*"
 (88C$C$CS "& &yF[  !12 	B$44S?OOB ? ?f"9B  	')II/I_4
 *-u~~?$'!Q
 !::-/226:N!!#&&226:N!!#&&-. 	 	#..vzJc""	#sD   5D? ?AJ&J&J&BI0#IJ&,
J&7J&8#J!!J&c                sb    V^ 8  d(   \         P                  ! W\         P                  4       R# R# r{   N)r   ZlseekZSEEK_SET)r    r9   r   r   rc   r   r   Z4_UnixSelectorEventLoop._sock_sendfile_update_filepos  s     >HHVR[[1 r   c                s:   a a V V3R  lpVP                  V4       R# )c                 s   < V P                  4       '       d-   SP                  4       pVR8w  d   SP                  V4       R# R# R# )i   Nr4   )r   r9   r   )r   r   r    re   s   & r   cbZB_UnixSelectorEventLoop._sock_add_cancellation_callback.<locals>.cb  s8    }}[[]8&&r*  r   N)Zadd_done_callback)r    r   re   r   s   f&f r   r   Z6_UnixSelectorEventLoop._sock_add_cancellation_callback  s    	+
 	b!r   c                s  < WP                   9   d   VP                  4       pMR p\        SV `  V4       Vea   V P                   V,          pV P                   V  \        P
                  ! V4      P                  V8X  d   \        P                  ! V4       R # R # R #   \         d     R # \         d#   p\        P                  ! RY$4        R p?R # R p?ii ; i)Nz/Unable to clean up listening UNIX socket %r: %r)r   r   r   _stop_servingr   r|   r   Zunlinkr   r:   r
   r   )r    re   ru   Zprev_inor   r"   s   &&   r   r   Z$_UnixSelectorEventLoop._stop_serving  s    ,,,##%DDd#006H))$/2774=''83IIdO 4	  %  2 &'+2 22s$   ;B C(C1C2CC)r   r   r   r   NN)__name__
__module____qualname____firstlineno____doc__r   r$   r0   rC   r-   r'   r6   rN   rP   r_   rT   rw   r   r   r   r   r   r   __static_attributes____classdictcell____classcell__r"   __classdict__   @@r   r   r   6   s     
4.(+Z2@
=KL,F0#0#0# !0# #'	0#
 "&0#dPP"P(,P #'P "&	P
 P
 04Pd.GFR2"2 2r   r   c                   s   a a ] tR tRt oRtRV 3R lltR tR tR tR t	R t
R tR	 tR
 tR tR t]P"                  3R ltRR ltR tR tRtVtV ;t# )rG   i  c                sb  < \         SV `  V4       W P                  R &   Wn        W n        VP                  4       V n        W0n        RV n        RV n	        \        P                  ! V P                  4      P                  p\        P                  ! V4      '       gY   \        P                  ! V4      '       g=   \        P                   ! V4      '       g!   RV n        RV n        RV n        \#        R4      h\        P$                  ! V P                  R4       V P                  P'                  V P                  P(                  V 4       V P                  P'                  V P*                  V P                  V P,                  4       Ve.   V P                  P'                  \.        P0                  VR4       R# R# )rI   FNz)Pipe transport is for pipes/sockets only.)r   r   _extra_loop_piper9   _fileno	_protocol_closing_pausedr   r   r~   r|   S_ISFIFOr}   S_ISCHRr   set_blocking	call_soonconnection_made_add_reader_read_readyr   _set_result_unless_cancelled)r    looprI   rJ   rK   rL   moder"   s   &&&&&& r   r   Z_UnixReadPipeTransport.__init__  s/   "F

{{}!xx%--d##d##T""DJDL!DNHII
e,

T^^;;TB

T--!\\4+;+;	=JJ  !E!E!'/ r   c                sl    V P                  4       '       g   R # V P                  P                  W4       R # r   )
is_readingr   r   )r    r   r?      &&&r   r   Z"_UnixReadPipeTransport._add_reader  s$      

r,r   c                sV    V P                   '       * ;'       d    V P                  '       * # r   )r   r   r    r   r   r   Z!_UnixReadPipeTransport.is_reading  s    <<55$55r   c                s   V P                   P                  .pV P                  f   VP                  R4       M#V P                  '       d   VP                  R4       VP                  RV P
                   24       \        V P                  RR 4      pV P                  e`   Ve\   \        P                  ! W P
                  \        P                  4      pV'       d   VP                  R4       MCVP                  R4       M1V P                  e   VP                  R4       MVP                  R4       RP                  R	P                  V4      4      # )
Nclosedclosingfd=	_selectorpollingidleopen<{}> )r"   r   r   appendr   r   getattrr   r   _test_selector_event	selectorsZ
EVENT_READformatjoin)r    r<   r!   r   s   &   r   __repr__Z_UnixReadPipeTransport.__repr__  s    ''(::KK!]]]KK	"c$,,()4::{D9::!h&:%::,,	(<(<>GI&F#ZZ#KKKK!}}SXXd^,,r   c                s    \         P                  ! V P                  V P                  4      pV'       d   V P                  P                  V4       R# V P                  P                  4       '       d   \        P                  ! R V 4       RV n
        V P                  P                  V P                  4       V P                  P                  V P                  P                  4       V P                  P                  V P                  R4       R#   \        \         3 d     R# \"         d   pT P%                  TR4        Rp?R# Rp?ii ; i)%r was closed by peerTNz"Fatal read error on pipe transport)r   Zreadr   max_sizer   Zdata_receivedr   	get_debugr
   r<   r   _remove_readerr   Zeof_received_call_connection_lostr   r   r:   _fatal_error)r    r.   rA      &  r   r   Z"_UnixReadPipeTransport._read_ready#  s    	G774<<7D ,,T2::''))KK 7> $

))$,,7

$$T^^%@%@A

$$T%?%?F  !12 	 	Ic#GHH	Is#   +D E E)E*EEc                s    V P                  4       '       g   R # RV n        V P                  P                  V P                  4       V P                  P                  4       '       d   \        P                  ! RV 4       R # R # )NTz%r pauses reading)r   r   r   r   r   r   r
   debugr   r   r   pause_readingZ$_UnixReadPipeTransport.pause_reading5  sV      

!!$,,/::!!LL,d3 "r   c                s2   V P                   '       g   V P                  '       g   R # RV n        V P                  P                  V P                  V P
                  4       V P                  P                  4       '       d   \        P                  ! RV 4       R # R # )NFz%r resumes reading)	r   r   r   r   r   r   r   r
   r   r   r   r   resume_readingZ%_UnixReadPipeTransport.resume_reading=  sb    ===

t||T-=-=>::!!LL-t4 "r   c                    Wn         R # r   r   r    rJ   r   r   set_protocolZ#_UnixReadPipeTransport.set_protocolE      !r   c                    V P                   # r   r   r   r   r   get_protocolZ#_UnixReadPipeTransport.get_protocolH      ~~r   c                r   r   r   r   r   r   
is_closingZ!_UnixReadPipeTransport.is_closingK      }}r   c                sP    V P                   '       g   V P                  R 4       R # R # r   )r   _closer   r   r   r$   Z_UnixReadPipeTransport.closeN  s    }}}KK r   c                    V P                   e0   V! RV : 2\        V R7       V P                   P                  4        R # R # Nzunclosed transport r#   r   r*   r$   r    _warnr   r   __del__Z_UnixReadPipeTransport.__del__R  5    ::!'x0/$OJJ "r   c           
     s`   \        V\        4      '       dZ   VP                  \        P                  8X  d;   V P                  P                  4       '       d   \        P                  ! R WRR7       M-V P                  P                  RVRVRV RV P                  /4       V P                  V4       R# z%r: %sT)Zexc_infomessageZ	exceptionrv   rJ   N)rE   r:   r=   ZEIOr   r   r
   r   call_exception_handlerr   r   r    rA   r   r   r   r   Z#_UnixReadPipeTransport._fatal_errorW  s    sG$$eii)?zz##%%XttDJJ--7STDNN	/  	Cr   c                s    R V n         V P                  P                  V P                  4       V P                  P	                  V P
                  V4       R# TN)r   r   r   r   r   r   r    rA   r   r   r   Z_UnixReadPipeTransport._closee  s9    

!!$,,/

T77=r   c                    V P                   P                  V4       V P                  P                  4        R V n        R V n         R V n        R #   T P                  P                  4        R T n        R T n         R T n        i ; ir   r   Zconnection_lostr   r$   r   r   r   r   r   Z,_UnixReadPipeTransport._call_connection_lostj  g    	NN**3/JJDJ!DNDJ JJDJ!DNDJ   A 1A?)r   r   r   r   r   r   i   r   zFatal error on pipe transport)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r(   r)   r   r   r   r   r   r   r   r   r   r   rG   rG     sd     H/<-
6-*G$45" %MM 
>
 r   rG   c                   s   a a ] tR tRt oRV 3R lltR tR tR tR tR t	R t
R	 tR
 tR tR tR t]P"                  3R ltR tRR ltRR ltR tRtVtV ;t# )rO   it  c                s  < \         S
V `  WQ4       W P                  R &   W n        VP	                  4       V n        W0n        \        4       V n        ^ V n	        RV n
        \        P                  ! V P
                  4      P                  p\        P                  ! V4      p\        P                   ! V4      p\        P"                  ! V4      p	V'       g1   V'       g)   V	'       g!   RV n        RV n        RV n        \%        R4      h\        P&                  ! V P
                  R4       V P(                  P+                  V P                  P,                  V 4       V	'       g.   V'       dk   \.        P0                  P3                  R4      '       gF   V P(                  P+                  V P(                  P4                  V P
                  V P6                  4       Ve.   V P(                  P+                  \8        P:                  VR4       R# R# )rI   FNz?Pipe transport is only for pipes, sockets and character devicesaix)r   r   r   r   r9   r   r   	bytearray_buffer
_conn_lostr   r   r   r~   r|   r   r   r}   r   r   r   r   r   r%   platform
startswithr   r   r   r   )r    r   rI   rJ   rK   rL   r   Zis_charZis_fifoZ	is_socketr"   s   &&&&&&    r   r   Z _UnixWritePipeTransport.__init__w  sd   %"F
{{}! {xx%--,,t$--%MM$'	7iDJDL!DN D E E 	e,

T^^;;TB
 )@)@)G)GJJ  !7!7!%t/?/?A JJ  !E!E!'/ r   c                s   V P                   P                  .pV P                  f   VP                  R4       M#V P                  '       d   VP                  R4       VP                  RV P
                   24       \        V P                  RR 4      pV P                  e   Ve   \        P                  ! W P
                  \        P                  4      pV'       d   VP                  R4       MVP                  R4       V P                  4       pVP                  RV 24       M1V P                  e   VP                  R4       MVP                  R4       R	P                  R
P                  V4      4      # )Nr   r   r   r   r   r   zbufsize=r   r   r   )r"   r   r   r   r   r   r   r   r   r   r   ZEVENT_WRITEget_write_buffer_sizer   r   )r    r<   r!   r   r\   s   &    r   r   Z _UnixWritePipeTransport.__repr__  s   ''(::KK!]]]KK	"c$,,()4::{D9::!h&:%::,,	(=(=?GI&F#002GKK(7),-ZZ#KKKK!}}SXXd^,,r   c                s,    \        V P                  4      # r   )lenr   r   r   r   r   Z-_UnixWritePipeTransport.get_write_buffer_size  s    4<<  r   c                s    V P                   P                  4       '       d   \        P                  ! R V 4       V P                  '       d   V P                  \        4       4       R# V P                  4        R# )r   N)r   r   r
   r<   r   r   ZBrokenPipeErrorr   r   r   r   Z#_UnixWritePipeTransport._read_ready  sE    ::!!KK/6<<<KK)*KKMr   c                s~   \        V\        4      '       d   \        V4      pV'       g   R # V P                  '       g   V P                  '       dQ   V P                  \
        P                  8  d   \        P                  ! R4       V ;P                  ^,          un        R # V P                  '       gz    \        P                  ! V P                  V4      pT\'        T4      8X  d   R # T^ 8  d   \        T4      TR  pT P(                  P+                  T P                  T P,                  4       V ;P                  V,          un	        V P/                  4        R #   \        \        3 d    ^ p L\        \         3 d    h \"         d7   pT ;P                  ^,          un        T P%                  TR4        R p?R # R p?ii ; i)Nz=pipe closed by peer or os.write(pipe, data) raised exception.#Fatal write error on pipe transport)rE   r   Z
memoryviewr   r   r   Z!LOG_THRESHOLD_FOR_CONNLOST_WRITESr
   warningr   r   writer   r   r   rU   rV   rW   r   r   r   Z_add_writer_write_readyZ_maybe_pause_protocol)r    r.   nrA   rD   r   r   Z_UnixWritePipeTransport.write  s@   dI&&d#D???dmmm)"M"MM  H IOOq O|||	HHT\\40 CI~Q!$'+JJ""4<<1B1BC""$ $%56  12   1$!!#'LMs*   3!E F<+F<:
F<F<+F77F<c                sB    \         P                  ! V P                  V P                  4      pV\	        V P                  4      8X  d   V P                  P                  4        V P                  P                  V P                  4       V P                  4        V P                  '       d7   V P                  P                  V P                  4       V P                  R 4       R # V^ 8  d   V P                  R V1 R # R #   \        \        3 d     R # \        \        3 d    h \          dv   pT P                  P                  4        T ;P"                  ^,          un        T P                  P                  T P                  4       T P%                  TR4        R p?R # R p?ii ; i)Nr   )r   r   r   r   r   r+   r   _remove_writerZ_maybe_resume_protocolr   r   r   r   r   rU   rV   rW   r   r   )r    r   rA   r   r   r   Z$_UnixWritePipeTransport._write_ready  s0   	%t||4A C%%""$

))$,,7++-===JJ--dll;..t4QLL!$ )  !12 	-. 	 	JLL OOq O JJ%%dll3c#HII	Js*   +C: :FF
F(F)A*FFc                s    R # )Tr   r   r   r   can_write_eofZ%_UnixWritePipeTransport.can_write_eof  s    r   c                s    V P                   '       d   R # RV n         V P                  '       gN   V P                  P                  V P                  4       V P                  P                  V P                  R 4       R # R # )NT)r   r   r   r   r   r   r   r   r   r   	write_eofZ!_UnixWritePipeTransport.write_eof  sS    ===|||JJ%%dll3JJ  !;!;TB r   c                r   r   r   r   r   r   r   Z$_UnixWritePipeTransport.set_protocol  r   r   c                r   r   r   r   r   r   r   Z$_UnixWritePipeTransport.get_protocol  r   r   c                r   r   r   r   r   r   r   Z"_UnixWritePipeTransport.is_closing  r   r   c                sn    V P                   e'   V P                  '       g   V P                  4        R # R # R # r   )r   r   r  r   r   r   r$   Z_UnixWritePipeTransport.close  s&    ::!$---NN +8!r   c                r   r   r   r   r   r   r   Z_UnixWritePipeTransport.__del__  r   r   c                s(    V P                  R 4       R # r   )r   r   r   r   abortZ_UnixWritePipeTransport.abort  s    Dr   c           
     s"   \        V\        4      '       d;   V P                  P                  4       '       d   \        P
                  ! R WRR7       M-V P                  P                  RVRVRV RV P                  /4       V P                  V4       R# r   )	rE   r:   r   r   r
   r   r   r   r   r   r   r   r   Z$_UnixWritePipeTransport._fatal_error!  sp    c7##zz##%%XttDJJ--7STDNN	/  	Cr   c                sL   R V n         V P                  '       d&   V P                  P                  V P                  4       V P                  P                  4        V P                  P                  V P                  4       V P                  P                  V P                  V4       R# r   )	r   r   r   r   r   r+   r   r   r   r   r   r   r   Z_UnixWritePipeTransport._close/  sh    <<<JJ%%dll3

!!$,,/

T77=r   c                r   r   r   r   r   r   r   Z-_UnixWritePipeTransport._call_connection_lost7  r   r   )r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r$   r(   r)   r   r  r   r   r   r   r   r   r   r   r   rO   rO   t  sk     #/J-0!!%F%8C"
 %MM 
> r   rO   c                   s&   a  ] tR tRt o R tRtV tR# )rR   iA  c                s    R pV\         P                  8X  d=   \        P                  P	                  R4      '       d   \
        P                  ! 4       w  r8 \         P                  ! V3RVRVRVRVRRRV/VB V n        Ve>   VP                  4        \        VP                  4       R	VR
7      V P                  n        R pVe#   VP                  4        VP                  4        R # R #   Te"   TP                  4        TP                  4        i i ; i)Nr   rX   rY   rZ   r[   Zuniversal_newlinesFr\   Zwb)Z	buffering)
subprocessZPIPEr%   r   r   rn   Z
socketpairZPopen_procr$   r   ZdetachrY   )	r    r@   rX   rY   rZ   r[   r\   r]   Zstdin_ws	   &&&&&&&, r   _startZ_UnixSubprocessTransport._startC  s    JOO#(?(?(F(F
 $..0NE	 #))E!E).E7=EFLE#(E29E=CEDJ "#'(8$'#R

 " #w" #s   A)C& &'D)r  N)r   r   r   r   r  r   r   r      @r   rR   rR   A  s        r   rR   c                   s0   a  ] tR tRt o RtR tR tRtV tR# )r   iY  a  Child watcher implementation using Linux's pid file descriptors.

This child watcher polls process file descriptors (pidfds) to await child
process termination. In some respects, PidfdChildWatcher is a "Goldilocks"
child watcher implementation. It doesn't require signals or threads, doesn't
interfere with any processes launched outside the event loop, and scales
linearly with the number of subprocesses launched by the event loop. The
main disadvantage is that pidfds are specific to Linux, and only work on
recent (5.3+) kernels.
c                s    \         P                  ! 4       p\        P                  ! V4      pVP	                  WPP
                  WW#4       R # r   )r   get_running_loopr   
pidfd_openr   _do_wait)r    ra   r?   r@   r   pidfd   &&&*  r   rS   Z$_PidfdChildWatcher.add_child_handlere  s4    &&(c"s8Jr   c                s0   \         P                  ! 4       pVP                  V4        \        P                  ! V^ 4      w  rg\        V4      p\        P                  ! V4       V! W.VO5!   R#   \         d    ^p\        P                  ! RT4        LHi ; i)r{   zJchild process pid %d exit status already read:  will report returncode 255N)
r   r  r   r   waitpidr   ChildProcessErrorr
   r   r$   )	r    ra   r  r?   r@   r   Z_r   rb   s	   &&&&&    r   r
  Z_PidfdChildWatcher._do_waitj  s    &&(E"	8

3*IA 07J
(4( ! 	 JNN.		s   A. .$BBr   N)	r   r   r   r   r   rS   r
  r   r   r  r  r   r   r   Y  s     	K
) )r   r   c                   sV   a  ] tR tRt o RtR t]P                  3R ltR t	R t
RtV tR# )	r   i}  a%  Threaded child watcher implementation.

The watcher uses a thread per process
for waiting for the process finish.

It doesn't require subscription on POSIX signal
but a thread creation is not free.

The watcher has O(1) complexity, its performance doesn't depend
on amount of spawn processes.
c                sJ    \         P                  ! ^ 4      V n        / V n        R# r   )	itertoolsr   _pid_counter_threadsr   r   r   r   Z_ThreadedChildWatcher.__init__  s    %OOA.r   c                s    \        V P                  P                  4       4       Uu. uF  pVP                  4       '       g   K  VNK  	  ppV'       d   V! V P                   R 2\
        V R7       R# R# u upi )z0 has registered but not finished child processesr#   N)r&   r  ZvaluesZis_aliver"   r*   )r    r   threadZthreadsrD   r   r   Z_ThreadedChildWatcher.__del__  sg    (,T]]-A-A-C(D )(Dfoo' 6(D )T^^$$TU! )s   A3A3c                s    \         P                  ! 4       p\        P                  ! V P                  R \        V P                  4       2WAW#3RR7      pWPP                  V&   VP                  4        R# )zasyncio-waitpid-T)ZtargetZnamer@   ZdaemonN)	r   r  	threadingZThread_do_waitpidZnextr  r  Zstart)r    ra   r?   r@   r   r  r  r   rS   Z'_ThreadedChildWatcher.add_child_handler  s`    &&(!!)9)9)9$t?P?P:Q9R'S(,8'B)-/ $cr   c                s    \         P                  ! V^ 4      w  rV\        V4      pVP                  4       '       d   \        P
                  ! RW'4       TP                  4       '       d   \        P                  ! RY4       MTP                  ! Y5T.TO5!   T P                  P                  T4       R#   \         d    Tp^p\        P                  ! RT4        Li ; i)r{   z$process %s exited with returncode %sz8Unknown child process pid %d, will report returncode 255z%Loop %r that handles pid %r is closedN)r   r  r   r   r
   r   r  r   Z	is_closedr`   r  Zpop)r    r   Zexpected_pidr?   r@   ra   r   rb   s   &&&&&   r   r  Z!_ThreadedChildWatcher._do_waitpid  s    	7**\15KC 07J~~C)7 >>NNBDN%%hZG$G,'' ! 	 CJNNJ	s   B3 3&CC)r  r  N)r   r   r   r   r   r   r(   r)   r   rS   r  r   r   r  r  r   r   r   }  s,     
 %MM ( (r   r   c                  s    \        \        R 4      '       g   R#  \        P                  ! 4       p \        P                  ! \        P                  ! V ^ 4      4       R#   \
         d     R# i ; i)r	  FT)Zhasattrr   Zgetpidr$   r	  r:   )ra   s    r   r   r     sR    2|$$iik
sA&'   s   A A A+*A+c                   s    ] tR tRtRt]tRtR# )_UnixDefaultEventLoopPolicyi  zUNIX event loop policyr   N)r   r   r   r   r   r   Z_loop_factoryr   r   r   r   r  r    s
     *Mr   r  )SelectorEventLoop	EventLoop)0r   r=   r   r  r   r   r7   rn   r|   r  r%   r  r(   Z r    r   r   r   r   r   r   r   r   r	   Zlogr
   Z__all__r   ZImportErrorr   r   ZBaseSelectorEventLoopr   ZReadTransportrG   Z_FlowControlMixinZWriteTransportrO   ZBaseSubprocessTransportrR   r   r   r   Z_BaseDefaultEventLoopPolicyr  r  Z_DefaultEventLoopPolicyr  r   r   r   <module>r     s   8  	  	      
              <<7
C
DD	
k2_BB k2\MZ55 M`Jj::(77JZ FF  0") ")H:( :(x	+&"D"D +
 + 5 	r   