mò æû¥Dc@sþdZdkZdkZdkZdkZdklZdkZdadZ de fd„ƒYZ dd„Z d Z d e fd „ƒYZd fd „ƒYZeZeeeeiid„Zd„Zd„ZdkZdkZedjo eƒndS(s8Asynchronous-friendly error mechanism. See L{Failure}. N(sStringIOiitDefaultExceptioncBstZRS(N(t__name__t __module__(((tn/home/radix/Projects/Twisted/branches/releases/twisted-core-2.5.x-2329-2/Twisted.exp/twisted/python/failure.pyRstdefaultc Csœ|d jotd|f‚n|}|djo;xa|D],\} }}}} |d||| fƒq;Wn*|djo^x|D]O\} }}}} |d||| fƒ|dt i t i ||ƒƒƒqƒWn¿|djo±x®|D]¢\} }}}} |d||| fƒ|d ƒx.|D]&\}}|d |t|ƒfƒq+W|d ƒx.| D]&\}}|d |t|ƒfƒqfWqîWnd S(sµFormat 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: Three detail levels are available: default, brief, and verbose. @type detail: string Rtbrieftverboses3Detail must be default, brief, or verbose. (not %r)s %s:%s:%s s File "%s", line %s, in %s s %s s%s:%d: %s(...) s [ Locals ] s %s : %s s ( Globals ) N(sdefaultRsverbose(tdetailt ValueErrortwritetwtframestmethodtfilenametlinenot localVarst globalVarststringtstript linecachetgetlinetnametvaltrepr( R R RRRRRR R R R((Rt format_framess2    +     s--- ---tNoCurrentExceptionErrorcBstZdZRS(sŠ Raised when trying to create a Failure from the current interpreter exception state and there is no current exception state. (RRt__doc__(((RRCs tFailurecBs¼tZdZdZeZeeed„Zd„Zd„Zd„Z d„Z d„Z d„Z d „Z d „Zd „Zdd d „Zedd d„Zedd„Zedd„ZRS(sA basic abstraction for an error that has occurred. This is necessary because Python's built-in error mechanisms are inconvenient for asynchronous communication. @ivar value: The exception instance responsible for this failure. @ivar type: The exception's class. icCstdat|_d|_|_} t|ti ƒpt|ti ƒo@|djo3dk } | i d|tddƒt|ƒ}nd}|djoBtiƒ\|_|_} |idjo tƒ‚nd}n\|djo<t|tƒo|i|_nt|ƒ|_||_n||_||_t|itƒo|ii|_dSn| djo|o |} q‰ng}|_g} |_| |_| o | i} n"t|itƒpd} }nx&|o| o| i} |d8}qäWx¼| o´| iiƒ}| i| i!jo h}n| i!iƒ}x/||fD]!} | i$dƒo | d=q\q\W| i%d| i&i'| i&i(| i)|i*ƒ|i*ƒgƒ| i} q WxÈ| dj oº| i} | iiƒ}| i| i!jo h}n| i!iƒ}x/||fD]!} | i$dƒo | d=q*q*W|i+| i&i'| i&i(| i,|i*ƒ|i*ƒgƒ| i-} qÌWt.i/|iƒoZt0|itƒoGt1i2|iƒ}t4t1i5|ƒ|_6|i6i+t1i5|iƒƒn|ig|_6dS(s Initialize me with an explanation of the error. By default, this will use the current X{exception} (L{sys.exc_info}()). However, if you want to specify a particular kind of failure, you can pass an exception as an argument. iNsTDon't pass strings (like %r) to failure.Failure (replacing with a DefaultException).t stackleveliit __builtins__(7tcounttselftNonettypetvaluettbt isinstancet exc_valuettypest StringTypet UnicodeTypetexc_typetwarningstwarntDeprecationWarningRt stackOffsettsystexc_infoRt Exceptiont __class__Rt__dict__texc_tbR tstackttb_frametftf_backtf_localstcopytlocalzt f_globalstglobalztdthas_keytinserttf_codetco_namet co_filenametf_linenotitemstappendt tb_linenottb_nexttinspecttisclasst issubclasstreflectt allYourBasetparentCstmaptqualtparents(RR%R)R3R-R:R R<RMR*R4R=R6R#((Rt__init__XsŒ  3                   :    7& cGs$|i|Œ}|p |‚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} N(Rtcheckt errorTypesterror(RRSRT((RttrapÔs  cGsfx_|D]W}|}ti|ƒo#t|tƒoti|ƒ}n||i jo|SqqWdS(súCheck 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( RSRTterrRHRIRJR0RKRORRPR (RRSRVRT((RRRïs  cCs|i|i|i‚dS(sf raise the original exception, preserving traceback information if available. N(RR!R"R#(R((RtraiseExceptionþscCsd|i|ifS(Ns<%s %s>(RR1R!(R((Rt__repr__scCsd|iƒS(Ns[Failure instance: %s](RtgetBriefTraceback(R((Rt__str__ scCs®|io |iSn|iiƒ}g}|iD]”}||d|d|dg}|dD]$}||dt i |dƒfq_~g}|dD]$}||dt i |dƒfq˜~gq2~|d