ó
 `¾Tc           @   sx  d  Z  d d l Z d d l Z d d l m Z d d l m Z m Z d d l m	 Z	 d d l
 m Z m Z m Z y d d l m Z Wn e k
 r d Z n Xy d d UWn- e k
 rÃ d	 Z n e k
 rÙ d
 Z n Xd e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d d „ Z d d „ Z d d „ Z d „  Z d „  Z d Z e d k rty e ƒ  Z Wn n X[ n  d S(   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(   t   missingt   internal_code(   t   TemplateSyntaxError(   t	   iteritemst   reraiset	   code_type(   t   tproxys   raise TypeError, 'foo's   raise __jinja_exception__[1]s4   raise __jinja_exception__[0], __jinja_exception__[1]t   TracebackFrameProxyc           B   sG   e  Z d  Z d „  Z e d „  ƒ Z d „  Z e d „  ƒ Z d „  Z RS(   s   Proxies a traceback frame.c         C   s   | |  _  d  |  _ d  S(   N(   t   tbt   Nonet   _tb_next(   t   selfR	   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   __init__'   s    	c         C   s   |  j  S(   N(   R   (   R   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   tb_next+   s    c         C   sS   t  d  k	 rF y# t  |  j | r' | j p* d  ƒ WqF t k
 rB qF Xn  | |  _ d  S(   N(   t   tb_set_nextR
   R	   t	   ExceptionR   (   R   t   next(    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   set_next/   s    #c         C   s   d |  j  j j k S(   Nt   __jinja_template__(   R	   t   tb_framet	   f_globals(   R   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   is_jinja_frame:   s    c         C   s   t  |  j | ƒ S(   N(   t   getattrR	   (   R   t   name(    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   __getattr__>   s    (	   t   __name__t
   __module__t   __doc__R   t   propertyR   R   R   R   (    (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyR   $   s   		c            s8   t  |  ƒ ‰  t d  k r ˆ  S‡  f d †  } t t | ƒ S(   Nc            sV   |  d k r t  ˆ  | d ƒ S|  d k r< ˆ  j | | Ž  n t  ˆ  |  ƒ | | Ž  Sd  S(   Nt   __getattribute__R   i    t   __setattr__(   s   __getattribute__s   __getattr__(   R   R   (   t	   operationt   argst   kwargs(   t   proxy(    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   operation_handlerF   s
    (   R   R   R
   R    (   t   frameR$   (    (   R#   sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   make_frame_proxyB   s
    t   ProcessedTracebackc           B   s\   e  Z d  Z d „  Z d d „ Z e d „ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z RS(   s?   Holds a Jinja preprocessed traceback for printing or reraising.c         C   sz   | s t  d ƒ ‚ | |  _ | |  _ | |  _ d  } x3 |  j D]( } | d  k	 r_ | j | ƒ n  | } q= W| j d  ƒ d  S(   Ns   no frames for this traceback?(   t   AssertionErrort   exc_typet	   exc_valuet   framesR
   R   (   R   R)   R*   R+   t   prev_tbR	   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyR   S   s    			
c         C   s;   t  j |  j |  j |  j d d | ƒ} d j | ƒ j ƒ  S(   s#   Return a string with the traceback.i    t   limitt    (   t	   tracebackt   format_exceptionR)   R*   R+   t   joint   rstrip(   R   R-   t   lines(    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   render_as_texta   s    c         C   s<   d d l  m } d | |  d | ƒ|  j ƒ  j d d ƒ f S(   s<   Return a unicode string with the traceback as rendered HTML.iÿÿÿÿ(   t   render_tracebacku   %s

<!--
%s
-->t   fulls   utf-8t   replace(   t   jinja2.debugrendererR5   R4   t   decode(   R   R6   R5   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   render_as_htmlg   s    c         C   s   t  |  j t ƒ S(   s*   `True` if this is a template syntax error.(   t
   isinstanceR*   R   (   R   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   is_template_syntax_erroro   s    c         C   s   |  j  |  j |  j d f S(   s;   Exception info tuple with a proxy around the frame objects.i    (   R)   R*   R+   (   R   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   exc_infot   s    c         C   s>   |  j  d } t | ƒ t k	 r+ | j } n  |  j |  j | f S(   s'   Standard python exc_info for re-raisingi    (   R+   t   typeR    R	   R)   R*   (   R   R	   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   standard_exc_infoy   s    N(   R   R   R   R   R
   R4   t   FalseR:   R   R<   R=   R?   (    (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyR'   P   s   	c         C   sI   |  \ } } } t  | t ƒ r6 t | | ƒ }  d } n d } t |  | ƒ S(   s7   Creates a processed traceback object from the exc_info.i    i   (   R;   R   t   translate_syntax_errort   translate_exception(   R=   t   source_hintR)   R*   R	   t   initial_skip(    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   make_traceback„   s    	c         C   sU   | |  _  t |  _ |  j |  d f } |  j } | d k rB d } n  t | | |  j ƒ S(   s4   Rewrites a syntax error to please traceback systems.s	   <unknown>N(   t   sourcet   Truet
   translatedt	   __class__R
   t   filenamet   fake_exc_infot   lineno(   t   errorRF   R=   RJ   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyRA      s    				i    c   	      C   s2  |  d } g  } x, t  | ƒ D] } | d k	 r | j } q q W| } x­ | d k	 rô | j j t k ru | j } qH n  | j } | j j j d ƒ } | d k	 rØ | j | j	 ƒ } t
 |  d  | f | j | ƒ d } n  | j t | ƒ ƒ | } qH W| st |  d |  d |  d ƒ n  t |  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.
    i   R   i    i   N(   t   rangeR
   R   R   t   f_codeR   R   t   gett   get_corresponding_linenot	   tb_linenoRK   RJ   t   appendR&   R   R'   (	   R=   RD   R	   R+   t   xt
   initial_tbR   t   templateRL   (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyRB   š   s*    
		
c         B   sÿ  |  \ } } } | d k	 r³ | j j j ƒ  } | j d ƒ } | rQ | j ƒ  } n i  } xF e | ƒ D]8 \ }	 }
 |	 j d ƒ rd |
 e k	 rd |
 | |	 d <qd qd W| j	 d d ƒ n i  } i | d 6| d 6|  d  d 6d d 6} e
 d | d	 e | d
 ƒ } y± | d k rd } nJ | j j j } | d k r9d } n& | j d ƒ rYd | d } n d } e d | j | j | j | j | j | j | j | | | j | j d d ƒ } Wn n Xy | | | f d UWn  e j ƒ  }  |  d j } n X|  d  | f S(   s!   Helper for `translate_exception`.t   contextt   l_i   t   __jinja_exception__R   t   __file__R   s   
i   t   execRV   t   roots   top-level template codet   block_s
   block "%s"i   i    N(    (    (   R
   R   t   f_localst   copyRP   t   get_allR   t
   startswithR   t   popt   compilet   raise_helperRO   t   co_nameR   t
   co_nlocalst   co_stacksizet   co_flagst   co_codet	   co_constst   co_namest   co_varnamest   co_firstlinenot	   co_lnotabt   sysR=   R   (   R=   RJ   RL   R)   R*   R	   t   real_localst   ctxt   localsR   t   valuet   globalst   codet   locationt   functiont   new_tb(    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyRK   Æ   sP    
			c             sg  d d l  ‰ d d l m ‰ t ˆ j d ƒ r: ˆ j }  n	 ˆ j }  d ˆ j f d „  ƒ  Y} d |  f d ˆ j | ƒ f g | _	 t t
 d	 ƒ ró d ˆ j f d
 „  ƒ  Y} d ˆ j | ƒ f d ˆ j | ƒ f d |  f d ˆ j | ƒ f g | _	 n  d | f d „  ƒ  Y‰  d ˆ j ˆ  ƒ f d ˆ j | ƒ f d ˆ j f d ˆ j f g ˆ  _	 ‡  ‡ ‡ f d †  } | S(   sñ   This function implements a few ugly things so that we can patch the
    traceback objects.  The function returned allows resetting `tb_next` on
    any python traceback object.  Do not attempt to use this on non cpython
    interpreters
    iÿÿÿÿN(   R    t   Py_InitModule4_64t	   _PyObjectc           B   s   e  Z RS(    (   R   R   (    (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyRz     s   t	   ob_refcntt   ob_typet
   getobjectsc           B   s   e  Z RS(    (   R   R   (    (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyRz   $  s   t   _ob_nextt   _ob_prevt
   _Tracebackc           B   s   e  Z RS(    (   R   R   (    (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyR€   -  s   R   R   t   tb_lastiRR   c            så   t  |  ˆ ƒ o' | d k p' t  | ˆ ƒ s9 t d ƒ ‚ n  ˆ  j t |  ƒ ƒ } |  j d k	 r‡ ˆ  j t |  j ƒ ƒ } | j d 8_ n  | d k r« ˆ j ˆ  ƒ ƒ  | _ n6 ˆ  j t | ƒ ƒ } | j d 7_ ˆ j | ƒ | _ d S(   s0   Set the tb_next attribute of a traceback object.s/   tb_set_next arguments must be traceback objectsi   N(	   R;   R
   t	   TypeErrort   from_addresst   idR   R{   t   POINTERt   pointer(   R	   R   t   objt   old(   R€   t   ctypesR    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyR   6  s    (   R‰   t   typesR    t   hasattrt	   pythonapit   c_int64t   c_intt	   StructureR…   t   _fields_Ro   (   t   _Py_ssize_tRz   R   (    (   R€   R‰   R    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   _init_ugly_crap  s*    			(   R   Ro   R/   RŠ   R    t   jinja2.utilsR   R   t   jinja2.exceptionsR   t   jinja2._compatR   R   R   t   __pypy__R   t   ImportErrorR
   t   SyntaxErrorRd   R‚   t   objectR   R&   R'   RE   RA   RB   RK   R’   R   (    (    (    sR   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/jinja2/debug.pyt   <module>   s>   
	
	4,	E	@