Ϫf!8dZddlZddlZddlmZddlmZddlmZm Z ddl m Z  ddZ Gd d e ZGd d e jZdidddfd ZGdde jZdiddfdZGdde jZdidddfdZdZdZdZgdZy)z Utility methods. Nwraps)BytesIO)deferprotocol)failurec|ddlm}tj}||g|}|j |||ft |z|||S)Nr)reactor)twisted.internetr rDeferred spawnProcesstuple) r executableargsenvpathr protoArgsdps 8/usr/lib/python3/dist-packages/twisted/internet/utils.py_callProtocolWithDeferredrsM, AYA J d (CS$O HceZdZdZdZy)_UnexpectedErrorOutputay Standard error data was received where it was not expected. This is a subclass of L{IOError} to preserve backward compatibility with the previous error behavior of L{getProcessOutput}. @ivar processEnded: A L{Deferred} which will fire when the process which produced the data on stderr has ended (exited and all file descriptors closed). cDtj|d|||_y)Nz got stderr: )IOError__init__ processEnded)selftextrs rrz_UnexpectedErrorOutput.__init__*s!dX67(rN)__name__ __module__ __qualname____doc__rr rrrrs )rrc0eZdZdZddZdZdZdZdZy) _BackRelaya Trivial protocol for communicating with a process and turning its output into the result of a L{Deferred}. @ivar deferred: A L{Deferred} which will be called back with all of stdout and, if C{errortoo} is true, all of stderr as well (mixed together in one string). If C{errortoo} is false and any bytes are received over stderr, this will fire with an L{_UnexpectedErrorOutput} instance and the attribute will be set to L{None}. @ivar onProcessEnded: If C{errortoo} is false and bytes are received over stderr, this attribute will refer to a L{Deferred} which will be called back when the process ends. This C{Deferred} is also associated with the L{_UnexpectedErrorOutput} which C{deferred} fires with earlier in this case so that users can determine when the process has actually ended, in addition to knowing when bytes have been received via stderr. cz||_t|_|r|j|_y|j |_yN)deferredrserrReceivedIsGood errReceivederrReceivedIsBad)r r*errortoos rrz_BackRelay.__init__Bs1   #55D #44D rc|jtj|_t ||j}|jj t j|d|_|jjyyr)) r*rr onProcessEndedrerrbackrFailure transportloseConnection)r r!errs rr.z_BackRelay.errReceivedIsBadJsd == $"'.."2D (t/B/BCC MM ! !'//#"6 7 DM NN ) ) + %rc:|jj|yr)r+writer r!s rr,z_BackRelay.errReceivedIsGoodR  Trc:|jj|yr)r8r:s r outReceivedz_BackRelay.outReceivedUr;rc|j4|jj|jjy|j|jj |yyr))r*callbackr+getvaluer1r2r reasons rrz_BackRelay.processEndedXsN == $ MM " "466??#4 5  ,    ' ' /-rN)r) r"r#r$r%rr.r,r=rr rrr'r'/s $5,0rr'c*tfd|||||S)a Spawn a process and return its output as a deferred returning a L{bytes}. @param executable: The file name to run and get the output of - the full path should be used. @param args: the command line arguments to pass to the process; a sequence of strings. The first string should B{NOT} be the executable's name. @param env: the environment variables to pass to the process; a dictionary of strings. @param path: the path to run the subprocess in - defaults to the current directory. @param reactor: the reactor to use - defaults to the default reactor @param errortoo: If true, include stderr in the result. If false, if stderr is received the returned L{Deferred} will errback with an L{IOError} instance with a C{processEnded} attribute. The C{processEnded} attribute refers to a L{Deferred} which fires when the executed process ends. ct|S)N)r/)r')rr/s rz"getProcessOutput..ys*Q2r)r)rrrrr r/s `rgetProcessOutputrF_s 2 %2Jc4QX rceZdZdZdZy) _ValueGetterc||_yr))r*)r r*s rrz_ValueGetter.__init__~s   rcb|jj|jjyr))r*r?valueexitCoderAs rrz_ValueGetter.processEndeds v||445rN)r"r#r$rrr rrrHrH}s !6rrHc*tt|||||S)z7Spawn a process and return its exit code as a Deferred.)rrH)rrrrr s rgetProcessValuerNs $\:tS$PW XXrc eZdZddZdZdZy)_EverythingGetterNc||_t|_t|_|jj|_|jj|_||_yr))r*routBuferrBufr9r=r- stdinBytes)r r*rTs rrz_EverythingGetter.__init__sF  i i ;;,,;;,,$rc|jA|jjd|j|jjyy)Nr)rTr4 writeToChild closeStdin)r s rconnectionMadez _EverythingGetter.connectionMades; ?? & NN ' '4?? ; NN % % ' 'rcB|jj}|jj}|j}|j}|j r)|j j|||j fy|j j|||fyr)) rRr@rSrKrLsignalr*r2r?)r rBoutr6ecodes rrz_EverythingGetter.processEndedsukk""$kk""$ LLzz 88 MM ! !3QXX"6 7 MM " "Cd#3 4rr))r"r#r$rrXrr rrrPrPs%(5rrPc 0tt||||||fS)a.Spawn a process and returns a Deferred that will be called back with its output (from stdout and stderr) and it's exit code as (out, err, code) If a signal is raised, the Deferred will errback with the stdout and stderr up to that point, along with the signal, as (out, err, signalNum) )r)rrP)rrrrr rTs rgetProcessOutputAndValuer_s( %   - rcr|D]"} tjj|$|S#t$rY2wxYwr))warningsfiltersremove ValueError) passthrough addedFiltersfs r_resetWarningFiltersrhsF      # #A &    s * 66c|D]\}}tj|i|tjdt|} ||i|}t |t j r|jt||Std||S#t$r8tj}td||dj|dwxYw)a} Run the function I{f}, but with some warnings suppressed. This calls L{warnings.filterwarnings} to add warning filters before invoking I{f}. If I{f} returns a L{Deferred} then the added filters are removed once the deferred fires. Otherwise they are removed immediately. Note that the list of warning filters is a process-wide resource, so calling this function will affect all threads. @param suppressedWarnings: A list of arguments to pass to L{warnings.filterwarnings}, a sequence of (args, kwargs) 2-tuples. @param f: A callable, which may return a L{Deferred}. @param a: Positional arguments passed to I{f} @param kw: Keyword arguments passed to I{f} @return: The result of C{f(*a, **kw)} @seealso: L{twisted.python.util.runWithWarningsSuppressed} functions similarly, but doesn't handled L{Deferred}s. N) rafilterwarningsrblen isinstancerr addBothrh BaseExceptionsysexc_infowith_traceback) suppressedWarningsrgakwrkwargsrfresultrrs rrunWithWarningsSuppressedrys4+1 f001##$=c*<&=>L A fenn - NN/ >  !| 4  6<<>T<0qk((!556s BACc2tfd}|S)z Wrap C{f} in a callable which suppresses the indicated warnings before invoking C{f} and unsuppresses them afterwards. If f returns a Deferred, warnings will remain suppressed until the Deferred fires. c$tg|i|Sr))ry)rurvrgrts rwarningSuppressingWrapperz3suppressWarnings..warningSuppressingWrappers();QIIbIIrr)rgrtr|s`` rsuppressWarningsr}s% 1XJJ %$r)ryr}rFrNr_)Nr )r%rqra functoolsriorr rrtwisted.pythonrrrrProcessProtocolr'rFrHrNrPr_rhryr}__all__r rrrs   ,"DF   )W ) -0))-0`')btTTU<68++6&(RdDY 50058RdDT&(V % r