B °-_Vã@s°dZddlZddlmZddlmZddlmZddlmZddlmZej Z ej Z ej Z Gd d „d ej ej ƒZGd d „d ƒZddddejfd d„Zddddejdœdd„ZdS))Úcreate_subprocess_execÚcreate_subprocess_shelléNé)Úevents)Ú protocols)Ústreams)Útasks)ÚloggercsPeZdZdZ‡fdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z ‡Z S)ÚSubprocessStreamProtocolz0Like StreamReaderProtocol, but for a subprocess.cs<tƒj|d||_d|_|_|_d|_d|_g|_dS)N)ÚloopF) ÚsuperÚ__init__Ú_limitÚstdinÚstdoutÚstderrÚ _transportÚ_process_exitedÚ _pipe_fds)ÚselfÚlimitr )Ú __class__©ú(/usr/lib/python3.7/asyncio/subprocess.pyr s z!SubprocessStreamProtocol.__init__cCsn|jjg}|jdk r&| d|j›¡|jdk rB| d|j›¡|jdk r^| d|j›¡d d |¡¡S)Nzstdin=zstdout=zstderr=z<{}>ú )rÚ__name__rÚappendrrÚformatÚjoin)rÚinforrrÚ__repr__s    z!SubprocessStreamProtocol.__repr__cCs®||_| d¡}|dk rDtj|j|jd|_|j |¡|j  d¡| d¡}|dk r‚tj|j|jd|_ |j  |¡|j  d¡| d¡}|dk rªtj ||d|jd|_ dS)Nr)rr ér)ÚprotocolÚreaderr ) rÚget_pipe_transportrÚ StreamReaderrÚ_looprZ set_transportrrrÚ StreamWriterr)rÚ transportZstdout_transportZstderr_transportZstdin_transportrrrÚconnection_made's&         z(SubprocessStreamProtocol.connection_madecCs:|dkr|j}n|dkr |j}nd}|dk r6| |¡dS)Nrr!)rrZ feed_data)rÚfdÚdatar#rrrÚpipe_data_received?sz+SubprocessStreamProtocol.pipe_data_receivedcCs–|dkr,|j}|dk r| ¡| |¡dS|dkr<|j}n|dkrL|j}nd}|dk rt|dkrj| ¡n | |¡||jkrŠ|j |¡|  ¡dS)Nrrr!) rÚcloseZconnection_lostrrZfeed_eofZ set_exceptionrÚremoveÚ_maybe_close_transport)rr*ÚexcÚpiper#rrrÚpipe_connection_lostIs$     z-SubprocessStreamProtocol.pipe_connection_lostcCsd|_| ¡dS)NT)rr/)rrrrÚprocess_exited`sz'SubprocessStreamProtocol.process_exitedcCs(t|jƒdkr$|jr$|j ¡d|_dS)Nr)Úlenrrrr-)rrrrr/ds z/SubprocessStreamProtocol._maybe_close_transport) rÚ __module__Ú __qualname__Ú__doc__r r r)r,r2r3r/Ú __classcell__rr)rrr s   r c@sjeZdZdd„Zdd„Zedd„ƒZdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z ddd„ZdS)ÚProcesscCs8||_||_||_|j|_|j|_|j|_| ¡|_dS)N)rZ _protocolr&rrrZget_pidÚpid)rr(r"r rrrr kszProcess.__init__cCsd|jj›d|j›dS)Nú)rrr:)rrrrr tszProcess.__repr__cCs |j ¡S)N)rZget_returncode)rrrrÚ returncodewszProcess.returncodecÃs|j ¡IdHS)z?Wait until the process exit and return the process return code.N)rZ_wait)rrrrÚwait{sz Process.waitcCs|j |¡dS)N)rÚ send_signal)rÚsignalrrrr?szProcess.send_signalcCs|j ¡dS)N)rÚ terminate)rrrrrA‚szProcess.terminatecCs|j ¡dS)N)rÚkill)rrrrrB…sz Process.killc Ãs˜|j ¡}|j |¡|r,t d|t|ƒ¡y|j ¡IdHWn8tt fk rx}z|rht d||¡Wdd}~XYnX|rŠt d|¡|j  ¡dS)Nz%%r communicate: feed stdin (%s bytes)z%r communicate: stdin got %rz%r communicate: close stdin) r&Ú get_debugrÚwriter Údebugr4ZdrainÚBrokenPipeErrorÚConnectionResetErrorr-)rÚinputrEr0rrrÚ _feed_stdinˆs    zProcess._feed_stdincÃsdS)Nr)rrrrÚ_noop™sz Process._noopcÃs˜|j |¡}|dkr|j}n|dks(t‚|j}|j ¡rV|dkrDdnd}t d||¡|  ¡IdH}|j ¡rŒ|dkrzdnd}t d||¡|  ¡|S)Nr!rrrz%r communicate: read %sz%r communicate: close %s) rr$rÚAssertionErrorrr&rCr rEÚreadr-)rr*r(ÚstreamÚnameÚoutputrrrÚ _read_streamœs    zProcess._read_streamNcÃsŽ|dk r| |¡}n| ¡}|jdk r2| d¡}n| ¡}|jdk rP| d¡}n| ¡}tj||||jdIdH\}}}| ¡IdH||fS)Nrr!)r ) rIrJrrPrrZgatherr&r>)rrHrrrrrrÚ communicate­s      zProcess.communicate)N)rr5r6r r Úpropertyr=r>r?rArBrIrJrPrQrrrrr9js  r9c ‹sPˆdkrt ¡‰‡‡fdd„}ˆj||f|||dœ|—ŽIdH\}} t|| ˆƒS)Ncs tˆˆdS)N)rr )r r)rr rrÚÅsz)create_subprocess_shell..)rrr)rÚget_event_loopZsubprocess_shellr9) Úcmdrrrr rÚkwdsÚprotocol_factoryr(r"r)rr rrÀsr)rrrr rc sTˆdkrt ¡‰‡‡fdd„}ˆj||f|ž|||dœ|—ŽIdH\} } t| | ˆƒS)Ncs tˆˆdS)N)rr )r r)rr rrrSÓsz(create_subprocess_exec..)rrr)rrTZsubprocess_execr9) Zprogramrrrr rÚargsrVrWr(r"r)rr rrÎsr)Ú__all__Ú subprocessÚrrrrÚlogr ÚPIPEZSTDOUTZDEVNULLZFlowControlMixinZSubprocessProtocolr r9Z_DEFAULT_LIMITrrrrrrÚs"     XV