Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/internet/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/internet/utils.pyc


[XMc@s]dZddlZddlZddlmZmZddlmZmZ	yddl
ZWnek
ryddlZnXddZdefdYZdejfd	YZdiddd
dZdejfd
YZdidddZdejfdYZdidddZdZdZdZdddddgZdS(s
Utility methods.
iN(tprotocoltdefer(tfailuretutilcCsa|dkrddlm}ntj}||}|j|||ft||||S(Ni(treactor(tNonettwisted.internetRRtDeferredtspawnProcessttuple(Rt
executabletargstenvtpathRtdtp((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyt_callProtocolWithDeferreds&t_UnexpectedErrorOutputcBseZdZdZRS(sy
    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).
    cCs$tj|d|f||_dS(Nsgot stderr: %r(tIOErrort__init__tprocessEnded(tselfttextR((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyR(s(t__name__t
__module__t__doc__R(((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyRs	t
_BackRelaycBs>eZdZddZdZdZdZdZRS(s
    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 C{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.
    icCs=||_tj|_|r-|j|_n|j|_dS(N(tdeferredtStringIOtsterrReceivedIsGoodterrReceivedterrReceivedIsBad(RRterrortoo((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyRAs
	cCsf|jdk	rbtj|_t||j}|jjtj|d|_|j	j
ndS(N(RRRRtonProcessEndedRterrbackRtFailuret	transporttloseConnection(RRterr((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyR Is	cCs|jj|dS(N(Rtwrite(RR((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyRQscCs|jj|dS(N(RR((RR((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pytoutReceivedTscCsQ|jdk	r+|jj|jjn"|jdk	rM|jj|ndS(N(RRtcallbackRtgetvalueR"R#(Rtreason((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyRWs(RRRRR RR)R(((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyR.s			ics"tfd|||||S(s
    Spawn a process and return its output as a deferred returning a string.

    @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 *NOT* be the
                 executable's name.

    @param env: the environment variables to pass to the processs; 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.
    cst|dS(NR!(R(R(R!(s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyt<lambda>ys(R(R
RRR
RR!((R!s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pytgetProcessOutput_st_ValueGettercBseZdZdZRS(cCs
||_dS(N(R(RR((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyRscCs|jj|jjdS(N(RR*tvaluetexitCode(RR,((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyRs(RRRR(((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyR/s	cCstt|||||S(s7Spawn a process and return its exit code as a Deferred.(RR/(R
RRR
R((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pytgetProcessValuest_EverythingGettercBseZdZdZRS(cCsI||_tj|_tj|_|jj|_|jj|_dS(N(RRtoutBufterrBufR(R)R(RR((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyRs
	cCsu|jj}|jj}|j}|j}|jrX|jj|||jfn|jj|||fdS(N(	R4R+R5R0R1tsignalRR#R*(RR,toutR'tetcode((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyRs			(RRRR(((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyR3s	cCstt|||||S(s.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)
    (RR3(R
RRR
R((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pytgetProcessOutputAndValuescCs=x6|D].}ytjj|Wqtk
r4qXqW|S(N(twarningstfilterstremovet
ValueError(tpassthroughtaddedFilterstf((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyt_resetWarningFilterss

c	Osx$|D]\}}tj||qWtjt| }y|||}Wn8tj}td||d|d|dn7Xt|t	j
r|jt|n
td||SdS(s%Run the function C{f}, but with some warnings suppressed.

    @param suppressedWarnings: A list of arguments to pass to filterwarnings.
                               Must be a sequence of 2-tuples (args, kwargs).
    @param f: A callable, followed by its arguments and keyword arguments
    iiiN(R;tfilterwarningsR<tlentsystexc_infoRBRt
isinstanceRRtaddBoth(	tsuppressedWarningsRAtatkwRtkwargsR@tresultRF((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pytrunWithWarningsSuppresseds

cs"fd}tj|S(s
    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.
    cst||S(N(RN(RJRK(RIRA(s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pytwarningSuppressingWrappers(ttputiltmergeFunctionMetadata(RARIRO((RIRAs:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pytsuppressWarningssRNRRR.R2R:((((RRER;RRRttwisted.pythonRRRPt	cStringIORtImportErrorRRRRtProcessProtocolRR.R/R2R3R:RBRNRRt__all__(((s:/usr/lib/python2.7/dist-packages/twisted/internet/utils.pyt<module>s,
1