o w[e@sdZddlZddlmZddlmZddlmZddlmZddlmZej Z ej Z ej Z Gd d d ej ej ZGd d d Zdddejfd dZdddejdddZdS))create_subprocess_execcreate_subprocess_shellN)events) protocols)streams)tasks)loggercsXeZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ Z S)SubprocessStreamProtocolz0Like StreamReaderProtocol, but for a subprocess.csHtj|d||_d|_|_|_d|_d|_g|_|j |_ dS)N)loopF) super__init___limitstdinstdoutstderr _transport_process_exited _pipe_fds_loop create_future _stdin_closed)selflimitr  __class__)/usr/lib/python3.10/asyncio/subprocess.pyr sz!SubprocessStreamProtocol.__init__cCsn|jjg}|jdur|d|j|jdur!|d|j|jdur/|d|jdd|S)Nzstdin=zstdout=zstderr=z<{}> )r__name__rappendrrformatjoin)rinforrr__repr__s    z!SubprocessStreamProtocol.__repr__cCs||_|d}|dur"tj|j|jd|_|j||j d|d}|durAtj|j|jd|_ |j ||j d|d}|durWtj ||d|jd|_ dSdS)Nrrr r)protocolreaderr ) rget_pipe_transportr StreamReaderrrr set_transportrr r StreamWriterr)r transportstdout_transportstderr_transportstdin_transportrrrconnection_made(s.        z(SubprocessStreamProtocol.connection_madecCs>|dkr|j}n |dkr|j}nd}|dur||dSdSNrr&)rr feed_data)rfddatar(rrrpipe_data_received@sz+SubprocessStreamProtocol.pipe_data_receivedcCs|dkr(|j}|dur||||dur |jddS|j|dS|dkr0|j}n |dkr8|j}nd}|durL|durG|n||||j vrW|j || dS)Nrrr&) rcloseconnection_lostr set_result set_exceptionrrfeed_eofrremove_maybe_close_transport)rr4excpiper(rrrpipe_connection_lostJs,        z-SubprocessStreamProtocol.pipe_connection_lostcCsd|_|dS)NT)rr=rrrrprocess_exitedes z'SubprocessStreamProtocol.process_exitedcCs0t|jdkr|jr|jd|_dSdSdS)Nr)lenrrrr7rArrrr=is  z/SubprocessStreamProtocol._maybe_close_transportcCs||jur|jSdSN)rr)rstreamrrr_get_close_waiterns z*SubprocessStreamProtocol._get_close_waiter) r __module__ __qualname____doc__r r$r1r6r@rBr=rF __classcell__rrrrr s    r c@sjeZdZddZddZeddZddZd d Zd d Z d dZ ddZ ddZ ddZ dddZdS)ProcesscCs8||_||_||_|j|_|j|_|j|_||_dSrD)r _protocolrrrrget_pidpid)rr-r'r rrrr tszProcess.__init__cCsd|jjd|jdS)N)rrrNrArrrr$}szProcess.__repr__cCs |jSrD)rget_returncoderArrr returncodes zProcess.returncodecs|jIdHS)z?Wait until the process exit and return the process return code.N)r_waitrArrrwaitsz Process.waitcCs|j|dSrD)r send_signal)rsignalrrrrUszProcess.send_signalcC|jdSrD)r terminaterArrrrXzProcess.terminatecCrWrD)rkillrArrrrZrYz Process.killc s|j}|j||rtd|t|z |jIdHWntt fy>}z|r4td||WYd}~nd}~ww|rGtd||j dS)Nz%%r communicate: feed stdin (%s bytes)z%r communicate: stdin got %rz%r communicate: close stdin) r get_debugrwriter debugrCdrainBrokenPipeErrorConnectionResetErrorr7)rinputr]r>rrr _feed_stdins"    zProcess._feed_stdincsdSrDrrArrr_noopsz Process._noopcs|j|}|dkr|j}n |dksJ|j}|jr,|dkr#dnd}td|||IdH}|jrG|dkr>dnd}td||| |S)Nr&rrrz%r communicate: read %sz%r communicate: close %s) rr)rrrr[r r]readr7)rr4r-rEnameoutputrrr _read_streams    zProcess._read_streamNcs|dur ||}n|}|jdur|d}n|}|jdur)|d}n|}t|||IdH\}}}|IdH||fSr2)rbrcrrgrrgatherrT)rrarrrrrr communicates     zProcess.communicaterD)rrGrHr r$propertyrRrTrUrXrZrbrcrgrirrrrrKss  rKc sJtfdd}j||f|||d|IdH\}}t||S)Nc tdSNr%r rr%rrz)create_subprocess_shell..rrr)rget_running_loopsubprocess_shellrK) cmdrrrrkwdsprotocol_factoryr-r'rr%rrs r)rrrrc sPtfdd}j||g|R|||d|IdH\}} t|| S)Ncrkrlrmrr%rrrnroz(create_subprocess_exec..rp)rrqsubprocess_execrK) programrrrrargsrtrur-r'rr%rrs r)__all__ subprocessrrrrlogr PIPESTDOUTDEVNULLFlowControlMixinSubprocessProtocolr rK_DEFAULT_LIMITrrrrrrs(     bU