m๒ +แธEc@sodkZdkZdklZdklZlZlZdklZl Z dk l Z dfd„ƒYZ dS(N(sStringIO(s ParseErrors parse_paramss render_blocks(s namespaces InstanceDict(sDTReturntTrycBsbtZdZdZd ZeZeZd„Zd„Z d„Z d„Z d „Z d „Z e ZRS( s` Zope DTML Exception handling usage: or: The DTML try tag functions quite like Python's try command. The contents of the try tag are rendered. If an exception is raised, then control switches to the except blocks. The first except block to match the type of the error raised is rendered. If an except block has no name then it matches all raised errors. The try tag understands class-based exceptions, as well as string-based exceptions. Note: the 'raise' tag raises string-based exceptions. Inside the except blocks information about the error is available via three variables. 'error_type' -- This variable is the name of the exception caught. 'error_value' -- This is the caught exception's value. 'error_tb' -- This is a traceback for the caught exception. The optional else block is rendered when no exception occurs in the try block. Exceptions in the else block are not handled by the preceding except blocks. The try..finally form specifies a `cleanup` block, to be rendered even when an exception occurs. Note that any rendered result is discarded if an exception occurs in either the try or finally blocks. The finally block is only of any use if you need to clean up something that will not be cleaned up by the transaction abort code. The finally block will always be called, wether there was an exception in the try block or not, or wether or not you used a return tag in the try block. Note that any output of the finally block is discarded if you use a return tag in the try block. If an exception occurs in the try block, and an exception occurs in the finally block, or you use the return tag in that block, any information about that first exception is lost. No information about the first exception is available in the finally block. Also, if you use a return tag in the try block, and an exception occurs in the finally block or you use a return tag there as well, the result returned in the try block will be lost. Original version by Jordan B. Baker. Try..finally and try..else implementation by Martijn Pieters. ttrytexcepttelsetfinallyc Csฎ|d\}}}t|ƒ|_|i|_t|ƒdjo-|dddjo|ddi|_n=g|_d}x*|dD]\}}}|djo6|i dj otd|if‚n|i|_ qˆ|djotd|if‚qˆ|i dj otd|if‚nx-|iƒD]}|ii||ifƒq0W|iƒd jo@|otd |if‚qฆd}|iid |ifƒqˆqˆWdS( NiiiRRs&No more than one else block is allowedsRA try..finally combination cannot contain any other else, except or finally blockss4The else block should be the last block in a try tagts-Only one default exception handler is allowed(tblocksttnametargstsectiont parse_paramstselftlent finallyBlockthandlerstdefaultHandlerFoundtnargstnsectiont elseBlocktNonet ParseErrortnametsplitterrnametappendtstrip( R RRRRRRRR ((t6/data/zmath/zope/lib/python/DocumentTemplate/DT_Try.pyt__init__Zs2 (     cCs2|idjo|i|ƒSn|i|ƒSdS(N(R R Rtrender_try_excepttmdtrender_try_finally(R R((RtrenderŠsc CsOd} yt|i|ƒ} Wntj o ‚ntiƒd \}}t |ƒt dƒjo |}n |i }|i |ƒ}|djo‚nzntƒ}tid|ƒ|iƒ}t|d|d|d|ƒd}|it||ƒƒt||ƒSWd|idƒXn-X|idjo| Sn| t|i|ƒSdS( NRiidt error_typet error_valueterror_tbii(tresultt render_blocksR R RtDTReturntsystexc_infotttvttypeRt__name__t find_handlerthandlerRtStringIOtft tracebackt print_exctgetvalueR"t namespacetnst_pusht InstanceDictt_popR( R RRR/R-R(R)R4R"R#((RRs4     cCs:d}zt|i|ƒ}Wd|t|i|ƒ}X|S(NR(R#R$R R RR (R RR#((RRนs cCsณt|ƒtdƒjoDxA|iD].\}}||jp |djo|Sq#q#WdSnxO|iD]D\}}||ijp |djp|i||ƒo|SqgqgWdS(s6recursively search for a handler for a given exceptionRN( R*t exceptionR RtethRR+t match_base(R R8R9R:((RR,รs   0 cCsCx<|iD]1}|i|jp|i||ƒodSq q WdS(Ni(R8t __bases__tbaseR+RR R;R(R R8RR=((RR;ะs  # (Rselsesfinally(R+t __module__t__doc__RtblockContinuationsRR RRRRRR,R;t__call__(((RRs ? 0  ) ( R&R0t cStringIOR.tDT_UtilRR R$R3R6t DT_ReturnR%R( RR%R.R0R3RR&R$R6R ((Rt?s