
bUf                 @   s  d  Z  d d l m Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d l m Z d d l m Z d d	 l m Z m Z m Z d d
 l m Z m Z m Z m Z m Z m Z d d d d d d d d d d d d d d d d i Z e e d  rd Z n d Z d d   Z e  e! e   d d   Z d d  d! d"  Z" d# d$   Z# d% d&   Z$ Gd' d(   d( e%  Z& Gd) d*   d* e%  Z' Gd+ d,   d, e(  Z) Gd- d.   d. e  Z* Gd/ d0   d0 e  Z+ Gd1 d2   d2 e  Z, Gd3 d4   d4 e-  Z. Gd5 d6   d6 e  Z/ d S)7z
    jinja2.compiler
    ~~~~~~~~~~~~~~~

    Compiles nodes into python code.

    :copyright: (c) 2010 by the Jinja Team.
    :license: BSD, see LICENSE for more details.
    )chain)deepcopy)	iskeyword)nodes)EvalContext)NodeVisitor)TemplateAssertionError)Markupconcatescape)
range_type	text_typestring_types	iteritemsNativeStringIOimapeqz==nez!=gt>Zgteqz>=lt<Zlteqz<=inZnotinznot inr   itemsc                 s   d     f d d   }  |  S)N*   c                  s   d  S)N r   )xr   1/usr/lib/python3/dist-packages/jinja2/compiler.pyf-   s    z&unoptimize_before_dead_code.<locals>.fr   )r   r   )r   r   unoptimize_before_dead_code+   s    r   __closure__NFc             C   sc   t  |  t j  s t d   | j | | | | |  } | j |   | d k r_ | j j   Sd S)z+Generate the python source for a node tree.z Can't compile non template nodesN)
isinstancer   ZTemplate	TypeErrorZcode_generator_classvisitstreamgetvalue)nodeenvironmentnamefilenamer$   
defer_init	generatorr   r   r   generate7   s    r,   c             C   s   |  d k s$ |  t  k s$ |  t k r( d St |  t t t t t t f t	  rQ d St |  t
 t t t f  r x |  D] } t |  ss d Sqs Wd St |  t  r x: t |   D], \ } }  t |  s d St |   s d Sq Wd Sd S)z)Does the node have a safe representation?NTF)NotImplementedEllipsisr!   boolintfloatcomplexr   r	   r   tuplelistset	frozensethas_safe_reprdictr   )valueitemkeyr   r   r   r7   C   s$    $r7   c             C   sJ   t  |  } y" x |  D] } | j |  q WWn t k
 rB Yn X| j S)zCheck if the names passed are accessed undeclared.  The return value
    is a set of all the undeclared names from the sequence of names found.
    )UndeclaredNameVisitorr#   VisitorExit
undeclared)r   namesvisitorr&   r   r   r   find_undeclaredY   s    rA   c               @   sF   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 S)Identifiersz+Tracks the status of identifiers in frames.c             C   s@   t    |  _ t    |  _ t    |  _ t    |  _ t    |  _ d  S)N)r5   declaredouter_undeclaredr>   declared_locallydeclared_parameter)selfr   r   r   __init__i   s
    zIdentifiers.__init__c             C   s$   |  j  j |  |  j j |  d S)z$Register a special name like `loop`.N)r>   discardrC   add)rG   r(   r   r   r   add_special|   s    zIdentifiers.add_specialc             C   s/   | |  j  k s | |  j k r" d S| |  j k S)z6Check if a name is declared in this or an outer scope.T)rE   rF   rC   )rG   r(   r   r   r   is_declared   s    zIdentifiers.is_declaredc             C   s
   t  |   S)N)r   )rG   r   r   r   copy   s    zIdentifiers.copyN)__name__
__module____qualname____doc__rH   rK   rL   rM   r   r   r   r   rB   f   s
   rB   c               @   sj   e  Z d  Z d Z d d d  Z d d   Z d d   Z f  d	 d
  Z d d   Z d d   Z	 e Z
 d S)Framez&Holds compile time information for us.Nc             C   s   | |  _  t   |  _ d |  _ d |  _ | o3 | j |  _ d  |  _ | rQ | j pT d  |  _ t   |  _	 | |  _
 | d  k	 r |  j j j | j j | j j B| j	 B |  j j j | j j |  j j  | j |  _ d  S)NF)eval_ctxrB   identifierstoplevel	rootlevelrequire_output_checkbufferblockr5   assigned_namesparentrC   updaterF   rD   r>   )rG   rS   r[   r   r   r   rH      s"    						zFrame.__init__c             C   sZ   t  j |  j  } | j j |  j  t  j |  j j  | _ | j j j |  j j  | S)z!Create a copy of the current one.)object__new__	__class____dict__r\   rT   )rG   rvr   r   r   rM      s
    z
Frame.copyc             C   s1   t  |  j  } x | D] } | j |  q Wd S)zWalk the node and check for identifiers.  If the scope is hard (eg:
        enforce on a python level) overrides from outer scopes are tracked
        differently.
        N)FrameIdentifierVisitorrT   r#   )rG   r   r@   r&   r   r   r   inspect   s    zFrame.inspectc                sB   |  j      j   j B  j   j B@t   f d d   | D  BS)zFind all the shadowed names.  extra is an iterable of variables
        that may be defined with `add_special` which may occour scoped.
        c             3   s$   |  ] }   j  |  r | Vq d  S)N)rL   ).0r   )ir   r   	<genexpr>   s    z&Frame.find_shadowed.<locals>.<genexpr>)rT   rC   rD   rE   rF   r5   )rG   extrar   )re   r   find_shadowed   s    	zFrame.find_shadowedc             C   s   t  |  j |   S)zReturn an inner frame.)rR   rS   )rG   r   r   r   inner   s    zFrame.innerc             C   s   |  j    } d | _ | S)zReturn a soft frame.  A soft frame may not be modified as
        standalone thing as it shares the resources with the frame it
        was created of, but it's not a rootlevel frame any longer.
        F)rM   rV   )rG   ra   r   r   r   soft   s    	z
Frame.soft)rN   rO   rP   rQ   rH   rM   rc   rh   ri   rj   __copy__r   r   r   r   rR      s   +			rR   c               @   s   e  Z d  Z d Z d S)r=   z?Exception used by the `UndeclaredNameVisitor` to signal a stop.N)rN   rO   rP   rQ   r   r   r   r   r=      s   r=   c               @   sF   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 S)DependencyFinderVisitorz.A visitor that collects filter and test calls.c             C   s   t    |  _ t    |  _ d  S)N)r5   filterstests)rG   r   r   r   rH      s    z DependencyFinderVisitor.__init__c             C   s$   |  j  |  |  j j | j  d  S)N)generic_visitrm   rJ   r(   )rG   r&   r   r   r   visit_Filter   s    z$DependencyFinderVisitor.visit_Filterc             C   s$   |  j  |  |  j j | j  d  S)N)ro   rn   rJ   r(   )rG   r&   r   r   r   
visit_Test   s    z"DependencyFinderVisitor.visit_Testc             C   s   d S)zStop visiting at blocks.Nr   )rG   r&   r   r   r   visit_Block   s    z#DependencyFinderVisitor.visit_BlockN)rN   rO   rP   rQ   rH   rp   rq   rr   r   r   r   r   rl      s
   rl   c               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	r<   zA visitor that checks if a name is accessed without being
    declared.  This is different from the frame visitor as it will
    not stop at closure frames.
    c             C   s   t  |  |  _ t    |  _ d  S)N)r5   r?   r>   )rG   r?   r   r   r   rH      s    zUndeclaredNameVisitor.__init__c             C   si   | j  d k rR | j |  j k rR |  j j | j  |  j |  j k re t    n |  j j | j  d  S)Nload)ctxr(   r?   r>   rJ   r=   rI   )rG   r&   r   r   r   
visit_Name  s
    !z UndeclaredNameVisitor.visit_Namec             C   s   d S)zStop visiting a blocks.Nr   )rG   r&   r   r   r   rr     s    z!UndeclaredNameVisitor.visit_BlockN)rN   rO   rP   rQ   rH   ru   rr   r   r   r   r   r<      s   r<   c               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d S)rb   zA visitor for `Frame.inspect`.c             C   s   | |  _  d  S)N)rT   )rG   rT   r   r   r   rH     s    zFrameIdentifierVisitor.__init__c             C   s   | j  d k r( |  j j j | j  nc | j  d k rP |  j j j | j  n; | j  d k r |  j j | j  r |  j j j | j  d S)z2All assignments to names go through this function.storeZparamrs   N)rt   rT   rE   rJ   r(   rF   rL   r>   )rG   r&   r   r   r   ru     s    z!FrameIdentifierVisitor.visit_Namec                s    j  | j   j   j  j B      f d d   } | | j  } | | j p_ f   }  j j | j	 |   j
   j j | | B d  S)Nc                sm   |  s t    S j    _ x |  D] }  j |  q# W j j   }  j j  j j    _ | S)N)r5   rM   rT   r#   rE   r>   r\   )r   Zsubnodera   )	old_namesreal_identifiersrG   r   r   inner_visit'  s    	z4FrameIdentifierVisitor.visit_If.<locals>.inner_visit)r#   testrT   rE   rF   bodyelse_r>   r\   symmetric_differencerC   )rG   r&   ry   r{   r|   r   )rw   rx   rG   r   visit_If   s    	
zFrameIdentifierVisitor.visit_Ifc             C   s   |  j  j j | j  d  S)N)rT   rE   rJ   r(   )rG   r&   r   r   r   visit_Macro?  s    z"FrameIdentifierVisitor.visit_Macroc             C   s'   |  j  |  |  j j j | j  d  S)N)ro   rT   rE   rJ   target)rG   r&   r   r   r   visit_ImportB  s    z#FrameIdentifierVisitor.visit_Importc             C   sa   |  j  |  xM | j D]B } t | t  rF |  j j j | d  q |  j j j |  q Wd  S)N   )ro   r?   r!   r3   rT   rE   rJ   )rG   r&   r(   r   r   r   visit_FromImportF  s
    z'FrameIdentifierVisitor.visit_FromImportc             C   s$   |  j  | j  |  j  | j  d S)z'Visit assignments in the correct order.N)r#   r&   r   )rG   r&   r   r   r   visit_AssignN  s    z#FrameIdentifierVisitor.visit_Assignc             C   s   |  j  | j  d S)zqVisiting stops at for blocks.  However the block sequence
        is visited as part of the outer scope.
        N)r#   iter)rG   r&   r   r   r   	visit_ForS  s    z FrameIdentifierVisitor.visit_Forc             C   s   |  j  | j  d  S)N)r#   call)rG   r&   r   r   r   visit_CallBlockY  s    z&FrameIdentifierVisitor.visit_CallBlockc             C   s   |  j  | j  d  S)N)r#   filter)rG   r&   r   r   r   visit_FilterBlock\  s    z(FrameIdentifierVisitor.visit_FilterBlockc             C   s   d S)zStop visiting at block assigns.Nr   )rG   r&   r   r   r   visit_AssignBlock_  s    z(FrameIdentifierVisitor.visit_AssignBlockc             C   s   d S)zStop visiting at scopes.Nr   )rG   r&   r   r   r   visit_Scopeb  s    z"FrameIdentifierVisitor.visit_Scopec             C   s   d S)zStop visiting at blocks.Nr   )rG   r&   r   r   r   rr   e  s    z"FrameIdentifierVisitor.visit_BlockN)rN   rO   rP   rQ   rH   ru   r~   r   r   r   r   r   r   r   r   r   rr   r   r   r   r   rb     s   
rb   c               @   s   e  Z d  Z d Z d S)CompilerExitzRaised if the compiler encountered a situation where it just
    doesn't make sense to further process the code.  Any block that
    raises such an exception is not further processed.
    N)rN   rO   rP   rQ   r   r   r   r   r   i  s   r   c               @   sN  e  Z d  Z d d d d  Z d d   Z d d   Z d	 d
   Z d d   Z d d   Z d d d  Z	 d d d  Z
 d d   Z d d d  Z d d   Z d d   Z d d d d  Z d d d d   Z d d! d"  Z d# d$   Z d% d&   Z d' d(   Z f  d) d*  Z d+ d,   Z d d- d. d/  Z d d0 d1  Z d2 d3   Z d4 d5   Z d d6 d7  Z d8 d9   Z d: d;   Z d< d=   Z d> d?   Z d@ dA   Z  dB dC   Z! dD dE   Z" dF dG   Z# dH dI   Z$ dJ dK   Z% dL dM   Z& dN dO   Z' dP dQ   Z( dR dS   Z) dT dU   Z* dV dW   Z+ dX dY   Z, dZ d[   Z- d\ d]   Z. d^ d_   Z/ d` da   Z0 db dc   Z1 d- dd de  Z2 d- df dg  Z3 e2 dh  Z4 e2 di  Z5 e2 dj  Z6 e2 dk  Z7 e2 dl  Z8 e2 dm  Z9 e2 dn  Z: e2 do dp d Z; e2 dq dp d Z< e3 dh  Z= e3 di  Z> e3 dr dp d Z? [2 [3 ds dt   Z@ du dv   ZA dw dx   ZB dy dz   ZC d{ d|   ZD d} d~   ZE d d   ZF d d   ZG d d   ZH d d d  ZI d d   ZJ d d   ZK d d   ZL d d   ZM d d   ZN d d   ZO d d   ZP d d   ZQ d d   ZR d d   ZS d d   ZT d d   ZU d d   ZV d S)CodeGeneratorNFc             C   s   | d  k r t    } | |  _ | |  _ | |  _ | |  _ d |  _ | |  _ i  |  _ i  |  _ d |  _	 d |  _
 d |  _ i  |  _ i  |  _ g  |  _ d  |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d  S)NFr   r   T)r   r'   r(   r)   r$   Zcreated_block_contextr*   import_aliasesblocksextends_so_farhas_known_extendscode_linenorn   rm   
debug_info_write_debug_info
_new_lines
_last_line_first_write_last_identifier_indentation)rG   r'   r(   r)   r$   r*   r   r   r   rH   r  s,    																				zCodeGenerator.__init__c             C   s   t  | | |  j |  j   d S)z*Fail with a :exc:`TemplateAssertionError`.N)r   r(   r)   )rG   msglinenor   r   r   fail  s    zCodeGenerator.failc             C   s   |  j  d 7_  d |  j  S)zGet a new unique identifier.r   zt_%d)r   )rG   r   r   r   temporary_identifier  s    z"CodeGenerator.temporary_identifierc             C   s'   |  j    | _ |  j d | j  d S)z7Enable buffering for the frame from that point onwards.z%s = []N)r   rX   	writeline)rG   framer   r   r   rX     s    zCodeGenerator.bufferc             C   s   | j  j ry |  j d  |  j   |  j d | j  |  j   |  j d  |  j   |  j d | j  |  j   n7 | j  j r |  j d | j  n |  j d | j  d S)z(Return the buffer contents of the frame.zif context.eval_ctx.autoescape:zreturn Markup(concat(%s))zelse:zreturn concat(%s)N)rS   volatiler   indentrX   outdent
autoescape)rG   r   r   r   r   return_buffer_contents  s    


z$CodeGenerator.return_buffer_contentsc             C   s   |  j  d 7_  d S)zIndent by one.r   N)r   )rG   r   r   r   r     s    zCodeGenerator.indentr   c             C   s   |  j  | 8_  d S)zOutdent by step.N)r   )rG   stepr   r   r   r     s    zCodeGenerator.outdentc             C   s=   | j  d k r" |  j d |  n |  j d | j  |  d S)z%Yield or write into the frame buffer.Nzyield z
%s.append()rX   r   )rG   r   r&   r   r   r   start_write  s    zCodeGenerator.start_writec             C   s    | j  d k	 r |  j d  d S)z1End the writing process started by `start_write`.N))rX   write)rG   r   r   r   r   	end_write  s    zCodeGenerator.end_writec             C   s.   |  j  | |  |  j |  |  j |  d S)z4Simple shortcut for start_write + write + end_write.N)r   r   r   )rG   sr   r&   r   r   r   simple_write  s    zCodeGenerator.simple_writec             C   sj   | j  d k r |  j d  n |  j d  y% x | D] } |  j | |  q6 WWn t k
 re Yn Xd S)zVisit a list of nodes as block in a frame.  If the current frame
        is no buffer a dummy ``if 0: yield None`` is written automatically
        unless the force_generator parameter is set to False.
        Nzif 0: yield Nonepass)rX   r   r#   r   )rG   r   r   r&   r   r   r   
blockvisit  s    zCodeGenerator.blockvisitc             C   s   |  j  r |  j so |  j j d |  j   |  j |  j  7_ |  j d k	 ro |  j j |  j |  j f  d |  _ d |  _ |  j j d |  j  d |  _  |  j j |  d S)z&Write a string into the output stream.
NFz    r   )	r   r   r$   r   r   r   r   appendr   )rG   r   r   r   r   r     s    					zCodeGenerator.writer   c             C   s!   |  j  | |  |  j |  d S)z!Combination of newline and write.N)newliner   )rG   r   r&   rg   r   r   r   r     s    zCodeGenerator.writelinec             C   sS   t  |  j d |  |  _ | d k	 rO | j |  j k rO | j |  _ | j |  _ d S)z/Add one or more newlines before the next write.r   N)maxr   r   r   r   )rG   r&   rg   r   r   r   r     s    zCodeGenerator.newlinec       	      C   sV  d } x@ t  d d   | j D | p( f   D] } t |  r, d } Pq, Wx. | j D]# } |  j d  |  j | |  qS W| s x. | j D]# } |  j d  |  j | |  q W| d k	 r x1 t |  D]# \ } } |  j d | | f  q W| j r|  j d  |  j | j |  | r#| j d k	 r?|  j d	  n |  j d
  xE | j D]: } |  j d | j	  |  j | j
 |  |  j d  qVW| d k	 rx1 t |  D]# \ } } |  j d | | f  qW| j d k	 r|  j d  |  j | j |  |  j d  qR|  j d  n/ | j d k	 rR|  j d  |  j | j |  d S)a,  Writes a function call to the stream for the current node.
        A leading comma is added automatically.  The extra keyword
        arguments may not include python keywords otherwise a syntax
        error could occour.  The extra keyword arguments should be given
        as python dict.
        Fc             s   s   |  ] } | j  Vq d  S)N)r;   )rd   r   r   r   r   rf     s    z*CodeGenerator.signature.<locals>.<genexpr>Tz, Nz, %s=%sz, *z
, **dict({z, **{z%r: z%r: %s, z}, **r   }z, **)r   kwargsis_python_keywordargsr   r#   r   Zdyn_argsZ
dyn_kwargsr;   r9   )	rG   r&   r   extra_kwargsZkwarg_workaroundZkwargargr;   r9   r   r   r   	signature  sJ    	,	zCodeGenerator.signaturec             C   s2   x+ | j  j D] } |  j d | | f  q Wd S)z9Pull all the references identifiers into the local scope.zl_%s = context.resolve(%r)N)rT   r>   r   )rG   r   r(   r   r   r   pull_locals@  s    zCodeGenerator.pull_localsc             C   s   t    } x | D] } | j |  q Wxq d D]i } t |  |  } xQ t | |  D]@ } | | k ru |  j   | | <|  j d | | | | f  qS Wq. Wd S)zPull all the dependencies.rm   rn   z%s = environment.%s[%r]N)zfiltersztests)rl   r#   getattrr   r   )rG   r   r@   r&   Z
dependencymappingr(   r   r   r   pull_dependenciesE  s    		zCodeGenerator.pull_dependenciesc             C   sO   | j  j rK |  j d t r! d p$ d d j d d   | j  j D  f  d S)z+Disable Python optimizations for the frame.z%sdummy(%s)zif 0:  z, c             s   s   |  ] } d  | Vq d S)l_Nr   )rd   r(   r   r   r   rf   [  s    z1CodeGenerator.unoptimize_scope.<locals>.<genexpr>N)rT   rC   r   r   join)rG   r   r   r   r   unoptimize_scopeR  s    	zCodeGenerator.unoptimize_scopec             C   s   i  } xB | j  |  D]1 } |  j   | | <} |  j d | | f  q Wt   } x1 | j j D]# } | | k ra | j d |  qa W| r |  j d j |  d  | S)a  This function returns all the shadowed variables in a dict
        in the form name: alias and will write the required assignments
        into the current scope.  No indentation takes place.

        This also predefines locally declared variables from the loop
        body because under some circumstances it may be the case that

        `extra_vars` is passed to `Frame.find_shadowed`.
        z	%s = l_%sr   z = z
 = missing)rh   r   r   r5   rT   rE   rJ   r   )rG   r   Z
extra_varsaliasesr(   ZidentZ
to_declarer   r   r   
push_scope^  s    
	zCodeGenerator.push_scopec             C   s   x1 t  |  D]# \ } } |  j d | | f  q Wt   } x1 | j j D]# } | | k rJ | j d |  qJ W| r |  j d j |  d  d S)z0Restore all aliases and delete unused variables.z	l_%s = %sr   z = z
 = missingN)r   r   r5   rT   rE   rJ   r   )rG   r   r   r(   aliasZ	to_deleter   r   r   	pop_scopet  s    	zCodeGenerator.pop_scopeTc       	      C   s  | d k r | j    } t |  } | j   } | j |  | j j | j j @| j j | j j B@} | r |  j	 d d j
 t |   | j  | j j | j j | j j @8_ | s | Sd | _ d | _ d | _ d d   | j D | _ } t | d  } d | k r8d
 | _ | j j d  | j d  d | k rjd
 | _ | j j d  | j d  d	 | k rd
 | _ | j j d	  | j d  | S)aM  In Jinja a few statements require the help of anonymous
        functions.  Those are currently macros and call blocks and in
        the future also recursive loops.  As there is currently
        technical limitation that doesn't allow reading and writing a
        variable in a scope where the initial value is coming from an
        outer scope, this function tries to fall back with a common
        error message.  Additionally the frame passed is modified so
        that the argumetns are collected and callers are looked up.

        This will return the modified frame.
        NzXIt's not possible to set and access variables derived from an outer scope! (affects: %s)z, Fc             S   s   g  |  ] } d  | j   q S)r   )r(   )rd   r   r   r   r   
<listcomp>  s   	 z2CodeGenerator.function_scoping.<locals>.<listcomp>callerr   varargsTZl_callerZl_kwargsZ	l_varargs)r   zkwargsr   )iter_child_nodesr4   ri   rc   rT   r>   rC   rE   rF   r   r   sortedr   accesses_kwargsaccesses_varargsaccesses_callerr   	argumentsrA   rK   r   )	rG   r&   r   childrenfind_specialZ
func_frameZoverridden_closure_varsr   r>   r   r   r   function_scoping  sD    
		
							zCodeGenerator.function_scopingc             C   s   |  j  | | |  } d | _ | j } d | j j k rF | d g } |  j d d j |  |  |  j   |  j |  |  j	 |  |  j
 | j |  |  j |  |  j   | S)z/Dump the function def of a macro or call block.Floopzl_loop=l_loopzdef macro(%s):z, )r   rW   r   rT   rC   r   r   r   rX   r   r   r{   r   r   )rG   r&   r   r   r   r   r   r   
macro_body  s    		

zCodeGenerator.macro_bodyc             C   s   d j  d d   | j D  } t | d d  } t | j  d k rP | d 7} |  j d | | f  x. | j D]# } |  j | |  |  j d  qq W|  j d	 t | j  t | j	  t | j
  f  d S)
z<Dump the macro definition for the def created by macro_body.z, c             s   s   |  ] } t  | j  Vq d  S)N)reprr(   )rd   r   r   r   r   rf     s    z*CodeGenerator.macro_def.<locals>.<genexpr>r(   Nr   ,z%Macro(environment, macro, %r, (%s), (z), %r, %r, %r))r   r   r   lenr   Zdefaultsr#   r/   r   r   r   )rG   r&   r   Z	arg_tupler(   r   r   r   r   	macro_def  s    
		zCodeGenerator.macro_defc             C   s7   d | j  } |  j d k	 r3 | d t |  j  7} | S)z.Return a human readable position for the node.zline %dNz in )r   r(   r   )rG   r&   ra   r   r   r   position  s    zCodeGenerator.positionc             C   sv  | d  k s t  d   t |  j |  j  } d d l m } |  j d  |  j d d j |   t sw |  j d  |  j	 r d p d	 } | j
 t j  d  k	 } xV | j t j  D]B } | j |  j k r |  j d
 | j | j  | |  j | j <q Wx | j t j  D] } | j |  j k r| j }	 |  j   |  j |	 <}
 d |	 k r|	 j d d  \ } } |  j d | | |
 f  q|  j d |	 |
 f  qW|  j d |  j  |  j d | d d t |  } | j | j  d | _ | _ | o	|  j | _ |  j   | r,|  j d  d t | j d#  k ra| j  j! d  |  j d  |  j" |  |  j# | j  |  j$ | j |  |  j%   | r|  j s|  j   |  j d  |  j   |  j d  |  j   |  j d  |  j% d |  j  xt& |  j  D] \ } } t |  } | j | j  | | _' |  j d | | f | d  |  j   t | j d$  } d | k r| j  j! d  |  j d  d | k r| j  j! d  |  j d | | f  |  j" |  |  j# | j  |  j$ | j |  |  j%   qW|  j d d j d d   |  j D  d d |  j d  d! j d" d   |  j( D   d  S)%Nzno root frame allowedr   )__all__zfrom __future__ import divisionzfrom jinja2.runtime import z, zdummy = lambda *x: Nonez, environment=environmentr   zblock %r defined twice.r   zfrom %s import %s as %szimport %s as %sz	name = %rzdef root(context%s):rg   Tzparent_template = NonerG   z#l_self = TemplateReference(context)zif parent_template is not None:z7for event in parent_template.root_render_func(context):zyield event   zdef block_%s(context%s):superz%l_super = context.super(%r, block_%s)zblocks = {%s}c             s   s   |  ] } d  | | f Vq d S)z%r: block_%sNr   )rd   r   r   r   r   rf   T  s   z/CodeGenerator.visit_Template.<locals>.<genexpr>zdebug_info = %r&c             s   s   |  ] } d  | Vq d S)z%s=%sNr   )rd   r   r   r   r   rf   Y  s    )self)r   zsuper))AssertionErrorr   r'   r(   Zjinja2.runtimer   r   r   r   r*   findr   ZExtendsfind_allZBlockr   r   r   ZImportedName
importnamer   r   rsplitrR   rc   r{   rU   rV   r   rW   r   rA   rT   rK   r   r   r   r   r   rY   r   )rG   r&   r   rS   ZexportedZenvenvZhave_extendsrY   import_impr   moduleobjr(   block_framer>   r   r   r   visit_Template  s    		

	


	

	zCodeGenerator.visit_Templatec             C   s   d } | j  rL |  j r d S|  j d k rL |  j d  |  j   | d 7} | j r[ d p^ d } |  j d | j | f |  |  j   |  j d |  |  j |  d S)	z.Call a block and register it for the template.r   Nr   zif parent_template is None:zcontext.derived(locals())contextz'for event in context.blocks[%r][0](%s):event)	rU   r   r   r   r   Zscopedr(   r   r   )rG   r&   r   levelr   r   r   r   rr   \  s    		

	
zCodeGenerator.visit_Blockc             C   s	  | j  s |  j d | j  |  j d k r{ |  j sK |  j d  |  j   |  j d d  |  j rq t    n
 |  j   |  j d |  |  j	 | j
 |  |  j d |  j  |  j d t  |  j   |  j d	  |  j   | j r d
 |  _ |  j d 7_ d S)zCalls the extender.z,cannot use extend from a non top-level scoper   zif parent_template is not None:zraise TemplateRuntimeError(%r)zextended multiple timesz+parent_template = environment.get_template(z, %r)z6for name, parent_block in parent_template.blocks.%s():z8context.blocks.setdefault(name, []).append(parent_block)Tr   N)rU   r   r   r   r   r   r   r   r   r#   templater   r(   dict_item_iterrV   )rG   r&   r   r   r   r   visit_Extendso  s.    		
	
		
	

		zCodeGenerator.visit_Extendsc             C   s  | j  r |  j |  | j r6 |  j d  |  j   d } t | j t j  r t | j j	 t
  ro d } q t | j j	 t t f  r d } n$ t | j t j t j f  r d } |  j d | |  |  j | j |  |  j d |  j  | j rJ|  j   |  j d  |  j   |  j d  |  j   |  j d	  |  j   | j  rc|  j d
  n |  j d  |  j   |  j d |  |  j   | j r|  j   d S)zHandles includes.ztry:Zget_or_select_templateZget_templateZselect_templateztemplate = environment.%s(z, %r)zexcept TemplateNotFound:r   zelse:z]for event in template.root_render_func(template.new_context(context.parent, True, locals())):z*for event in template.module._body_stream:r   N)with_contextr   Zignore_missingr   r   r!   r   r   ZConstr9   r   r3   r4   ZTupleZListr#   r   r(   r   r   )rG   r&   r   	func_namer   r   r   visit_Include  s@    		
			



	

	zCodeGenerator.visit_Includec             C   s   | j  r |  j |  |  j d | j |  | j rJ |  j d | j  |  j d  |  j | j |  |  j d |  j  | j  r |  j d  n |  j d  | j r | j j	 d  r |  j d | j  | j
 j | j  d	 S)
zVisit regular imports.zl_%s = zcontext.vars[%r] = zenvironment.get_template(z, %r).z+make_module(context.parent, True, locals())r   _z!context.exported_vars.discard(%r)N)r   r   r   r   rU   r   r#   r   r(   
startswithrZ   rJ   )rG   r&   r   r   r   r   r     s    			zCodeGenerator.visit_Importc             C   s  |  j  |  |  j d  |  j | j |  |  j d |  j  | j rZ |  j d  n |  j d  g  } g  } x | j D] } t | t  r | \ } } n | } |  j	 d | | f  |  j	 d |  |  j
   |  j	 d | d |  j |  t |  f | f  |  j   | j rH| j |  | j d	  sH| j |  | j j |  q} W| rt |  d
 k r| d } |  j	 d | | f  n' |  j	 d d j d d   | D   | rt |  d
 k r|  j	 d | d  n# |  j	 d d j t t |    d S)zVisit named imports.z-included_template = environment.get_template(z, %r).z!make_module(context.parent, True)r   z.l_%s = getattr(included_template, %r, missing)zif l_%s is missing:zGl_%s = environment.undefined(%r %% included_template.__name__, name=%r)zGthe template %%r (imported on %s) does not export the requested name %sr   r   r   zcontext.vars[%r] = l_%szcontext.vars.update({%s})z, c             s   s   |  ] } d  | | f Vq d S)z%r: l_%sNr   )rd   r(   r   r   r   rf     s    z1CodeGenerator.visit_FromImport.<locals>.<genexpr>z!context.exported_vars.discard(%r)z-context.exported_vars.difference_update((%s))N)r   r   r#   r   r(   r   r?   r!   r3   r   r   r   r   r   rU   r   r   rZ   rJ   r   r   r   )rG   r&   r   Z	var_namesZdiscarded_namesr(   r   r   r   r   r     sP    		
	
	
		zCodeGenerator.visit_FromImportc       
      C   s  | j  d d#  } | j r9 |  j | | | d d } n | j   } | j |  | j py d t | j  d d$  d%  k } | j s |  j | d&  } n- |  j d |  |  j   |  j	 |  i  } | r |  j d	  | j
 j d  xK | j t j  D]7 } | j d
 k r | j d k r |  j d | j  q W|  j |  | j rk|  j   } |  j d |  d | k rd t | j  d d'  d(  k r|  j d d |  j |   |  j d |  |  j | j |  |  j | rd pd  | r| j d  k	 r|  j d  |  j | j |  |  j d  |  j | j |  |  j d  | j rm|  j d  n |  j | j |  |  j d  | j   }	 |  j | j |	  |  j d  n, | j r|  j d  n |  j | j |  | j r|  j d  n |  j | rd pd  | r| j d  k	 r|  j   |  j d  |  j | j |  |  j d  |  j   |  j d  |  j d  |  j   |  j | j |  | j r|  j d |  |  j   | j r|  j d  |  |  j   |  j | j |  |  j   | j s&|  j  | |  | j r|  j! |  |  j   |  j" | |  |  j d!  |  j | j |  |  j d"  |  j# |  d  S))Nexcluder   r   Fr   Zonlyr{   z-def loop(reciter, loop_render_func, depth=0):zl_loop = missingrv   z8Can't assign to special loop variable in for-loop targetz%s = 1r|   rz   z/l_loop = environment.undefined(%r, name='loop')z'loop' is undefined. the filter section of a loop as well as the else block don't have access to the special 'loop' variable of the current loop.  Because there is no parent loop it's undefined.  Happened in loop on %szfor z, l_loop in LoopContext(z in (z for Zreciterz if (z))z, loop_render_func, depth):z)::zif not continuer   z%s = 0zif %s:zloop(z, loop))ziter)zbody)loop)r   )zelse_ztest)r   )$r   Z	recursiver   ri   rc   rA   r   r   r   rX   rT   rK   r   r   Namert   r(   r   r   r   r|   r   r   r#   r   r   rz   r   rM   r   r   r{   r   r   r   r   )
rG   r&   r   r   Z
loop_frameZextended_loopr   r(   Ziteration_indicatorZ
test_framer   r   r   r     s    		
						


	
	

		
zCodeGenerator.visit_Forc             C   s   | j    } |  j d |  |  j | j |  |  j d  |  j   |  j | j |  |  j   | j	 r |  j d  |  j   |  j | j	 |  |  j   d  S)Nzif r   zelse:)
rj   r   r#   rz   r   r   r   r{   r   r|   )rG   r&   r   Zif_framer   r   r   r~     s    

	
zCodeGenerator.visit_Ifc             C   s   |  j  | |  } |  j   | j r_ | j j d  sK |  j d | j  |  j d | j  |  j d | j  |  j | |  | j j	 | j  d  S)Nr   zcontext.exported_vars.add(%r)zcontext.vars[%r] = zl_%s = )
r   r   rU   r(   r   r   r   r   rZ   rJ   )rG   r&   r   Zmacro_framer   r   r   r     s    
	zCodeGenerator.visit_Macroc             C   s~   | j  d d  } |  j | | |  } |  j d  |  j | |  |  j | |  |  j | j | d d |  j |  d  S)Nr   r   z	caller = forward_callerT)zcall)r   r   r   r   r   
visit_Callr   r   )rG   r&   r   r   Z
call_framer   r   r   r     s    zCodeGenerator.visit_CallBlockc             C   s   | j    } | j | j    |  j |  } |  j |  |  j |  |  j | j |  |  j | |  |  j	 | j
 |  |  j |  |  j | |  d  S)N)ri   rc   r   r   r   rX   r   r{   r   rp   r   r   r   )rG   r&   r   Zfilter_framer   r   r   r   r     s    zCodeGenerator.visit_FilterBlockc             C   s$   |  j  |  |  j | j |  d  S)N)r   r#   r&   )rG   r&   r   r   r   r   visit_ExprStmt  s    zCodeGenerator.visit_ExprStmtc                s    j  r | j r d  Sd }   j j r   j j } t | d d  sX t | d d  ra d } q t | d d  r   f d d   } q   f d d   } n t } d } | j r   j d	    j   d } g  } x	| j D] } y( | s t j	    | j
 | j  }	 Wn% t j	 k
 r4| j |  w Yn XyF | j j rnt |	 d
  rb|	 j   }	 n t |	  }	 | |	  }	 Wn" t k
 r| j |  w Yn X| rt | d t  r| d  j |	  q | j |	 g  q Wt |  d k  s| j d  k	 r| j d  k	 rXt |  d k r:  j d | j  n   j d | j    j   xk| D]c}
 t |
 t  rt t |
   } | j d  k r  j d |  q  j | d  q_| j d  k r  j d |
  n   j |
  d } | j j r  j d  n) | j j r*  j d  n   j d    j j d  k	 r  j d  t   j j d d  r{  j d  | d 7}   j |
 |    j d |  | j d  k	 r_  j d  q_W| j d  k	 r  j     j t |  d k rd p d  ng  } g  } xY | D]Q }
 t |
 t  rQ| j t |
  j d d   q| j d  | j |
  qW  j d    j t t |   d    j   x-| D]%}   j |  d } | j j r  j d  | d 7} n# | j j r  j d  | d 7}   j j d  k	 r  j d  t   j j d d  rS  j d  nM t   j j d d  r{  j d  n% t   j j d d  r  j d  | d 7}   j | |    j d | d  qW  j     j d  | r  j   d  S)!NTZcontextfunctionFZevalcontextfunctionZenvironmentfunctionc                s   t    j j   j |    S)N)r   r'   finalize)r   )rG   r   r   <lambda>  s   z,CodeGenerator.visit_Output.<locals>.<lambda>c                s   t    j j |    S)N)r   r'   r   )r   )rG   r   r   r     s    zif parent_template is None:__html__r      z
%s.append(z%s.extend((zyield z, z6(context.eval_ctx.autoescape and escape or to_string)(zescape(z
to_string(zenvironment.finalize(z	context, r   z))%z%%z%sz % (r   zcontext.eval_ctx, zenvironment, r  )r   rW   r'   r   r   r   r   r   r   
Impossibleas_constrS   r   r   hasattrr   r   	Exceptionr!   r4   r   rX   r   r
   r   r   r   r#   r   replace)rG   r&   r   Zallow_constant_finalizefuncr   Zoutdent_laterr{   childZconstr:   valcloseformatr   Zargumentr   )rG   r   visit_Output  s    		
!


("



zCodeGenerator.visit_Outputc             C   s)   | j  s | S| j   } t   | _ | S)N)rU   rM   r5   toplevel_assignments)rG   r   assignment_framer   r   r   make_assignment_frameQ  s
    	z#CodeGenerator.make_assignment_framec             C   s"  | j  s d  Sd d   | j D } t | j  d k rg t t | j   } |  j d | | f  nd |  j d  xG t | j  D]6 \ } } | r |  j d  |  j d | | f  q W|  j d  | rt |  d k r |  j d	 | d
  n# |  j d d j t	 t
 |    d  S)Nc             S   s%   g  |  ] } | j  d   s |  q S)r   )r   )rd   r   r   r   r   r   _  s   	 z6CodeGenerator.export_assigned_vars.<locals>.<listcomp>r   zcontext.vars[%r] = l_%szcontext.vars.update({z, z%r: l_%sz})zcontext.exported_vars.add(%r)r   z"context.exported_vars.update((%s)))rU   r  r   nextr   r   	enumerater   r   r   r   )rG   r   r  Zpublic_namesr(   idxr   r   r   export_assigned_vars\  s$    			z"CodeGenerator.export_assigned_varsc             C   sc   |  j  |  |  j |  } |  j | j |  |  j d  |  j | j |  |  j | |  d  S)Nz = )r   r  r#   r   r   r&   r  )rG   r&   r   r  r   r   r   r   s  s    zCodeGenerator.visit_Assignc             C   s   | j    } | j | j  |  j |  } |  j |  |  j |  |  j | j |  |  j | |  |  j |  } |  j	 |  |  j
 | j |  |  j d | j  |  j | |  d  S)Nz = concat(%s))ri   rc   r{   r   r   rX   r   r   r  r   r#   r   r   r  )rG   r&   r   r   r   r  r   r   r   r   {  s    zCodeGenerator.visit_AssignBlockc             C   sV   | j  d k r+ | j r+ | j j | j  |  j d | j  | j j | j  d  S)Nrv   r   )rt   rU   r  rJ   r(   r   rZ   )rG   r&   r   r   r   r   ru     s    zCodeGenerator.visit_Namec             C   sE   | j  } t | t  r. |  j t |   n |  j t |   d  S)N)r9   r!   r1   r   strr   )rG   r&   r   r  r   r   r   visit_Const  s    	zCodeGenerator.visit_Constc             C   sS   y# |  j  t | j | j    Wn) t j k
 rN |  j  d | j  Yn Xd  S)Nz8(context.eval_ctx.autoescape and Markup or identity)(%r))r   r   r  rS   r   r  data)rG   r&   r   r   r   r   visit_TemplateData  s
    #	z CodeGenerator.visit_TemplateDatac             C   sy   |  j  d  d } x@ t | j  D]/ \ } } | rB |  j  d  |  j | |  q# W|  j  | d k rn d pq d  d  S)Nr   r   z, r   z,)r   r  )r   r  r   r#   )rG   r&   r   r  r:   r   r   r   visit_Tuple  s    zCodeGenerator.visit_Tuplec             C   sa   |  j  d  x@ t | j  D]/ \ } } | r< |  j  d  |  j | |  q W|  j  d  d  S)N[z, ])r   r  r   r#   )rG   r&   r   r  r:   r   r   r   
visit_List  s    zCodeGenerator.visit_Listc             C   s   |  j  d  xc t | j  D]R \ } } | r< |  j  d  |  j | j |  |  j  d  |  j | j |  q W|  j  d  d  S)N{z, z: r   )r   r  r   r#   r;   r9   )rG   r&   r   r  r:   r   r   r   
visit_Dict  s    zCodeGenerator.visit_Dictc                s     f d d   } | S)Nc                s   |  j  j re   |  j  j k re |  j d    |  j | j |  |  j d  |  j | j |  nD |  j d  |  j | j |  |  j d    |  j | j |  |  j d  d  S)Nz$environment.call_binop(context, %r, z, r   z %s r   )r'   	sandboxedZintercepted_binopsr   r#   leftright)rG   r&   r   )operatorr   r   r@     s    z$CodeGenerator.binop.<locals>.visitorr   )r#  interceptabler@   r   )r#  r   binop  s    zCodeGenerator.binopc                s     f d d   } | S)Nc                sz   |  j  j rE   |  j  j k rE |  j d    |  j | j |  n$ |  j d    |  j | j |  |  j d  d  S)Nz#environment.call_unop(context, %r, r   r   )r'   r   Zintercepted_unopsr   r#   r&   )rG   r&   r   )r#  r   r   r@     s    z#CodeGenerator.uaop.<locals>.visitorr   )r#  r$  r@   r   )r#  r   uaop  s    	zCodeGenerator.uaop+-*/z//z**r  andr$  orznot c             C   s   | j  j r d } n | j  j r* d } n d } |  j d |  x. | j D]# } |  j | |  |  j d  qK W|  j d  d  S)Nz;(context.eval_ctx.volatile and markup_join or unicode_join)Zmarkup_joinZunicode_joinz%s((z, z)))rS   r   r   r   r   r#   )rG   r&   r   r   r   r   r   r   visit_Concat  s    		zCodeGenerator.visit_Concatc             C   s;   |  j  | j |  x! | j D] } |  j  | |  q Wd  S)N)r#   exprZops)rG   r&   r   opr   r   r   visit_Compare  s    zCodeGenerator.visit_Comparec             C   s/   |  j  d t | j  |  j | j |  d  S)Nz %s )r   	operatorsr/  r#   r.  )rG   r&   r   r   r   r   visit_Operand  s    zCodeGenerator.visit_Operandc             C   s8   |  j  d  |  j | j |  |  j  d | j  d  S)Nzenvironment.getattr(z, %r))r   r#   r&   attr)rG   r&   r   r   r   r   visit_Getattr  s    zCodeGenerator.visit_Getattrc             C   s   t  | j t j  rX |  j | j |  |  j d  |  j | j |  |  j d  nM |  j d  |  j | j |  |  j d  |  j | j |  |  j d  d  S)Nr  r  zenvironment.getitem(z, r   )r!   r   r   ZSlicer#   r&   r   )rG   r&   r   r   r   r   visit_Getitem  s    zCodeGenerator.visit_Getitemc             C   s   | j  d  k	 r" |  j | j  |  |  j d  | j d  k	 rQ |  j | j |  | j d  k	 r |  j d  |  j | j |  d  S)Nr   )startr#   r   stopr   )rG   r&   r   r   r   r   visit_Slice  s    zCodeGenerator.visit_Slicec             C   se  |  j  |  j | j d  |  j j j | j  } | d  k rY |  j d | j | j  t | d d  r{ |  j  d  nA t | d d  r |  j  d  n t | d d  r |  j  d	  | j d  k	 r |  j	 | j |  nc | j
 j r|  j  d
 | j | j f  n7 | j
 j r0|  j  d | j  n |  j  d | j  |  j | |  |  j  d  d  S)Nr   zno filter named %rZcontextfilterFz	context, Zevalcontextfilterzcontext.eval_ctx, Zenvironmentfilterzenvironment, zB(context.eval_ctx.autoescape and Markup(concat(%s)) or concat(%s))zMarkup(concat(%s))z
concat(%s)r   )r   rm   r(   r'   getr   r   r   r&   r#   rS   r   rX   r   r   )rG   r&   r   r	  r   r   r   rp     s(    	zCodeGenerator.visit_Filterc             C   s~   |  j  |  j | j d  | j |  j j k rJ |  j d | j | j  |  j | j |  |  j | |  |  j  d  d  S)Nr   zno test named %rr   )	r   rn   r(   r'   r   r   r#   r&   r   )rG   r&   r   r   r   r   rq   4  s    zCodeGenerator.visit_Testc                s}       f d d   }  j  d   j  j     j  d   j  j     j  d  |    j  d  d  S)Nc                  sD    j  d  k	 r"  j  j     S j d d  j    d  S)Nzenvironment.undefined(%r)zRthe inline if-expression on %s evaluated to false and no else section was defined.)Zexpr2r#   r   r   r   )r   r&   rG   r   r   write_expr2=  s    z1CodeGenerator.visit_CondExpr.<locals>.write_expr2r   z if z else r   )r   r#   Zexpr1rz   )rG   r&   r   r:  r   )r   r&   rG   r   visit_CondExpr<  s    zCodeGenerator.visit_CondExprc             C   sx   |  j  j r |  j d  n |  j d  |  j | j |  | rN d d i pQ d  } |  j | | |  |  j d  d  S)Nzenvironment.call(context, zcontext.call(r   r   )r'   r   r   r#   r&   r   )rG   r&   r   r   r   r   r   r   r   L  s    zCodeGenerator.visit_Callc             C   s+   |  j  | j d  |  j | j |  d  S)N=)r   r;   r#   r9   )rG   r&   r   r   r   r   visit_KeywordV  s    zCodeGenerator.visit_Keywordc             C   s1   |  j  d  |  j | j |  |  j  d  d  S)NzMarkup(r   )r   r#   r.  )rG   r&   r   r   r   r   visit_MarkSafe\  s    zCodeGenerator.visit_MarkSafec             C   s1   |  j  d  |  j | j |  |  j  d  d  S)Nz5(context.eval_ctx.autoescape and Markup or identity)(r   )r   r#   r.  )rG   r&   r   r   r   r   visit_MarkSafeIfAutoescapea  s    z(CodeGenerator.visit_MarkSafeIfAutoescapec             C   s   |  j  d | j  d  S)Nzenvironment.)r   r(   )rG   r&   r   r   r   r   visit_EnvironmentAttributef  s    z(CodeGenerator.visit_EnvironmentAttributec             C   s!   |  j  d | j | j f  d  S)Nzenvironment.extensions[%r].%s)r   Z
identifierr(   )rG   r&   r   r   r   r   visit_ExtensionAttributei  s    z&CodeGenerator.visit_ExtensionAttributec             C   s   |  j  |  j | j  d  S)N)r   r   r   )rG   r&   r   r   r   r   visit_ImportedNamel  s    z CodeGenerator.visit_ImportedNamec             C   s   |  j  | j  d  S)N)r   r(   )rG   r&   r   r   r   r   visit_InternalNameo  s    z CodeGenerator.visit_InternalNamec             C   s   |  j  d  d  S)Nr   )r   )rG   r&   r   r   r   r   visit_ContextReferencer  s    z$CodeGenerator.visit_ContextReferencec             C   s   |  j  d |  d  S)Nr   )r   )rG   r&   r   r   r   r   visit_Continueu  s    zCodeGenerator.visit_Continuec             C   s   |  j  d |  d  S)Nbreak)r   )rG   r&   r   r   r   r   visit_Breakx  s    zCodeGenerator.visit_Breakc             C   sb   | j    } | j | j    |  j |  } |  j |  |  j | j |  |  j | |  d  S)N)ri   rc   r   r   r   r   r{   r   )rG   r&   r   Zscope_framer   r   r   r   r   {  s    zCodeGenerator.visit_Scopec             C   s   x | j  D] } |  j d | j  |  j | j |  y | j j | j  } Wn! t j k
 rs d | j _	 Yq
 Xt
 | j | j |  q
 Wd  S)Nzcontext.eval_ctx.%s = T)Zoptionsr   r;   r#   r9   r  rS   r   r  r   setattr)rG   r&   r   keywordr  r   r   r   visit_EvalContextModifier  s    z'CodeGenerator.visit_EvalContextModifierc             C   s   |  j    } | j j   } |  j d |  |  j | |  x! | j D] } |  j | |  qF W| j j |  |  j d |  d  S)Nz%s = context.eval_ctx.save()zcontext.eval_ctx.revert(%s))r   rS   Zsaver   rJ  r{   r#   Zrevert)rG   r&   r   Zold_ctx_nameZ	safed_ctxr
  r   r   r   visit_ScopedEvalContextModifier  s    z-CodeGenerator.visit_ScopedEvalContextModifier)WrN   rO   rP   rH   r   r   rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rr   r   r   r   r   r   r~   r   r   r   r   r  r  r  r   r   ru   r  r  r  r  r  r%  r&  Z	visit_AddZ	visit_SubZ	visit_MulZ	visit_DivZvisit_FloorDivZ	visit_PowZ	visit_ModZ	visit_AndZvisit_OrZ	visit_PosZ	visit_NegZ	visit_Notr-  r0  r2  r4  r5  r8  rp   rq   r;  r   r=  r>  r?  r@  rA  rB  rC  rD  rE  rG  r   rJ  rK  r   r   r   r   r   p  s   65D	c/+5~		


r   )0rQ   	itertoolsr   rM   r   rI  r   r   Zjinja2r   Zjinja2.nodesr   Zjinja2.visitorr   Zjinja2.exceptionsr   Zjinja2.utilsr	   r
   r   Zjinja2._compatr   r   r   r   r   r   r1  r  r8   r   r   r/   r   r,   r7   rA   r]   rB   rR   RuntimeErrorr=   rl   r<   rb   r  r   r   r   r   r   r   <module>
   sF   .	%XY