Your IP : 172.28.240.42


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


@Nc@sKdZddlZddlZddlZddlZddlmZddlmZddlm	Z	da
dZdefd	YZ
d
dZdZd
efdYZdefdYZdefdYZdefdYZdfdYZdZeZeeeeejjdZdZddlZdS(s9
Asynchronous-friendly error mechanism.

See L{Failure}.
iN(tStringIO(tgetmro(treflectiitDefaultExceptioncBseZRS((t__name__t
__module__(((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRstdefaultcCs|dkr"td|fn|}|dkrnx|D],\}}}}}|d|||fq;Wnr|dkrxc|D]L\}}}}}|d|||f|dtj||jqWn|dkr$x4|D],\}}}}}|d	|||fqW|d
n|dkrx|D]\}}}}}|d	|||f|dx.|D]&\}	}
|d|	t|
fqtW|d
x.|D]&\}	}
|d|	t|
fqWq7WndS(sFormat and write frames.

    @param frames: is a list of frames as used by Failure.frames, with
        each frame being a list of
        (funcName, fileName, lineNumber, locals.items(), globals.items())
    @type frames: list
    @param write: this will be called with formatted strings.
    @type write: callable
    @param detail: Four detail levels are available:
        default, brief, verbose, and verbose-vars-not-captured.
        C{Failure.printDetailedTraceback} uses the latter when the caller asks
        for verbose, but no vars were captured, so that an explicit warning
        about the missing data is shown.
    @type detail: string
    Rtbrieftverbosesverbose-vars-not-capturedsNDetail must be default, brief, verbose, or verbose-vars-not-captured. (not %r)s	%s:%s:%s
s  File "%s", line %s, in %s
s    %s
s%s:%d: %s(...)
sA [Capture of Locals and Globals disabled (use captureVars=True)]
s [ Locals ]
s
  %s : %s
s
 ( Globals )
N(sdefaultRsverbosesverbose-vars-not-captured(t
ValueErrort	linecachetgetlinetstriptrepr(tframestwritetdetailtwtmethodtfilenametlinenot	localVarst
globalVarstnametval((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyt
format_framess4	'


s--- <exception caught here> ---tNoCurrentExceptionErrorcBseZdZRS(s
    Raised when trying to create a Failure from the current interpreter
    exception state and there is no current exception state.
    (RRt__doc__(((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRPst
_TracebackcBseZdZdZRS(sq
    Fake traceback object which can be passed to functions in the standard
    library L{traceback} module.
    cCst|dkstd|d|d}}|\}}}}}t|||_||_t|dkrd|_nt||_dS(s]
        Construct a fake traceback object using a list of frames. Note that
        although frames generally include locals and globals, this information
        is not kept by this object, since locals and globals are not used in
        standard tracebacks.

        @param frames: [(methodname, filename, lineno, locals, globals), ...]
        isMust pass some framesiN(tlentAssertionErrort_Framettb_framet	tb_linenotNonettb_nextR(tselfRtheadRRRtlocalztglobalz((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyt__init__]s		(RRRR((((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRWsRcBseZdZdZRS(s
    A fake frame object, used by L{_Traceback}.

    @ivar f_code: fake L{code<types.CodeType>} object
    @ivar f_globals: fake f_globals dictionary (usually empty)
    @ivar f_locals: fake f_locals dictionary (usually empty)
    cCs(t|||_i|_i|_dS(s
        @param name: method/function name for this frame.
        @type name: C{str}
        @param filename: filename for this frame.
        @type name: C{str}
        N(t_Codetf_codet	f_globalstf_locals(R$RR((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyR(zs	(RRRR((((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRqsR)cBseZdZdZRS(sB
    A fake code object, used by L{_Traceback} via L{_Frame}.
    cCs||_||_dS(N(tco_nametco_filename(R$RR((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyR(s	(RRRR((((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyR)stFailurecBseZdZdZdZeejdZ	ddde
dZdZdZ
dZdZdZeeZd	Zd
ZdZdZd
ZdZdZdddZde
ddZdddZdddZRS(s
    A basic abstraction for an error that has occurred.

    This is necessary because Python's built-in error mechanisms are
    inconvenient for asynchronous communication.

    The C{stack} and C{frame} attributes contain frames.  Each frame is a tuple
    of (funcName, fileName, lineNumber, localsItems, globalsItems), where
    localsItems and globalsItems are the contents of
    C{locals().items()}/C{globals().items()} for that frame, or an empty tuple
    if those details were not captured.

    @ivar value: The exception instance responsible for this failure.
    @ivar type: The exception's class.
    @ivar stack: list of frames, innermost last, excluding C{Failure.__init__}.
    @ivar frames: list of frames, innermost first.
    itYIELD_VALUEc	Cstdat|_d|_|_}||_t|ttfr|dkrddl}|j	d|t
ddt|}nd}|dkr|j}n|dkrt
j\|_|_}|jdkrtnd}nW|dkr7t|tr|j|_nt||_||_n||_||_t|jtrn|jj|_dS|dkr|r|}qng}|_g}	|_||_|r|j}
nt|jtsd}
}nx#|r|
r|
j}
|d8}qWx|
r|r|
jj}|
j|
jkr?i}n|
jj}x*||fD]}
d|
kr[|
d=q[q[W|j}|j}n
d	}}|	jd|
jj|
jj |
j!||f|
j}
q	Wx|dk	r|j}
|rz|
jj}|
j|
jkr#i}n|
jj}x*||fD]}
d|
kr?|
d=q?q?W|j}|j}n
d
}}|j"|
jj|
jj |j#||f|j$}qWt%j&|jrt'|jtrt(|j}t)t*j+||_,n|jg|_,dS(s-
        Initialize me with an explanation of the error.

        By default, this will use the current C{exception}
        (L{sys.exc_info}()).  However, if you want to specify a
        particular kind of failure, you can pass an exception as an
        argument.

        If no C{exc_value} is passed, then an "original" C{Failure} will
        be searched for. If the current exception handler that this
        C{Failure} is being constructed in is handling an exception
        raised by L{raiseException}, then this C{Failure} will act like
        the original C{Failure}.

        For C{exc_tb} only L{traceback} instances or C{None} are allowed.
        If C{None} is supplied for C{exc_value}, the value of C{exc_tb} is
        ignored, otherwise if C{exc_tb} is C{None}, it will be found from
        execution context (ie, L{sys.exc_info}).

        @param captureVars: if set, capture locals and globals of stack
            frames.  This is pretty slow, and makes no difference unless you
            are going to use L{printDetailedTraceback}.
        iiNsTDon't pass strings (like %r) to failure.Failure (replacing with a DefaultException).t
stackleveliit__builtins__(((-tcountR"ttypetvaluetcaptureVarst
isinstancetstrtunicodetwarningstwarntDeprecationWarningRt_findFailuretsystexc_infoRt	Exceptiont	__class__R/t__dict__RtstackttbR tf_backR,tcopyR+titemstinsertR*R-R.tf_linenotappendR!R#tinspecttisclasst
issubclassRtmapRtqualtparents(R$t	exc_valuetexc_typetexc_tbR6RDR:tstackOffsetRRCtfR&R'tdtparentCs((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyR(s
		!			

	
	
		
			

		
		

$cGs"|j|}|s|n|S(sTrap this failure if its type is in a predetermined list.

        This allows you to trap a Failure in an error callback.  It will be
        automatically re-raised if it is not a type that you expect.

        The reason for having this particular API is because it's very useful
        in Deferred errback chains::

            def _ebFoo(self, failure):
                r = failure.trap(Spam, Eggs)
                print 'The Failure is due to either Spam or Eggs!'
                if r == Spam:
                    print 'Spam did it!'
                elif r == Eggs:
                    print 'Eggs did it!'

        If the failure is not a Spam or an Eggs, then the Failure
        will be 'passed on' to the next errback.

        @type errorTypes: L{Exception}
        (tcheck(R$t
errorTypesterror((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyttrapBs	cGs^xW|D]O}|}tj|rCt|trCtj|}n||jkr|SqWdS(sCheck if this failure's type is in a predetermined list.

        @type errorTypes: list of L{Exception} classes or
                          fully-qualified class names.
        @returns: the matching L{Exception} type, or None if no match.
        N(RKRLRMR@RRORPR"(R$RYRZterr((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRX]s
cCs|j|j|jdS(sf
        raise the original exception, preserving traceback
        information if available.
        N(R4R5RD(R$((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pytraiseExceptionmscCs|j|j|j|jS(sJ
        Throw the original exception into the given generator,
        preserving traceback information if available.

        @return: The next value yielded from the generator.
        @raise StopIteration: If there are no more values in the generator.
        @raise anything else: Anything that the generator raises.
        (tthrowR4R5RD(R$tg((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pytthrowExceptionIntoGeneratorus	cCstjd}|sdSd}|}x|jrD|}|j}q)W|j}|j|jjkrs|jj	dS|jj
s|jj
|j|jkrdS|r|j}|j|j
jkr|jj	dSn|jj}|r|j|j
jkr|jj	dSdS(sV
        Find the failure that represents the exception currently in context.
        iNR$(R>R?R"R#R R*R]t	func_codeR,tgettco_codettb_lastit_yieldOpcodeR`RE(tclsRDtsecondLastTbtlastTbt	lastFrametframe((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyR=s*
		
	cCsd|j|jfS(Ns<%s %s>(RAR4(R$((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyt__repr__scCsd|jS(Ns[Failure instance: %s](tgetBriefTraceback(R$((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyt__str__sc	Cs|jr|jS|jj}g|jD];}|d|d|dt|dt|dg^q)|d<d
|d<|jd
k	rg|jD];}|d|d|dt|dt|dg^q|d<nd|d	<|S(s1Avoid pickling objects in the traceback.
        iiiiiRRDRCtpickledN(RnRBRFRt
_safeReprVarsR"RC(R$tctv((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyt__getstate__s	L
O
cCs|j|_dS(sIRemove references to other objects, replacing them with strings.
        N(RrRB(R$((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pytcleanFailurescCs@|jdk	r|jSt|jdkr8t|jSdSdS(s
        Get an object that represents this Failure's stack that can be passed
        to traceback.extract_tb.

        If the original traceback object is still present, return that. If this
        traceback object has been lost but we still have the information,
        return a fake traceback object (see L{_Traceback}). If there is no
        traceback information at all, return None.
        iN(RDR"RRR(R$((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pytgetTracebackObjects


cCs/t|jtr|jjStj|jS(s8Get a string of the exception which caused this Failure.(R7R5R/tgetErrorMessageRtsafe_str(R$((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRus
cCs#t}|jd||jS(Ntfile(RtprintBriefTracebacktgetvalue(R$tio((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRls	RcCs/t}|jd|d|d||jS(NRwtelideFrameworkCodeR(RtprintTracebackRy(R$R{RRz((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pytgetTracebacks	cCs|dkrtj}n|j}|dkr@|jr@d}n|}|dkr{|d|j|jrmdppdfn`|dkr|jrd}nd}|d	|tj	|j
tj	|jfn
|d
|jr,|st|j
t|||dtfnt|j||n|dksE|dn|dkst|j
ttfr}||j
d
q|dtj|j
tj	|jfnt|jtr|jd|jj|||n|dkr|d|jndS(s
        Emulate Python's standard error reporting mechanism.

        @param file: If specified, a file-like object to which to write the
            traceback.

        @param elideFrameworkCode: A flag indicating whether to attempt to
            remove uninteresting frames from within Twisted itself from the
            output.

        @param detail: A string indicating how much information to include
            in the traceback.  Must be one of C{'brief'}, C{'default'}, or
            C{'verbose'}.
        Rsverbose-vars-not-captureds*--- Failure #%d%s---
s (pickled) t Rt	Tracebacks"Traceback (failure with no frames)s%s: %s: %s
s#Traceback (most recent call last):
s%s
s	Failure: s
s%s: %s
s (chained Failure)
s*--- End of Failure #%d ---
N(R"tlogtlogerrRR6R3RnRRRvR4R5RRCt
traceupLengthtEXCEPTION_CAUGHT_HERER7R8R9ROR/R|(R$RwR{RRtformatDetailt	hasFrames((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyR|sH				
	

cCs|j||dddS(s2Print a traceback as densely as possible.
        RRN(R|(R$RwR{((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRxSscCs|j||dddS(sHPrint a traceback with detailed locals and globals information.
        RRN(R|(R$RwR{((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pytprintDetailedTracebackXsN(RRRRnR"RCtchrtopcodetopmapRetFalseR(R[RXR]R`R=tclassmethodRkRmRrRsRtRuRlR}R|RxR(((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyR/s.						8			 				KcCs,g|D]!\}}|tj|f^qS(sq
    Convert a list of (name, object) pairs into (name, repr) pairs.

    L{twisted.python.reflect.safe_repr} is used to generate the repr, so no
    exceptions will be raised by faulty C{__repr__} methods.

    @param varsDictItems: a sequence of (name, value) pairs as returned by e.g.
        C{locals().items()}.
    @returns: a sequence of (name, repr) pairs.
    (Rt	safe_repr(t
varsDictItemsRtobj((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyRo^sc	Cs|||fdkrtj}|d|jkrtryt|d}Wn
d}nXd|fGHddl}|j|dqn||||||dS(	s;
    Initialize failure object, possibly spawning pdb.
    iis
broken strs8Jumping into debugger for post-mortem of exception '%s':iNi(NNN(R"R>R?RAtDO_POST_MORTEMR8tpdbtpost_mortem(	R$RQRRRSR6tFailure__init__texctstrreprR((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyt
_debuginitps
cCs
tt_dS(s Enable debug hooks for Failures.N(RR/R((((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pytstartDebugModes( RR>R
RKRt	cStringIORRttwisted.pythonRR3RR@RRRRtobjectRRR)R/RotTrueRR"RR(tim_funcRRR(((s:/usr/lib/python2.7/dist-packages/twisted/python/failure.pyt<module>s2.