~e$ ddlZddlmZddlmZddlmZddlmZddlmZddl m Z ddl m Z dd l m Z dd lmZdd lmZGd d eZddZGdde Zdidddddddf dZy)N)reactor)Deferred) DeferredList)Process) ProcessReader)ProcessProtocol) itervalues) networkString)Failure) encode_valuesceZdZdZy) SignalErrorz3An error if the process was terminated by a signal.N)__name__ __module__ __qualname____doc__z gather_results..s1-aQqT--s c.|jjSN)value subFailure)fs rrz gather_results..s177--r)r addCallback addErrback) deferredsconsume_errorsds rgather_resultsr(s6$ A MM-.LL-. Hrc*eZdZdZddZdZdZdZy)AllOutputProcessProtocolzG MM ! !' * MM " "Cd#3 4r)NN)rrrrr8r<rDrQrrrr*r*sF!( % 5rr*rTc |g} | j|t} t| | |} t|}t j | || ||||||s fd} | _| S)a Spawn a process using Twisted reactor. Return a deferred which will be called with process stdout, stderr and exit code. @param wait_pipes: if set to False, don't wait for stdin/stdout pipes to close when process ends. @param line_received: an optional callback called with every line of output from the process as parameter. @note: compared to reactor.spawnProcess, this version does NOT require the executable name as first element of args. )r4r5)argsenvpathuidgidusePTYcjr]jsQtjD]2}t|tr|j |j 4i_tjy)aA less strict version of Process.maybeCallProcessEnded. This behaves exactly like the original method, but in case the process has ended already and sent us a SIGCHLD, it doesn't wait for the stdin/stdout pipes to close, because the child process itself might have passed them to its own child processes. @note: Twisted 8.2 now has a processExited hook that could be used in place of this workaround. N) pipespidr isinstancerdoRead stopReadingrmaybeCallProcessEnded)pipeprocesss rr_z,spawn_process..maybeCallProcessEndeds`}}W[[&w}}5'D!$ 6 $$& ' !#  ) )' 2r)extendrr*r r spawnProcessr_) executablerSrTrUrVrWrX wait_pipesr5r4 list_argsresultprotocolr_ras @r spawn_processriOs6 I T ZF'#H  C""      G  3()>% Mr)F)r.twisted.internetrtwisted.internet.deferrrtwisted.internet.processrrtwisted.internet.protocolrtwisted.python.compatr r twisted.python.failurer landscape.lib.encodingr Exceptionrr(r*rirrrrrsg $+/,25,/*0>)> -5-5d     Hr