3 \@sddgZddlZddlmZddlmZddlmZddlmZdd lmZdd l m Z ej Z ej Z ej Z Gd d d ejejZGd ddZeddddejfddZeddddejdddZdS)create_subprocess_execcreate_subprocess_shellN)events) protocols)streams)tasks) coroutine)loggercsLeZdZfddZddZddZddZd d Zd d Zd dZ Z S)SubprocessStreamProtocolcs<tj|d||_d|_|_|_d|_d|_g|_dS)N)loopF) super__init___limitstdinstdoutstderr _transport_process_exited _pipe_fds)selflimitr ) __class__*/usr/lib64/python3.6/asyncio/subprocess.pyrs z!SubprocessStreamProtocol.__init__cCsf|jjg}|jdk r$|jd|j|jdk r>|jd|j|jdk rX|jd|jddj|S)Nzstdin=%rz stdout=%rz stderr=%rz<%s> )r__name__rappendrrjoin)rinforrr__repr__s    z!SubprocessStreamProtocol.__repr__cCs||_|jd}|dk rDtj|j|jd|_|jj||jj d|jd}|dk rtj|j|jd|_ |j j||jj d|jd}|dk rtj ||d|jd|_ dS)Nr)rr r)protocolreaderr ) rget_pipe_transportr StreamReaderr_looprZ set_transportrrr StreamWriterr)r transportZstdout_transportZstderr_transportZstdin_transportrrrconnection_made(s&         z(SubprocessStreamProtocol.connection_madecCs:|dkr|j}n|dkr |j}nd}|dk r6|j|dS)Nrr!)rrZ feed_data)rfddatar#rrrpipe_data_received@sz+SubprocessStreamProtocol.pipe_data_receivedcCs|dkr,|j}|dk r|j|j|dS|dkr<|j}n|dkrL|j}nd}|dkrt|dkrj|jn |j|||jkr|jj||j dS)Nrrr!) rcloseZconnection_lostrrZfeed_eofZ set_exceptionrremove_maybe_close_transport)rr*excpiper#rrrpipe_connection_lostJs$     z-SubprocessStreamProtocol.pipe_connection_lostcCsd|_|jdS)NT)rr/)rrrrprocess_exitedasz'SubprocessStreamProtocol.process_exitedcCs(t|jdkr$|jr$|jjd|_dS)Nr)lenrrrr-)rrrrr/es z/SubprocessStreamProtocol._maybe_close_transport) r __module__ __qualname__rr r)r,r2r3r/ __classcell__rr)rrr s   r c@s~eZdZddZddZeddZeddZd d Z d d Z d dZ eddZ eddZ eddZedddZdS)ProcesscCs8||_||_||_|j|_|j|_|j|_|j|_dS)N)rZ _protocolr&rrrZget_pidpid)rr(r"r rrrrlszProcess.__init__cCsd|jj|jfS)Nz<%s %s>)rrr9)rrrrr uszProcess.__repr__cCs |jjS)N)rZget_returncode)rrrr returncodexszProcess.returncodeccs|jjEdHS)N)rZ_wait)rrrrwait|sz Process.waitcCs|jj|dS)N)r send_signal)rsignalrrrr<szProcess.send_signalcCs|jjdS)N)r terminate)rrrrr>szProcess.terminatecCs|jjdS)N)rkill)rrrrr?sz Process.killccs|jj}|jj||r,tjd|t|y|jjEdHWn8tt fk rx}z|rhtjd||WYdd}~XnX|rtjd||jj dS)Nz%%r communicate: feed stdin (%s bytes)z%r communicate: stdin got %rz%r communicate: close stdin) r& get_debugrwriter debugr4ZdrainBrokenPipeErrorConnectionResetErrorr-)rinputrBr0rrr _feed_stdins     zProcess._feed_stdincCsdS)Nr)rrrr_noopsz Process._noopccs|jj|}|dkr|j}n|j}|jjrJ|dkr8dnd}tjd|||jEdH}|jjr|dkrndnd}tjd|||j |S)Nr!rrrz%r communicate: read %sz%r communicate: close %s) rr$rrr&r@r rBreadr-)rr*r(streamnameoutputrrr _read_streams   zProcess._read_streamNccs|dk r|j|}n|j}|jdk r2|jd}n|j}|jdk rP|jd}n|j}tj||||jdEdH\}}}|jEdH||fS)Nrr!)r ) rFrGrrLrrZgatherr&r;)rrErrrrrr communicates      zProcess.communicate)N)rr5r6rr propertyr:r r;r<r>r?rFrGrLrMrrrrr8ks      r8c +sPdkrtjfdd}j||f|||d|EdH\}} t|| S)Ncs tdS)N)rr )r r)rr rrsz)create_subprocess_shell..)rrr)rget_event_loopZsubprocess_shellr8) cmdrrrr rkwdsprotocol_factoryr(r"r)rr rrs)rrrr rc /sTdkrtjfdd}j||f||||d|EdH\} } t| | S)Ncs tdS)N)rr )r r)rr rrrOsz(create_subprocess_exec..)rrr)rrPZsubprocess_execr8) Zprogramrrrr rargsrRrSr(r"r)rr rrs)__all__ subprocessrrrrZ coroutinesr logr PIPEZSTDOUTZDEVNULLZFlowControlMixinZSubprocessProtocolr r8Z_DEFAULT_LIMITrrrrrrs(      X]