ó ÈÏRc@sxdZddlZddlZddlmZddlmZmZddlm Z ddl m Z m Z m Z yddlmZWnek rdZnXy ddUWn-ek rÃd Znek rÙd ZnXd efd „ƒYZd „Zdefd„ƒYZdd„Zdd„Zdd„Zd„Zd„ZdZedkrty eƒZWnnX[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. iÿÿÿÿN(t TracebackType(tmissingt internal_code(tTemplateSyntaxError(t iteritemstreraiset code_type(ttproxysraise TypeError, 'foo'sraise __jinja_exception__[1]s4raise __jinja_exception__[0], __jinja_exception__[1]tTracebackFrameProxycBsGeZdZd„Zed„ƒZd„Zed„ƒZd„ZRS(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*dƒWqFtk 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|ƒ‰tdkrˆS‡fd†}tt|ƒS(NcsV|dkrtˆ|dƒS|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\eZdZd„Zdd„Zed„Zed„ƒZ ed„ƒZ ed„ƒZ RS(s?Holds a Jinja preprocessed traceback for printing or reraising.cCsz|stdƒ‚||_||_||_d}x3|jD](}|dk r_|j|ƒn|}q=W|jdƒdS(Nsno frames for this traceback?(tAssertionErrortexc_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|ƒjƒS(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|ƒ|jƒjddƒfS(s<Return a unicode string with the traceback as rendered HTML.iÿÿÿÿ(trender_tracebacku%s tfullsutf-8treplace(tjinja2.debugrendererR5R4tdecode(R R6R5((s0/usr/lib/python2.7/site-packages/jinja2/debug.pytrender_as_htmlgscCst|jtƒS(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 R4tFalseR:RR<R=R?(((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyR'Ps   cCsI|\}}}t|tƒr6t||ƒ}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_traceback„s  cCsU||_t|_|j|df}|j}|dkrBd}nt|||jƒS(s4Rewrites a syntax error to please traceback systems.s N(tsourcetTruet translatedt __class__R tfilenamet fake_exc_infotlineno(terrorRFR=RJ((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyRAs     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|dƒnt|d|d|ƒS(s„If 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_linenoRKRJtappendR&RR'( R=RDR R+txt initial_tbRttemplateRL((s0/usr/lib/python2.7/site-packages/jinja2/debug.pyRBšs*      cBsÿ|\}}}|dk r³|jjjƒ}|jdƒ}|rQ|jƒ}ni}xFe|ƒD]8\} } | jdƒrd| ek rd| || d s>          4 , E @