Rc@sxdZddlZddlZddlmZddlmZmZddlm Z ddl m Z m Z m Z yddlmZWnek rdZnXy ddUWn-ek rd Znek rd ZnXd efd YZd ZdefdYZddZddZddZdZdZdZedkrty eZWnnX[ndS(sQ jinja2.debug ~~~~~~~~~~~~ Implements the debug interface for Jinja. This module does some pretty ugly stuff with the Python traceback system in order to achieve tracebacks with correct line numbers, locals and contents. :copyright: (c) 2010 by the Jinja Team. :license: BSD, see LICENSE for more details. iN(t TracebackType(tmissingt internal_code(tTemplateSyntaxError(t iteritemstreraiset code_type(ttproxysraise TypeError, 'foo'sraise __jinja_exception__[1]s4raise __jinja_exception__[0], __jinja_exception__[1]tTracebackFrameProxycBsGeZdZdZedZdZedZdZRS(sProxies a traceback frame.cCs||_d|_dS(N(ttbtNonet_tb_next(tselfR ((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyt__init__'s cCs|jS(N(R (R ((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyttb_next+scCsStdk rFy#t|j|r'|jp*dWqFtk rBqFXn||_dS(N(t tb_set_nextR R t ExceptionR (R tnext((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytset_next/s  # cCsd|jjjkS(Nt__jinja_template__(R ttb_framet f_globals(R ((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytis_jinja_frame:scCst|j|S(N(tgetattrR (R tname((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyt __getattr__>s( t__name__t __module__t__doc__R tpropertyRRRR(((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyR$s   cs8t|tdkrSfd}tt|S(NcsV|dkrt|dS|dkr<j||nt|||SdS(Nt__getattribute__Rit __setattr__(s__getattribute__s __getattr__(RR(t operationtargstkwargs(tproxy(s0/usr/lib/python2.7/site-packages/jinja2/debug.pytoperation_handlerFs   (RRR R(tframeR$((R#s0/usr/lib/python2.7/site-packages/jinja2/debug.pytmake_frame_proxyBs   tProcessedTracebackcBs\eZdZdZddZedZedZ edZ edZ RS(s?Holds a Jinja preprocessed traceback for printing or reraising.cCsh||_||_||_d}x3|jD](}|dk rM|j|n|}q+W|jddS(N(texc_typet exc_valuetframesR R(R R(R)R*tprev_tbR ((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyR Ss     cCs;tj|j|j|jdd|}dj|jS(s#Return a string with the traceback.itlimitt(t tracebacktformat_exceptionR(R)R*tjointrstrip(R R,tlines((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytrender_as_textascCs<ddlm}d||d||jjddfS(s<Return a unicode string with the traceback as rendered HTML.i(trender_tracebacku%s tfullsutf-8treplace(tjinja2.debugrendererR4R3tdecode(R R5R4((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytrender_as_htmlgscCst|jtS(s*`True` if this is a template syntax error.(t isinstanceR)R(R ((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytis_template_syntax_erroroscCs|j|j|jdfS(s;Exception info tuple with a proxy around the frame objects.i(R(R)R*(R ((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytexc_infotscCs>|jd}t|tk r+|j}n|j|j|fS(s'Standard python exc_info for re-raisingi(R*ttypeRR R(R)(R R ((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytstandard_exc_infoys  N( RRRR R R3tFalseR9RR;R<R>(((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyR'Ps   cCsI|\}}}t|tr6t||}d}nd}t||S(s7Creates a processed traceback object from the exc_info.ii(R:Rttranslate_syntax_errorttranslate_exception(R<t source_hintR(R)R t initial_skip((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytmake_tracebacks  cCsU||_t|_|j|df}|j}|dkrBd}nt|||jS(s4Rewrites a syntax error to please traceback systems.s N(tsourcetTruet translatedt __class__R tfilenamet fake_exc_infotlineno(terrorRER<RI((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyR@s     ic Cs2|d}g}x,t|D]}|dk r|j}qqW|}x|dk r|jjtkru|j}qHn|j}|jjjd}|dk r|j|j }t |d |f|j |d}n|j t ||}qHW|st|d|d|dnt|d|d|S(sIf passed an exc_info it will automatically rewrite the exceptions all the way down to the correct line numbers and frames. iRiiN(trangeR RRtf_codeRRtgettget_corresponding_linenot tb_linenoRJRItappendR&RR'( R<RCR R*txt initial_tbRttemplateRK((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyRAs*      cBs|\}}}|dk r|jjj}|jd}|rQ|j}ni}xFe|D]8\} } | jdrd| ek rd| || d s>          4 , E @