
    ,h!                        d Z ddl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 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 d
dlmZ d
dlm Z  d
dl!m"Z" ejF                  r
ddl$Z%d
dl&m'Z'  ejP                  dejR                  dejT                  f         Z+dddddd d!d"d#Z,d$e+d%e+fd&Z-d'e.d%ejR                  d(ej^                  d)gdf   fd*Z0d'e.d%ejR                  d(ejb                  d)gdf   fd+Z2	 	 	 dFd,ejf                  d-d.d/ejh                  e.   d0ejh                  e.   d1ejh                  ejj                     d2e6d3e6d%ejh                  e.   fd4Z7d5ejT                  d%e6fd6Z8d7ejr                  ejt                     d8ejr                  e.   d%ejv                  e.   fd9Z< G d: d;      Z= G d< d)      Z> G d= d>e?      Z@ G d? d@e"      ZA G dA dBe"      ZB G dC dDeC      ZD G dE d(e"      ZEy)Gz0Compiles nodes from the parser into Python code.    N)contextmanager)update_wrapper)StringIO)chain)	iskeyword)escape)Markup   )nodes)TemplateAssertionError)Symbols)VAR_LOAD_ALIAS)VAR_LOAD_PARAMETER)VAR_LOAD_RESOLVE)VAR_LOAD_UNDEFINED)EvalContext)	Optimizer)_PassArg)concat)NodeVisitor)EnvironmentF.)boundz==z!=>z>=<z<=inznot in)eqnegtgteqltlteqr   notinfreturnc           
           dddt         j                  dddt        j                  dt        j                  f
 fd}t	        |       S )	NselfCodeGeneratornodeframeFramekwargsr%   c                     | j                   S|j                  j                  s=| j                   j                  ||j                        }||k7  r| j                  ||      S  | ||fi |S N)	optimizereval_ctxvolatilevisit)r'   r)   r*   r,   new_noder$   s        Q/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/jinja2/compiler.pynew_funczoptimizeconst.<locals>.new_func.   sb     >>%enn.E.E~~++D%..AH4zz(E22tU-f--    )r   ExprtAnyr   )r$   r5   s   ` r4   optimizeconstr:   -   sK    
.
.%*ZZ
.8?
.KL55
.	

. (A&&r6   opr(   r+   c           	      Z     t         dddt        j                  dt        dd f fd       }|S )Nr'   r(   r)   r*   r%   c                    | j                   j                  rw| j                   j                  v r_| j                  dd       | j	                  |j
                  |       | j                  d       | j	                  |j                  |       n^| j                  d       | j	                  |j
                  |       | j                  d d       | j	                  |j                  |       | j                  d       y )Nz environment.call_binop(context, , ( ))environment	sandboxedintercepted_binopswriter2   leftrightr'   r)   r*   r;   s      r4   visitorz_make_binop.<locals>.visitor>   s     &&21A1A1T1T+TJJ9"rBCJJtyy%(JJtJJtzz5)JJsOJJtyy%(JJ2$ay!JJtzz5)

3r6   )r:   r   BinExprr+   r;   rI   s   ` r4   _make_binoprL   =   s<    o U]] 5 T    Nr6   c           	      Z     t         dddt        j                  dt        dd f fd       }|S )Nr'   r(   r)   r*   r%   c                 H   | j                   j                  rJ| j                   j                  v r2| j                  dd       | j	                  |j
                  |       n0| j                  dz          | j	                  |j
                  |       | j                  d       y )Nzenvironment.call_unop(context, r>   r?   rA   )rB   rC   intercepted_unopsrE   r2   r)   rH   s      r4   rI   z_make_unop.<locals>.visitorU   s|     &&21A1A1S1S+SJJ8bABJJtyy%(JJsRx JJtyy%(

3r6   )r:   r   	UnaryExprr+   rK   s   ` r4   
_make_unoprQ   R   s>     
o 
U__ 
U 
t 
 
 Nr6   r)   rB   r   namefilenamestream
defer_init	optimizedc                     t        | t        j                        st        d      |j	                  ||||||      }|j                  |        ||j                  j                         S y)z+Generate the python source for a node tree.z Can't compile non template nodesN)
isinstancer   Template	TypeErrorcode_generator_classr2   rT   getvalue)r)   rB   rR   rS   rT   rU   rV   	generators           r4   generater^   e   sf     dENN+:;;00T8VZI OOD~((**r6   valuec                 T   | | t         u s| t        u ryt        |       t        t        t
        t        t        t        t        hv ryt        |       t        t        t        t        hv rt        d | D              S t        |       t        u r t        d | j!                         D              S y)z)Does the node have a safe representation?Tc              3   2   K   | ]  }t        |        y wr.   has_safe_repr).0vs     r4   	<genexpr>z has_safe_repr.<locals>.<genexpr>   s     3=#3s   c              3   R   K   | ]  \  }}t        |      xr t        |       ! y wr.   rb   rd   kre   s      r4   rf   z has_safe_repr.<locals>.<genexpr>   s&     STQ=#8a(88Ss   %'F)NotImplementedEllipsistypeboolintfloatcomplexrangestrr	   tuplelistset	frozensetalldictitemsr_   s    r4   rc   rc   }   s    }/5H3DE{tS%%fEEE{udC333U333E{dSU[[]SSSr6   r   namesc                     t        |      }	 | D ]  }|j                  |        	 |j                  S # t        $ r Y |j                  S w xY w)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.
    )UndeclaredNameVisitorr2   VisitorExit
undeclared)r   r{   rI   r)   s       r4   find_undeclaredr      s\     $E*G 	 DMM$	    s   2 	A	A	c                   b    e Zd Zdej                  ej                  ej                  f   ddfdZy)MacroRefr)   r%   Nc                 <    || _         d| _        d| _        d| _        y NF)r)   accesses_calleraccesses_kwargsaccesses_varargsr'   r)   s     r4   __init__zMacroRef.__init__   s!    	$$ %r6   )	__name__
__module____qualname__r8   Unionr   Macro	CallBlockr    r6   r4   r   r      s+    &QWWU[[%//%AB &t &r6   r   c            	           e Zd ZdZ	 	 ddedej                  d    dej                  e   ddfdZddZ	dd	e
dd fd
ZddZe	Zy)r+   z&Holds compile time information for us.Nr0   parentlevelr%   c                 V   || _         || _        |'t        |      | _        d| _        d | _        d | _        nOt        |j                  |      | _        |j                  | _        |j
                  | _        |j                  | _        d| _        d| _        d| _	        d| _
        d| _        y )Nr   F)r0   r   r   symbolsrequire_output_checkbufferblocktoplevel	rootlevel
loop_frameblock_frame
soft_frame)r'   r0   r   r   s       r4   r   zFrame.__init__   s     ! >"/DL ).D% ,0DK +/DJ #6>>?DL(.(C(CD% --DKDJ 
    
  r6   c                     t         j                  | j                        }|j                  j	                  | j                         | j
                  j                         |_        |S )z!Create a copy of the current one.)object__new__	__class____dict__updater   copyr'   rvs     r4   r   z
Frame.copy   sC    ^^DNN+
4==)\\&&(
	r6   isolatedc                     |r.t        | j                  | j                  j                  dz         S t        | j                  |       S )zReturn an inner frame.r
   r   )r+   r0   r   r   )r'   r   s     r4   innerzFrame.inner   s6    dll.@.@1.DEET]]D))r6   c                 B    | j                         }d|_        d|_        |S )a&  Return 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.

        This is only used to implement if-statements and conditional
        expressions.
        FT)r   r   r   r   s     r4   softz
Frame.soft   s"     YY[	r6   )NN)r%   zte.SelfF)r   r   r   __doc__r   r8   Optionalrn   r   r   rm   r   r   __copy__r   r6   r4   r+   r+      sn    0
 '+!%	1 1  

7#1  zz#	1 
 
1 f*d *w * Hr6   c                       e Zd ZdZy)r~   z?Exception used by the `UndeclaredNameVisitor` to signal a stop.Nr   r   r   r   r   r6   r4   r~   r~      s    Ir6   r~   c                       e Zd ZdZd	dZdej                  ddfdZdej                  ddfdZ	dej                  ddfdZy)
DependencyFinderVisitorz.A visitor that collects filter and test calls.r%   Nc                 @    t               | _        t               | _        y r.   )ru   filterstestsr'   s    r4   r   z DependencyFinderVisitor.__init__   s    #&5!$
r6   r)   c                 p    | j                  |       | j                  j                  |j                         y r.   )generic_visitr   addrR   r   s     r4   visit_Filterz$DependencyFinderVisitor.visit_Filter  s&    4 #r6   c                 p    | j                  |       | j                  j                  |j                         y r.   )r   r   r   rR   r   s     r4   
visit_Testz"DependencyFinderVisitor.visit_Test  s$    4 

tyy!r6   c                      y)zStop visiting at blocks.Nr   r   s     r4   visit_Blockz#DependencyFinderVisitor.visit_Block      r6   r%   N)r   r   r   r   r   r   Filterr   Testr   Blockr   r   r6   r4   r   r      sO    8'$ $$ $"uzz "d "' ' 'r6   r   c                       e Zd ZdZdej
                  e   ddfdZdej                  ddfdZ
dej                  ddfdZy)	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.
    r{   r%   Nc                 B    t        |      | _        t               | _        y r.   )ru   r{   r   )r'   r{   s     r4   r   zUndeclaredNameVisitor.__init__  s    Z
&)er6   r)   c                 .   |j                   dk(  ra|j                  | j                  v rI| j                  j	                  |j                         | j                  | j                  k(  r
t               y | j                  j                  |j                         y )Nload)ctxrR   r{   r   r   r~   discardr   s     r4   
visit_Namez UndeclaredNameVisitor.visit_Name  sh    88v$))tzz"9OO		*$**,!m# - JJtyy)r6   c                      y)zStop visiting a blocks.Nr   r   s     r4   r   z!UndeclaredNameVisitor.visit_Block!  r   r6   )r   r   r   r   r8   Iterablerr   r   r   Namer   r   r   r   r6   r4   r}   r}     sP    
,ajjo ,$ ,*uzz *d *& & &r6   r}   c                       e Zd ZdZy)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.
    Nr   r   r6   r4   r   r   %  s    r6   r   c                   Z   e Zd ZU 	 	 	 ddddej                  e   dej                  e   dej                  ej                     deded	dfd
Ze	d	efd       Z
deded	dfdZd	efdZded	dfdZ	 ddeded	dfdZddZdded	dfdZddedej                  ej(                     d	dfdZded	dfdZ	 ddededej                  ej(                     d	dfdZdej0                  ej(                     ded	dfdZded	dfd Z	 ddedej                  ej(                     d!ed	dfd"Zddej                  ej(                     d!ed	dfd#Z	 ddej:                  ej<                  ej>                  ej@                  f   ded$ej                  ejB                  eejD                  f      d	dfd%Z#dej0                  ej(                     d	dfd&Z$ded	dfd'Z%dded(ed	dfd)Z&dd*ed+ed	efd,Z'ded	efd-Z(dej:                  ejR                  ejT                  f   ded	ejV                  ee,f   fd.Z-d/e,ded	dfd0Z.dej(                  d	efd1Z/ded	efd2Z0dd3Z1ded	dfd4Z2dd5Z3d6ed	dfd7Z4d6ed	dfd8Z5dd9Z6d	efd:Z7d	efd;Z8ded	efd<Z9d6ed	efd=Z:dd>Z;ded	dfd?Z<	 ddejz                  dej                  e   d	dfd@Z>dej~                  ded	dfdAZ@dej                  ded	dfdBZBdej                  ded	dfdCZDdej:                  ej                  ej                  f   ded	dfdDZGdej                  ded	dfdEZHdej                  ded	dfdFZIdej                  ded	dfdGZKdej                  ded	dfdHZMdejR                  ded	dfdIZNdejT                  ded	dfdJZOdej                  ded	dfdKZQdej                  ded	dfdLZSdej                  ded	dfdMZU G dN dOej                        ZWeXdPejD                  d	ejD                  fdQ       ZYdZZej                  eW   e[dR<   d	eWfdSZ\dTej0                  ejD                     d	efdUZ]dej                  dedVeWd	efdWZ_dej                  dedVeWd	dfdXZ`dej                  dedVeWd	dfdYZadej                  ded	dfdZZcdej                  ded	dfd[Zedej                  ded	dfd\Zgdej                  ded	dfd]Zidej                  ded	dfd^Zkdej                  ded	dfd_Zmdej                  ded	dfd`ZodejV                  ded	dfdaZpdej                  ded	dfdbZrdej                  ded	dfdcZt eudd      Zv eude      Zw eudf      Zx eudg      Zy eudh      Zz eudi      Z{ eudj      Z| eudk      Z} eudl      Z~ edd      Z ede      Z edm      Zedej                  ded	dfdn       Zedej                  ded	dfdo       Zdej                  ded	dfdpZedej                  ded	dfdq       Zedej                  ded	dfdr       Zdej                  ded	dfdsZedej:                  ej>                  ej@                  f   dedted	ej"                  d   fdu       Zedej>                  ded	dfdv       Zedej@                  ded	dfdw       Zedej*                  ded	dfdx       Ze	 ddej<                  dedyed	dfdz       Zdej0                  ded	dfd{Zdej4                  ded	dfd|Zdej8                  ded	dfd}Zdej<                  ded	dfd~Zdej@                  ded	dfdZdejD                  ded	dfdZdejH                  ded	dfdZdejL                  ded	dfdZdejP                  ded	dfdZdejT                  ded	dfdZdejX                  ded	dfdZdej\                  ded	dfdZdej`                  ded	dfdZdejd                  ded	dfdZdejh                  ded	dfdZy)r(   NrB   r   rR   rS   rT   rU   rV   r%   c                    |
t               }|| _        || _        || _        || _        d| _        || _        d | _        |rt        |      | _        i | _	        i | _
        d| _        d| _        d| _        i | _        i | _        g | _        d | _        d| _        d| _        d| _        d| _        d| _        g | _        g | _        dg| _        y )NFr   r
   Tcontext)r   rB   rR   rS   rT   created_block_contextrU   r/   r   import_aliasesblocksextends_so_farhas_known_extendscode_linenor   r   
debug_info_write_debug_info
_new_lines
_last_line_first_write_last_identifier_indentation_assign_stack_param_def_block_context_reference_stack)r'   rB   rR   rS   rT   rU   rV   s          r4   r   zCodeGenerator.__init__-  s     >ZF&	 %*"$04&{3DN 13 13  
 "'  (*
)+ 6826   ! !"  24 57 *3%r6   c                     | j                   d uS r.   )r/   r   s    r4   rV   zCodeGenerator.optimizedv  s    ~~T))r6   msglinenozte.NoReturnc                 F    t        ||| j                  | j                        )z*Fail with a :exc:`TemplateAssertionError`.)r   rR   rS   )r'   r   r   s      r4   failzCodeGenerator.fail|  s    $S&$))T]]KKr6   c                 J    | xj                   dz  c_         d| j                    S )zGet a new unique identifier.r
   t_)r   r   s    r4   temporary_identifierz"CodeGenerator.temporary_identifier  s'    "D))*++r6   r*   c                 j    | j                         |_        | j                  |j                   d       y)z7Enable buffering for the frame from that point onwards.z = []N)r   r   	writeliner'   r*   s     r4   r   zCodeGenerator.buffer  s)    002%,,u-.r6   force_unescapedc                     |s|j                   j                  r| j                  d       | j                          | j                  d|j                   d       | j                          | j                  d       | j                          | j                  d|j                   d       | j                          y|j                   j                  r | j                  d|j                   d       y| j                  d|j                   d       y)z(Return the buffer contents of the frame.zif context.eval_ctx.autoescape:zreturn Markup(concat())else:zreturn concat(rA   N)r0   r1   r   indentr   outdent
autoescape)r'   r*   r   s      r4   return_buffer_contentsz$CodeGenerator.return_buffer_contents  s     ~~&&@A!6u||nBGHw'~Q?@**!6u||nBGH~Q78r6   c                 .    | xj                   dz  c_         y)zIndent by one.r
   Nr   r   s    r4   r   zCodeGenerator.indent  s    Qr6   stepc                 .    | xj                   |z  c_         y)zOutdent by step.Nr   )r'   r   s     r4   r   zCodeGenerator.outdent  s    T!r6   r)   c                     |j                   | j                  d|       y| j                  |j                    d|       y)z%Yield or write into the frame buffer.Nyield .append()r   r   )r'   r*   r)   s      r4   start_writezCodeGenerator.start_write  s3    <<NN8T*NNell^84d;r6   c                 @    |j                   | j                  d       yy)z1End the writing process started by `start_write`.NrA   )r   rE   r   s     r4   	end_writezCodeGenerator.end_write  s    <<#JJsO $r6   sc                 l    | j                  ||       | j                  |       | j                  |       y)z4Simple shortcut for start_write + write + end_write.N)r   rE   r  )r'   r  r*   r)   s       r4   simple_writezCodeGenerator.simple_write  s+     	%

1ur6   r   c                 x    	 | j                  d       |D ]  }| j                  ||        y# t        $ r Y yw xY w)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.
        passN)r   r2   r   )r'   r   r*   r)   s       r4   
blockvisitzCodeGenerator.blockvisit  sB    	NN6" (

4'( 		s   *- 	99xc                    | j                   r| j                  s| j                  j                  d| j                   z         | xj                  | j                   z  c_        | j
                  8| j                  j                  | j
                  | j                  f       d| _        d| _        | j                  j                  d| j                  z         d| _         | j                  j                  |       y)z&Write a string into the output stream.
NFz    r   )	r   r   rT   rE   r   r   r   appendr   )r'   r  s     r4   rE   zCodeGenerator.write  s    ??$$!!$"89  DOO3 ))5OO**D,B,BDDTDT+UV-1D* %DKKft'8'889DO!r6   extrac                 J    | j                  ||       | j                  |       y)z!Combination of newline and write.N)newlinerE   )r'   r  r)   r  s       r4   r   zCodeGenerator.writeline  s     	T5!

1r6   c                     t        | j                  d|z         | _        |=|j                  | j                  k7  r#|j                  | _        |j                  | _        yyy)z/Add one or more newlines before the next write.r
   N)maxr   r   r   r   )r'   r)   r  s      r4   r  zCodeGenerator.newline  sL    dooq5y9t >%)[[D""kkDO !?r6   extra_kwargsc                    t        d t        d |j                  D        |xs d      D              }|j                  D ]%  }| j	                  d       | j                  ||       ' |se|j                  D ]%  }| j	                  d       | j                  ||       ' |/|j                         D ]  \  }}| j	                  d| d|         |j                  r-| j	                  d       | j                  |j                  |       |r|j                  | j	                  d       n| j	                  d	       |j                  D ]M  }| j	                  |j                  d
       | j                  |j                  |       | j	                  d       O |/|j                         D ]  \  }}| j	                  |d
| d        |j                  ?| j	                  d       | j                  |j                  |       | j	                  d       y| j	                  d       y|j                  .| j	                  d       | j                  |j                  |       yy)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 occur.  The extra keyword arguments should be given
        as python dict.
        c              3   b   K   | ]'  }t        t        j                  t        |             ) y wr.   )is_python_keywordr8   castrr   )rd   ri   s     r4   rf   z*CodeGenerator.signature.<locals>.<genexpr>  s'      
 affS!n-
s   -/c              3   4   K   | ]  }|j                     y wr.   )keyrd   r  s     r4   rf   z*CodeGenerator.signature.<locals>.<genexpr>  s     7aAEE7   r   r>   N=z, *z
, **dict({z, **{: z}, **rA   }z, **)anyr   r,   argsrE   r2   ry   dyn_args
dyn_kwargsr  r_   )	r'   r)   r*   r  kwarg_workaroundargkwargr  r_   s	            r4   	signaturezCodeGenerator.signature  s
     
74;;79KL
 

 99 	#CJJtJJsE"	#   )

4 

5%() '"."4"4"6 3JCJJC5%123==JJuJJt}}e,*

<(

7# !

eii]"-.

5;;.

4 ! '"."4"4"6 6JCJJ#5'456*

7#

4??E2

3

3__(JJvJJt. )r6   c           
         t               }|D ]  }|j                  |        | j                  |j                  df| j                  |j                  dffD ]  \  }}}t	        |      D ]  }||vr| j                         ||<   | j                  d       | j                          | j                  ||    d| d|d       | j                          | j                  d       | j                          | j                  d       | j                  d	||    d
       | j                          | j                  d|dd  d|d       | j                          | j                            y)a  Find all filter and test names used in the template and
        assign them to variables in the compiled namespace. Checking
        that the names are registered with the environment is done when
        compiling the Filter and Test nodes. If the node is in an If or
        CondExpr node, the check is done at runtime instead.

        .. versionchanged:: 3.0
            Filters and tests in If and CondExpr nodes are checked at
            runtime instead of compile time.
        r   r   try:z = environment.[]zexcept KeyError:z@internalcodedef z
(*unused):zraise TemplateRuntimeError("No N named z	 found."))	r   r2   r   r   sortedr   r   r   r   )r'   r   rI   r)   id_mapr{   
dependencyrR   s           r4   pull_dependencieszCodeGenerator.pull_dependencies  s\    *+ 	 DMM$	  \\7??I6

*
 	%FE: u v%#'#<#<#>F4L v&&,zl!D8STUV12/fTl^:>?5j"o5FdXY0 )	r6   c           	         g }|j                   j                  j                         D ]  \  }\  }}|t        k(  r|t        k(  r)| j                  | d| j                          d|d       E|t        k(  r| j                  | d|        e|t        k(  r|j                  |       t        d       |r$| j                  dj                  |       d       y y )N = r?   rA   zunknown load instruction
 = missing)r   loadsry   r   r   r   get_resolve_funcr   r   r  NotImplementedErrorjoin)r'   r*   undefstargetactionparams         r4   enter_framezCodeGenerator.enter_frameH  s    ',}}':':'@'@'B 
	F#FOVU++++&T-B-B-D,EQuiqQR>)&UG45--f%)*DEE
	F NNejj01<= r6   with_python_scopec                     |sUg }|j                   j                  D ]  }|j                  |        |r$| j                  dj	                  |       d       y y y )Nr1  r2  )r   r3  r  r   r6  )r'   r*   r<  r7  r8  s        r4   leave_framezCodeGenerator.leave_frameX  sY     F---- &f%&%**V"4!5Z@A 	 !r6   async_value
sync_valuec                 6    | j                   j                  r|S |S r.   )rB   is_async)r'   r?  r@  s      r4   choose_asynczCodeGenerator.choose_async`  s    "..77{GZGr6   c                 ,    | j                          d| S )Nr)  )rC  )r'   rR   s     r4   funczCodeGenerator.funcc  s    ##%&d4&11r6   c           
         |j                         }|j                  j                  |       t        |      }d}t	               }g }t        |j                        D ]s  \  }}|j                  dk(  r|}|j                  dv r|j                  |j                         |j                  |j                  j                  |j                               u t        |j                  d      }	d|	v rZ|'	 |j                  |t        |j                        z
      n*|j                  |j                  j%                  d             d|_        d|	v r5d|vr1|j                  |j                  j%                  d             d|_        d|	v r5d|vr1|j                  |j                  j%                  d             d|_        d	|_        |j                  j                  |       | j/                  | j1                  d
       ddj3                  |       d|       | j5                          | j7                  |       | j9                  |       | j;                  |       t        |j                        D ]  \  }}|j                  j                  |j                        }
| j/                  d|
 d       | j5                          	 |j                  |t        |j                        z
     }| j/                  |
 d       | j=                  ||       | j?                  |
       | jA                           | jC                          | jE                  |j                  |       | jG                  |d       | jI                  |d       | jA                          ||fS # t        $ r  | j!                  d|j"                         Y vw xY w# t        $ r1 | j/                  |
 d|j                  d|j                  d       Y w xY w)z/Dump the function def of a macro or call block.Ncaller)r,   varargs)rG  r,   rH  zhWhen defining macros or call blocks the special "caller" argument must be omitted or be given a default.Tr,   rH  Fmacror?   r>   ):if  is missing:r1  z = undefined("parameter z was not provided", name=rA   )r   r<  )%r   r   analyze_noder   ru   	enumerater  rR   r   r  refr   bodydefaultslen
IndexErrorr   r   declare_parameterr   r   r   r   r   rE  r6  r   r   r;  push_parameter_definitionsr2   mark_parameter_storedr   pop_parameter_definitionsr  r   r>  )r'   r)   r*   	macro_refexplicit_callerskip_special_paramsr  idxr"  r   rP  defaults               r4   
macro_bodyzCodeGenerator.macro_bodyf  sb    ""4(TN	!e!$)), 	5HCxx8#"%xx00#''1KK))#((34	5 %TYY0OP
z! *MM/C		N"BC EMM;;HEF(,I%z!h6I&IKK77AB(,I%
"y8K'KKK77	BC)-I& &+"""4($))G,-Qtyy.?rBDIE''.!$)), 	HC--##CHH-CNNS\23KKM	+--c$))n(<= #c{+

7E*&&s+LLN	  	&&(		5)##E4#@$7ie " II1 	B  e3CHH< @ XXL+s$   -%N 7%N7%N43N477O10O1rY  c                 V   dj                  d |j                  j                  D              }t        |j                  dd      }t	        |j                  j                        dk(  r|dz  }| j                  d|d| d	|j                  d|j                  d|j                  d
       y)z<Dump the macro definition for the def created by macro_body.r>   c              3   F   K   | ]  }t        |j                          y wr.   )reprrR   r  s     r4   rf   z*CodeGenerator.macro_def.<locals>.<genexpr>  s     Hqd166lHs   !rR   Nr
   ,zMacro(environment, macro, z, (z), z, context.eval_ctx.autoescape))	r6  r)   r  getattrrS  rE   r   r   r   )r'   rY  r*   	arg_tuplerR   s        r4   	macro_defzCodeGenerator.macro_def  s    IIHINN4G4GHH	y~~vt4y~~""#q(I

(I; ?)),By/I/I.L M)),,JL	
r6   c                 ^    d|j                    }| j                  | d| j                  }|S )z.Return a human readable position for the node.zline  in )r   rR   )r'   r)   r   s      r4   positionzCodeGenerator.position  s5    T[[M"99 4tDII=)B	r6   c                     dj                  d |j                  j                         j                         D              }d| dS )Nr>   c              3   0   K   | ]  \  }}|d |   ywr  Nr   )rd   rR   r8  s      r4   rf   z3CodeGenerator.dump_local_context.<locals>.<genexpr>  s'      
f hb!
   {r  )r6  r   dump_storesry   )r'   r*   items_kvs      r4   dump_local_contextz CodeGenerator.dump_local_context  sD    99 
 % 9 9 ; A A C
 
 H:R  r6   c                     | j                  d       | j                  d       | j                  d       | j                  d       | j                  d       y)zWrites a common preamble that is used by root and block functions.
        Primarily this sets up common local helpers and enforces a generator
        through a dead branch.
        z$resolve = context.resolve_or_missingz!undefined = environment.undefinedzconcat = environment.concatzcond_expr_undefined = Undefinedzif 0: yield NoneNr   r   s    r4   write_commonszCodeGenerator.write_commons  sG    
 	=>:;45 	89)*r6   c                 j    | j                   j                  |j                  j                                y)aQ  Pushes all parameter targets from the given frame into a local
        stack that permits tracking of yet to be assigned parameters.  In
        particular this enables the optimization from `visit_Name` to skip
        undefined expressions for parameters in macros as macros can reference
        otherwise unbound parameters.
        N)r   r  r   dump_param_targetsr   s     r4   rV  z(CodeGenerator.push_parameter_definitions  s%     	$$U]]%E%E%GHr6   c                 8    | j                   j                          y)z+Pops the current parameter definitions set.N)r   popr   s    r4   rX  z'CodeGenerator.pop_parameter_definitions  s    !!#r6   r8  c                 Z    | j                   r| j                   d   j                  |       yy)zMarks a parameter in the current parameter definitions as stored.
        This will skip the enforced undefined checks.
        r*  N)r   r   r'   r8  s     r4   rW  z#CodeGenerator.mark_parameter_stored  s+       !!"%--f5 !r6   c                 :    | j                   j                  |       y r.   )r   r  ry  s     r4   push_context_referencez$CodeGenerator.push_context_reference  s    %%,,V4r6   c                 8    | j                   j                          y r.   )r   rw  r   s    r4   pop_context_referencez#CodeGenerator.pop_context_reference  s    %%))+r6   c                      | j                   d   S )Nr*  r   r   s    r4   get_context_refzCodeGenerator.get_context_ref  s    ,,R00r6   c                 6    | j                   d   }|dk(  ry| dS )Nr*  r   resolvez.resolver  ry  s     r4   r4  zCodeGenerator.get_resolve_func  s*    ..r2Y""r6   c                 L    | j                          d| j                  |       dS )Nz	.derived(rA   )r  rp  r   s     r4   derive_contextzCodeGenerator.derive_context  s,    &&()43J3J53Q2RRSTTr6   c                 >    | j                   sy|| j                   d   v S )z4Checks if a given target is an undeclared parameter.Fr*  )r   ry  s     r4   parameter_is_undeclaredz%CodeGenerator.parameter_is_undeclared  s$    $$..r222r6   c                 J    | j                   j                  t                      y)z+Pushes a new layer for assignment tracking.N)r   r  ru   r   s    r4   push_assign_trackingz"CodeGenerator.push_assign_tracking  s    !!#%(r6   c                 x   | j                   j                         }|j                  s|j                  s|j                  r|sy|D cg c]  }|dd dk7  s| }}t        |      dk(  rt        t        |            }|j                  j                  |      }|j                  r| j                  d|d|        y|j                  r| j                  d|d|        y| j                  d|d|        n|j                  r| j                  d       n/|j                  r| j                  d	       n| j                  d
       t        t        |            D ]I  \  }}|r| j                  d       |j                  j                  |      }| j                  |d|        K | j                  d       |j                  su|j                  sh|ret        |      dk(  r| j                  d|d   d       ydj                  t        t         t        |                  }| j                  d| d       yyyyc c}w )zoPops the topmost level for assignment tracking and updates the
        context variables if necessary.
        Nr
   _z_loop_vars[] = z_block_vars[context.vars[z_loop_vars.update({z_block_vars.update({context.vars.update({r>   r  })context.exported_vars.add(r   rA   zcontext.exported_vars.update((r   )r   rw  r   r   r   rS  nextiterr   rP  r   rO  r,  rE   r6  mapra  )	r'   r*   varsr  public_namesrR   rP  r\  	names_strs	            r4   pop_assign_trackingz!CodeGenerator.pop_assign_tracking  s    !!%%'!!$$NN#'8a1Ra5C<88t9>T
#D--##D)CTHD>?  dXT#?@NN]4($se<=45""5667&vd|4 /	TJJt$mm''-

dXRu-.	/
 JJt  )9)9l< A%!;LO;NaPQ IIc$|0D&EF	!?	{"MN ?K)9 1 9s   H7H7c           	         |J d       t        | j                  | j                        }ddlm} ddlm} | j                  j                  rt        ||z         }nt        |      }| j                  ddj                  |      z          | j                  rdnd}|j                  t        j                        d u}|j                  t        j                        D ]]  }	|	j                  | j                   v r*| j#                  d	|	j                  d
|	j$                         |	| j                   |	j                  <   _ |j                  t        j&                        D ]  }
|
j(                  | j*                  vs|
j(                  }| j-                         x| j*                  |<   }d|v r0|j/                  dd      \  }}| j                  d| d| d|        {| j                  d| d|         | j                  d| j                         | j                  | j1                  d       d| dd       | j3                          | j5                          t7        |      }dt9        |j:                  d      v r/|j<                  j?                  d      }| j                  | d       |j<                  jA                  |       dx|_!        |_"        |xr | jF                   |_$        |r| j                  d       | jK                  |       | jM                  |j:                         | jO                  |j:                  |       | jQ                  |d       | jS                          |r| jF                  s!| j3                          | j                  d       | j3                          | j                  j                  s| j                  d       n| j                  d       | j                  d       | j3                          | j                  d       | j3                          | j                  d        | jS                          | jS                          | j                  d!       | jS                  d| jF                   z          | j                   jU                         D ]  \  }}	| j                  | j1                  d"|z          d| d|	d       | j3                          | j5                          t7        |      }d|_+        t9        |	j:                  d#      }d|v r/|j<                  j?                  d      }| j                  | d       d$|v r5|j<                  j?                  d$      }| j                  | d%|d&| d'       |j<                  jA                  |	       ||_,        | j                  d(       | jK                  |       | jM                  |	j:                         | jO                  |	j:                  |       | jQ                  |d       | jS                           dj                  d) | j                   D              }| j                  d*| d+d       d,j                  d- | jZ                  D              }| j                  d.|       y )/Nzno root frame allowedr
   )async_exported)exportedzfrom jinja2.runtime import r>    z, environment=environmentzblock z defined twice.zfrom z import z as zimport zname = rootz(context, missing=missingrJ  )r  r'   r   z = TemplateReference(context)Tzparent_template = NonerM  if parent_template is not None:z4yield from parent_template.root_render_func(context)z0agen = parent_template.root_render_func(context)r&  zasync for event in agen:zyield eventzfinally: await agen.aclose()block_)r'   superr  z = context.super(z, block_rA   z_block_vars = {}c              3   *   K   | ]  }|d |   yw)z: block_Nr   r  s     r4   rf   z/CodeGenerator.visit_Template.<locals>.<genexpr>  s     !K!QE!"5!Ks   z
blocks = {r  &c              3   0   K   | ]  \  }}| d |   yw)r  Nr   rh   s      r4   rf   z/CodeGenerator.visit_Template.<locals>.<genexpr>  s     Gtq!1#Qqc
Grl  zdebug_info = ).r   rB   rR   runtimer  r  rB  r,  r   r6  rU   findr   Extendsfind_allr   r   r   r   ImportedName
importnamer   r   rsplitrE  r   rs  r+   r   rQ  r   rU  rN  r   r   r   r   r;  r/  r  r>  r   ry   r   r   r   )r'   r)   r*   r0   r  r  exported_namesenvenvhave_extendsr   import_impaliasmoduleobjrP  rR   r   r   blocks_kv_strdebug_kv_strs                        r4   visit_TemplatezCodeGenerator.visit_Template=  s}    }555t//;+%$$#H~$=>N#H-N4tyy7PPQ ,G yy/t; ]]5;;/ 	,EzzT[[(		F5::.?N&+DKK

#	, }}U%7%78 	?G!!)<)<<((373L3L3NN##C(5#:"%**S!"4KFCNNU6((3%tE7#KLNNWSEeW#=>	? 	./ 	yy !!:6("EQ 	 	
 	 h_TYY	::--11&9CNNcU"?@A""4(+//%1%P$:P:P6P"NN34tyy)		5)$7 ))@AKKM##,,UVQRv&9:}-=>LL$"8"889:  ;;,,. 	KD%NN99X_-..GxrR
 KKM   /K&*K#(5FGJ#!));;FC#&CDE*$!));;GD#&7xxvQOP,,U3 $KNN-.[)""5::.OOEJJ4[DALLN7	: 		!Kt{{!KK]O26a@xxGtGG|&678r6   c                    d}|j                   rB| j                  ry| j                  dkD  r&| j                  d       | j	                          |dz  }|j
                  r| j                  |      }n| j                         }|j                  r`| j                  d|j                  d|       | j	                          | j                  d|j                  d|       | j                          | j                  j                  s0|j                  $| j                  d	|j                  d
| d|       n| j                  d|j                  d
| d       | j                  d       | j	                          | j                  | j                          d|       | j	                          | j                  d|       | j                          | j                          | j                  d| j                  dd              | j                  |       y)z.Call a block and register it for the template.r   Nif parent_template is None:r
   zif len(context.blocks[z]) <= 1:z+raise TemplateRuntimeError("Required block z not found")zyield from context.blocks[z][0](rA   zgen = context.blocks[r&  for event in gen:event	finally: await gen.aclose()gen.close())r   r   r   r   r   scopedr  r  requiredrR   r   rB   rB  r   rC  r  )r'   r)   r*   r   r   s        r4   r   zCodeGenerator.visit_Block  s   >> %%""Q&<=
;;))%0G**,G==NN3DII=I4PKKMNN=dii],W LLN((U\\-ANN,TYYMwiqI4 NN2499-uWIQOPNN6"KKMNN$$&''89 KKMgu-LLNLLNNND--.BMRST 	Ur6   c                    |j                   s| j                  d|j                         | j                  dkD  rd| j                  s!| j                  d       | j                          | j                  d       | j                  r
t               | j                          | j                  d|       | j                  |j                  |       | j                  d| j                  d       | j                  d       | j                          | j                  d	       | j                          |j                  rd
| _        | xj                  dz  c_        y)zCalls the extender.z,cannot use extend from a non top-level scoper   r  z5raise TemplateRuntimeError("extended multiple times")z+parent_template = environment.get_template(r>   rA   z9for name, parent_block in parent_template.blocks.items():z8context.blocks.setdefault(name, []).append(parent_block)Tr
   N)r   r   r   r   r   r   r   r   r   r2   templaterE   rR   r   r'   r)   r*   s      r4   visit_ExtendszCodeGenerator.visit_Extends  s    ~~IIDdkkR
 "
 ))@ANNRS %%"n$DdK

4==%(

R		}A&'RSQR
 ??%)D" 	q r6   c                     |j                   r! j                  d        j                          d}t        |j                  t
        j                        rTt        |j                  j                  t              rd}nct        |j                  j                  t        t        f      r9d}n6t        |j                  t
        j                  t
        j                  f      rd} j                  d| d|        j                  |j                          j                  d j                  d       |j                   rs j!                           j                  d	        j                           j                  d
        j!                           j                  d        j                          d fd}|j"                  r j                  d j%                         d        j                  d        j                           j                   j'                          d        |         j!                           j                  d j'                  dd              n@ j(                  j*                  r j                  d        |        n j                  d       |j                   r j!                          yy)zHandles includes.r&  get_or_select_templateget_templateselect_templateztemplate = environment.r?   r>   rA   zexcept TemplateNotFound:r  r   Nc                  j    j                          j                  d        j                          y )Nr  )r   r  r   )r*   r'   s   r4   	loop_bodyz.CodeGenerator.visit_Include.<locals>.loop_body-  s%    KKMgu-LLNr6   zNgen = template.root_render_func(template.new_context(context.get_all(), True, r   r  r  r  r  zGfor event in (await template._get_default_module_async())._body_stream:z6yield from template._get_default_module()._body_streamr   )ignore_missingr   r   rX   r  r   Constr_   rr   rs   rt   TupleListr2   rE   rR   r   with_contextrp  rC  rB   rB  )r'   r)   r*   	func_namer  s   ` `  r4   visit_IncludezCodeGenerator.visit_Include  s   NN6"KKM,	dmmU[[1$----s3*	DMM//%?-	UZZ'@A)I01=tD

4==%(

R		}A&'LLNNN56KKMNN6"LLNNN7#KKM	
 NN++E2327
 NN6"KKMNNd//122CDEKLLNNND--.BMRST &&NN! KNNSTLLN r6   c                    | j                  | j                  d       d       | j                  |j                  |       | j                  d| j                  d       |j
                  r;d| j                  d       }| j                  | d| j                  |       d       y | j                  d	| j                  d       d
       y )Nawait zenvironment.get_template(r>   z).make_module_asyncz(context.get_all(), True, rA   _get_default_modulez	(context))rE   rC  r2   r  rR   r  rp  )r'   r)   r*   f_names       r4   _import_commonzCodeGenerator._import_commonL  s     	

d''122KLM

4==%(

R		}B'("4#4#4X#>"?@FJJ(4T5L5LU5S4TTUV JJ,T->->x-H,ISTr6   c                 ~   | j                  |j                  j                  |j                         d|       |j                  r| j                  d|j                  d       | j                  ||       |j                  r<|j                  j                  d      s | j                  d|j                  d       yyy)zVisit regular imports.r1  r  r  r  context.exported_vars.discard(rA   N)r   r   rP  r8  r   rE   r  
startswithr  s      r4   visit_ImportzCodeGenerator.visit_Import[  s    %--++DKK89=tD>>JJt{{oT:;D%(>>$++"8"8"=NN;DKK?!LM #>>r6   c           	         | j                  |       | j                  d       | j                  |       g }g }|j                  D ]H  }t	        |t
              r|\  }}n|}| j                  j                  j                  |       d|d       | j                  dj                  j                  |       d       | j                          | j                  |      j                  dd      j                  dd	      }d
| d|}| j                  j                  j                  |       d|d|d       | j                          j                  s|j                  |       |j                  d      r8|j                  |       K |rst!        |      dk(  r6|d   }| j                  d|dj                  j                  |              n/dj#                  fd|D              }	| j                  d|	 d       |r\t!        |      dk(  r| j                  d|d   d       ydj#                  t%        t&        |            }
| j                  d|
 d       yy)zVisit named imports.zincluded_template = z = getattr(included_template, z
, missing)rK  rL  rm  z{{r  z}}z9the template {included_template.__name__!r} (imported on z%) does not export the requested name z = undefined(fz, name=rA   r  r
   r   r  r  r>   c              3   ^   K   | ]$  }|d j                   j                  |        & ywrk  )r   rP  )rd   rR   r*   s     r4   rf   z1CodeGenerator.visit_FromImport.<locals>.<genexpr>  s1      %?Cthb!2!24!8 9:%s   *-r  r  r  z)context.exported_vars.difference_update((r   N)r  rE   r  r{   rX   rs   r   r   rP  r   rh  replacer   r   r  r  rS  r6  r  ra  )r'   r)   r*   	var_namesdiscarded_namesrR   r  rh  messagenames_kvr  s     `        r4   visit_FromImportzCodeGenerator.visit_FromImportf  sT   T

)*D%(	JJ 	2D$&"eNN==$$U+, -//3hjB NNS!2!25!9 :,GHKKM
 }}T*223=EEc4PH!!)
 +77;h@ 
 NN==$$U+,N7+WTHTUV LLN~~  ''',#**519	2< 9~" |thd5==;L;LT;R:STU99 %GP%  !7zEF?#q(!?PQ@R?UUVWX IIc$&@A	?	{"M r6   c                 "   |j                         }d|_        |j                         }|j                         }|j                  xsO dt        |j	                  d      d      v xs/ t        d |j                  t        j                        D              }d }|r|j                  j                  d      }|j                  j                  |d       |j                  r|j                  j                  |d	       |j                  r| j                         }|j                  j                  |d
       | j                  | j!                  |       d|j                         | j#                          | j%                  |       | j                  | j'                  dd             | j)                  |j*                  |       | j-                  d       | j-                  | j'                  dd             | j-                  d       | j#                          | j                  d|j                         | j)                  |j                  |       | j-                  d       | j#                          | j                  d       | j)                  |j*                  |       | j/                  d       | j1                  |d       |j                  rV| j                  | j!                  d       d|       | j#                          | j3                  |       |j2                  |_        |r| j                  | d       |j                  t        j4                        D ]>  }	|	j6                  dk(  s|	j8                  dk(  s#| j;                  d|	j<                         @ |j                  r$| j                         }
| j                  |
 d       | j                  | j'                  dd      |       | j)                  |j*                  |       |r(| j-                  d| d| j'                  d       d       n| j-                  d       |j                  r| j-                   d       |j                  r| j-                  d       nn| j>                  j@                  r|s| j-                  d        | j)                  |jB                  |       | j>                  j@                  r|s| j-                  d!       |j                  r| j-                  d!       |j                  r| j-                  d"       n| j-                  |rd#nd       | j#                          | j%                  |       | j                  d$       | jE                  |jF                  |       |j                  r| j                  
 d%       | j/                          | j1                  ||j                  xr |j                          |j                  rs| j                  d
 d       | j#                          | j%                  |       | jE                  |j                  |       | j1                  |       | j/                          |j                  r| jI                  |       | j/                          | jK                  ||       | j-                  | j'                  d&       d'       | j>                  j@                  r| j-                  d        | j)                  |jB                  |       | j>                  j@                  r| j-                  d!       | j-                  d(       | jM                  |       | jN                  r3| jN                  d)   jQ                  |j                  jR                         y y )*NTloop)rQ  )only)r  c              3   4   K   | ]  }|j                     y wr.   )r  )rd   r   s     r4   rf   z*CodeGenerator.visit_For.<locals>.<genexpr>  s     HE5<<Hr  rQ  )
for_branchelsetestz(fiter):z
async for zfor rg  zauto_aiter(fiter)fiter:rK  r      rM  z%(reciter, loop_render_func, depth=0):r2  storez8Can't assign to special loop variable in for-loop targetz = 1r>   AsynczLoopContext(r?   reciterzauto_aiter(rA   z&, undefined, loop_render_func, depth):z, undefined):z_loop_vars = {}z = 0r  zloop(z, loop)r*  )*r   r   	recursiver   iter_child_nodesr  r  r   r   r   rU  rN  else_r  r   r   rE  r   r;  rC  r2   r8  rE   r   r>  r   r   r   rR   r   r   rB   rB  r  r  rQ  r   r   r  r   difference_updatestores)r'   r)   r*   r   
test_frame
else_frameextended_looploop_refloop_filter_funcrR   iteration_indicators              r4   	visit_ForzCodeGenerator.visit_For  s   [[]
 $
[[]
[[]
 NN It44)4DiPQI HT]]5;;-GHH	 	 !));;FCH'''@::++DV+D99#88:++DV+DNNdii(89:(CTYYOKKMZ(NN4,,\6BCJJt{{J/JJvJJt(()<gFGJJsOKKMNN5$)),JJtyy*-JJsOKKMNN8$JJt{{J/LLOZ4@
 >>NN99V$%%JKT KKMKK
# !+ 1 1J NNhZz23MM%**- 	Dxx7"tyyF':		NKK	 ::"&";";"=NN12$78t((v>E

4;;
+JJH:T$*;*;G*D)E\RSJJv99JJ*+1-.>>JJy!((

=)JJtyy%(((

399JJsO>>JJ?@JJ-SA$()		:.::NN12$78$..*K^ 	 	
 ::NNS!4 5Q78KKMZ(OODJJ
3Z(LLN >>''
3LLNUD)JJ$++H56e<=((

=)JJtyy%(((

3JJy!NN5! r"44Z5G5G5N5NO r6   c                    |j                         }| j                  d|       | j                  |j                  |       | j	                  d       | j                          | j                  |j                  |       | j                          |j                  D ]}  }| j                  d|       | j                  |j                  |       | j	                  d       | j                          | j                  |j                  |       | j                           |j                  rN| j                  d       | j                          | j                  |j                  |       | j                          y y )NrK  r  zelif r   )r   r   r2   r  rE   r   r  rQ  r   elif_r  )r'   r)   r*   if_framer  s        r4   visit_IfzCodeGenerator.visit_If(  s    ::<ud#

499h'

3		8,ZZ 	ENN7E*JJuzz8,JJsOKKMOOEJJ1LLN	 ::NN7#KKMOODJJ1LLN	 r6   c                    | j                  ||      \  }}| j                          |j                  rY|j                  j	                  d      s| j                  d|j                  d       | j                  d|j                  d       | j                  |j                  j                  |j                         d       | j                  ||       y )Nr  r  rA   r  r  r1  )
r^  r  r   rR   r  rE   r   r   rP  re  )r'   r)   r*   macro_framerY  s        r4   visit_MacrozCodeGenerator.visit_Macro=  s    !%u!=Y>>99'',

7		}AFGNN]499-t<=

emm''		23378y+.r6   c                     | j                  ||      \  }}| j                  d       | j                  ||       | j                  ||       | j	                  |j
                  |d       | j                  |       y )Nz	caller = T)forward_caller)r^  r   re  r   
visit_Callcallr  )r'   r)   r*   
call_framerY  s        r4   visit_CallBlockzCodeGenerator.visit_CallBlockG  sc     $e <
I{#y*-%		5>ur6   c                 v   |j                         }|j                  j                  |       | j                  |       | j	                  |       | j                  |j                  |       | j                  ||       | j                  |j                  |       | j                  |       | j                  |       y r.   )r   r   rN  r;  r   r  rQ  r   r   filterr  r>  )r'   r)   r*   filter_frames       r4   visit_FilterBlockzCodeGenerator.visit_FilterBlockO  s    {{}))$/&L!		<0%$++|4u&r6   c                    |j                         }|j                  j                  |       | j                  |       t	        |j
                  |j                        D ]J  \  }}| j                          | j                  ||       | j                  d       | j                  ||       L | j                  |j                  |       | j                  |       y )Nr1  )r   r   rN  r;  ziptargetsvaluesr  r2   rE   r  rQ  r>  )r'   r)   r*   
with_framer8  exprs         r4   
visit_WithzCodeGenerator.visit_WithZ  s    [[]
''-$dkk: 	$LFDLLNJJvz*JJuJJtU#		$
 			:.$r6   c                 ^    | j                  |       | j                  |j                  |       y r.   )r  r2   r)   r  s      r4   visit_ExprStmtzCodeGenerator.visit_ExprStmtf  s     T

499e$r6   c                   t    e Zd ZU ej                  ej
                  def      ed<   ej                  e   ed<   y)CodeGenerator._FinalizeInfo.constsrcN)r   r   r   r8   r   Callablerr   __annotations__r   r6   r4   _FinalizeInfor  j  s,    zz!**S#X.//ZZ_r6   r  r_   c                     t        |       S )zThe default finalize function if the environment isn't
        configured with one. Or, if the environment has one, this is
        called on that function's output for constants.
        )rr   rz   s    r4   _default_finalizezCodeGenerator._default_finalizen  s     5zr6   	_finalizec                 b     j                    j                   S  j                  x}d} j                  j                  rd} j                  j                  t        j
                  dt        j                  dt        j                  dij                  t	        j                              }d}|(dt        j                  dt        j                  ffd}n4| | d	}|dk(  r(dt        j                  dt        j                  f fd
} j                  ||       _          j                   S )a  Build the finalize function to be used on constants and at
        runtime. Cached so it's only created once for all output nodes.

        Returns a ``namedtuple`` with the following attributes:

        ``const``
            A function to finalize constant data at compile time.

        ``src``
            Source code to output around nodes to be evaluated at
            runtime.
        Nzenvironment.finalize(r   context.eval_ctxrB   r_   r%   c                        |             S r.   r   )r_   r]  env_finalizes    r4   finalizez.CodeGenerator._make_finalize.<locals>.finalize  s    "<#677r6   r>   c                 6      j                   |             S r.   )rB   )r_   r]  r"  r'   s    r4   r#  z.CodeGenerator._make_finalize.<locals>.finalize  s    &|D4D4De'LMMr6   )r  r  rB   r#  r   r   eval_contextgetfrom_objr8   r9   r  )r'   r#  r  pass_argr]  r"  s   `   @@r4   _make_finalizezCodeGenerator._make_finalizex  s    >>%>>! "3337$$)C++44L  )%%'9$$m c!!,/	  H8AEE 8aee 8 hZr*},N N!%% N ++Hc:~~r6   groupc                 *    t        t        |            S )zGiven a group of constant values converted from ``Output``
        child nodes, produce a string to write to the template module
        source.
        )ra  r   )r'   r*  s     r4   _output_const_reprz CodeGenerator._output_const_repr  s    
 F5M""r6   r#  c                     |j                  |j                        }|j                  j                  rt        |      }t	        |t
        j                        rt        |      S |j                  |      S )aC  Try to optimize a child of an ``Output`` node by trying to
        convert it to constant, finalized data at compile time.

        If :exc:`Impossible` is raised, the node is not constant and
        will be evaluated at runtime. Any other exception will also be
        evaluated at runtime for easier debugging.
        )	as_constr0   r   r   rX   r   TemplateDatarr   r  )r'   r)   r*   r#  r  s        r4   _output_child_to_constz$CodeGenerator._output_child_to_const  sW     enn->>$$5ME dE../u:~~e$$r6   c                    |j                   j                  r| j                  d       n9|j                   j                  r| j                  d       n| j                  d       |j                  | j                  |j                         yy)zXOutput extra source code before visiting a child of an
        ``Output`` node.
        z1(escape if context.eval_ctx.autoescape else str)(zescape(zstr(N)r0   r1   rE   r   r  r'   r)   r*   r#  s       r4   _output_child_prezCodeGenerator._output_child_pre  sb     >>""JJJK^^&&JJy!JJv<<#JJx||$ $r6   c                 b    | j                  d       |j                  | j                  d       yy)zWOutput extra source code after visiting a child of an
        ``Output`` node.
        rA   N)rE   r  r2  s       r4   _output_child_postz CodeGenerator._output_child_post  s)     	

3<<#JJsO $r6   c                 ~   |j                   r.| j                  ry | j                  d       | j                          | j	                         }g }|j
                  D ]  }	 |j                  s.t        |t
        j                        st        j                         | j                  |||      }|r(t        |d   t              r|d   j                  |       {|j                  |g        |j                  [t        |      dk(  r| j                  |j                   d       n| j                  |j                   d       | j                          |D ]  }t        |t              rG| j!                  |      }|j                  | j                  d|z          E| j                  |dz          Z|j                  | j                  d|       n| j#                  |       | j%                  |||       | j'                  ||       | j)                  |||       |j                  | j+                  d        |j                  1| j-                          | j                  t        |      dk(  rdnd	       |j                   r| j-                          y y # t
        j                  t        f$ r |j                  |       Y bw xY w)
Nr  r*  r
   r   z	.extend((r   rb  rA   r   )r   r   r   r   r)  r   r  rX   r/  
Impossibler0  	Exceptionr  rt   r   rS  r,  r  r3  r2   r5  rE   r   )	r'   r)   r*   r#  rQ  childr  itemvals	            r4   visit_OutputzCodeGenerator.visit_Output  sH   %%%%NN89KKM&&(;=
 ZZ 	%E NN "%););<**,,33E5(K 
48T2R&UG$/	%2 <<#4yA~%,,x89%,,y9:KKM 	$D$%--d3<<'NN8c>2NN39-<<'NN8T2LL& &&tUH=

4'''eX><<+JJsO+	$. <<#LLNNN#d)q.3d;%%LLN &_ $$i0  E"s   AJ*J<;J<c                    | j                          t               }|j                  t        j                        D ]  }|j
                  |v r|j                  |j
                         |j                  j                  |j
                        }| j                  d| d       | j                          | j                  d       | j                           | j                  |       | j                  |j                  |       | j                  d       | j                  |j                   |       | j#                  |       y )Nzif not isinstance(z, Namespace):zMraise TemplateRuntimeError("cannot assign attribute on non-namespace object")r1  )r  ru   r  r   NSRefrR   r   r   rP  r   r   r   r  r2   r8  rE   r)   r  )r'   r)   r*   	seen_refsnsrefrP  s         r4   visit_AssignzCodeGenerator.visit_Assign.  s    !!# !$	]]5;;/ 	EzzY& MM%**%--##EJJ/CNN/uMBCKKMNNF LLN	  	T

4;;&

5

499e$  'r6   c                 v   | j                          |j                         }d|_        |j                  j	                  |       | j                  |       | j                  |       | j                  |j                  |       | j                  |       | j                  |j                  |       | j                  d       |j                  | j                  |j                  |       n| j                  d|j                   d       | j                  d       | j                  |       | j!                  |       y )NFz9 = (Markup if context.eval_ctx.autoescape else identity)(concat(rA   )r  r   r   r   rN  r;  r   r  rQ  r  r2   r8  rE   r	  r   r  r>  )r'   r)   r*   r   s       r4   visit_AssignBlockzCodeGenerator.visit_AssignBlockM  s    !!#kkm ,1(((.%K 		;/T

4;;&

NO;;"dkk;7JJ!3!3 4A67

3  '%r6   c           	         |j                   dk(  rX|j                  s|j                  s|j                  r4| j                  r(| j                  d   j                  |j                         |j                  j                  |j                        }|j                   dk(  r`|j                  j                  |      }||d   t        k(  r| j                  |      r&| j                  d|j                  d| d| d       y | j                  |       y )	Nr  r*  r   r   z(undefined(name=z) if z is missing else rA   )r   r   r   r   r   r   rR   r   rP  	find_loadr   r  rE   )r'   r)   r*   rP  r   s        r4   r   zCodeGenerator.visit_Namee  s    88wNNe..%2C2C!!""2&**4995mm		*
 88v==**3/D G1144S9

&tyym5=NseSTU 

3r6   c                     |j                   j                  |j                        }| j                  | d|j                  d       y )Nr'  r(  )r   rP  rR   r   attr)r'   r)   r*   rP  s       r4   visit_NSRefzCodeGenerator.visit_NSRef~  s9    
 mm		*#a		}A./r6   c                     |j                  |j                        }t        |t              r| j	                  t        |             y | j	                  t        |             y r.   )r.  r0   rX   ro   rE   rr   ra  )r'   r)   r*   r;  s       r4   visit_ConstzCodeGenerator.visit_Const  s>    mmENN+c5!JJs3x JJtCy!r6   c                     	 | j                  t        |j                  |j                                     y # t        j
                  $ r" | j                  d|j                  d       Y y w xY wNz6(Markup if context.eval_ctx.autoescape else identity)(rA   )rE   ra  r.  r0   r   r7  datar  s      r4   visit_TemplateDataz CodeGenerator.visit_TemplateData  sW    	JJtDMM%..9:; 	JJHUVW	s   36 2A+*A+c                     | j                  d       d}t        |j                        D ]*  \  }}|r| j                  d       | j                  ||       , | j                  |dk(  rd       y d       y )Nr?   r*  r>   r   z,)rA   rE   rO  ry   r2   r'   r)   r*   r\  r:  s        r4   visit_TuplezCodeGenerator.visit_Tuple  sd    

3"4::. 	$IC

4 JJtU#	$ 	

3!84--r6   c                     | j                  d       t        |j                        D ]*  \  }}|r| j                  d       | j                  ||       , | j                  d       y )Nr'  r>   r(  rQ  rR  s        r4   
visit_ListzCodeGenerator.visit_List  sS    

3"4::. 	$IC

4 JJtU#	$ 	

3r6   c                 :   | j                  d       t        |j                        D ]a  \  }}|r| j                  d       | j                  |j                  |       | j                  d       | j                  |j
                  |       c | j                  d       y )Nrm  r>   r  r  )rE   rO  ry   r2   r  r_   rR  s        r4   
visit_DictzCodeGenerator.visit_Dict  su    

3"4::. 	*IC

4 JJtxx'JJtJJtzz5)	* 	

3r6   +-*/z//z**%andorznot c                    |j                   j                  rd}n|j                   j                  rd}nd}| j                  | d       |j                  D ]%  }| j                  ||       | j                  d       ' | j                  d       y )Nz8(markup_join if context.eval_ctx.volatile else str_join)markup_joinstr_joinz((r>   r   )r0   r1   r   rE   r   r2   )r'   r)   r*   r  r"  s        r4   visit_ConcatzCodeGenerator.visit_Concat  sy    >>""RI^^&&%I"I

i[#$:: 	CJJsE"JJt	 	

4r6   c                     | j                  d       | j                  |j                  |       |j                  D ]  }| j                  ||        | j                  d       y )Nr?   rA   )rE   r2   r  opsrH   s       r4   visit_ComparezCodeGenerator.visit_Compare  sK    

3

499e$(( 	"BJJr5!	"

3r6   c                     | j                  dt        |j                      d       | j                  |j                  |       y )Nr@   )rE   	operatorsr;   r2   r  r  s      r4   visit_OperandzCodeGenerator.visit_Operand  s3    

Qy)*!,-

499e$r6   c                 :   | j                   j                  r| j                  d       | j                  d       | j                  |j                  |       | j                  d|j
                  d       | j                   j                  r| j                  d       y y )N(await auto_await(zenvironment.getattr(r>   rA   r   )rB   rB  rE   r2   r)   rH  r  s      r4   visit_GetattrzCodeGenerator.visit_Getattr  sv    $$JJ+,

)*

499e$

R		}A&'$$JJt %r6   c                 v   t        |j                  t        j                        r[| j	                  |j
                  |       | j                  d       | j	                  |j                  |       | j                  d       y | j                  j                  r| j                  d       | j                  d       | j	                  |j
                  |       | j                  d       | j	                  |j                  |       | j                  d       | j                  j                  r| j                  d       y y )Nr'  r(  rj  zenvironment.getitem(r>   rA   r   )	rX   r"  r   Slicer2   r)   rE   rB   rB  r  s      r4   visit_GetitemzCodeGenerator.visit_Getitem  s     dhh,JJtyy%(JJsOJJtxx'JJsO((

/0JJ-.JJtyy%(JJtJJtxx'JJsO((

4  )r6   c                 :   |j                   | j                  |j                   |       | j                  d       |j                  | j                  |j                  |       |j                  .| j                  d       | j                  |j                  |       y y )Nr  )startr2   rE   stopr   r  s      r4   visit_SlicezCodeGenerator.visit_Slice  sq    ::!JJtzz5)

399 JJtyy%(99 JJsOJJtyy%( !r6   	is_filterc              #     K   | j                   j                  r| j                  d       |r[| j                  | j                  |j                      d       | j                   j                  j                  |j                        }nZ| j                  | j                  |j                      d       | j                   j                  j                  |j                        }|?|j                  s3|rdnd}| j                  d| d|j                  d|j                         t        j                  dt        j                  d	t        j                   d
ij                  t        j                  |            }|| j                  | d       d  | j                  ||       | j                  d       | j                   j                  r| j                  d       y y w)Nrj  r?   r	  r  zNo r+  r  r   r   rB   r>   rA   r   )rB   rB  rE   r   rR   r&  r   r   r   r   r   r   r%  r'  r$  )r'   r)   r*   rs  rE  	type_namer(  s          r4   _filter_test_commonz!CodeGenerator._filter_test_common  s     $$JJ+,JJ$,,tyy12!45##++//		:DJJ$**TYY/023##))--dii8D
 < 0 0$-6IIII;gdii]!<dkkJ i!!#5  -
 #d#
	 	 JJ(2' 	tU#

3$$JJt %s   GGc                    | j                  ||d      5  |j                  | j                  |j                  |       n|j                  j                  r-| j                  d|j                   d|j                   d       nU|j                  j                  r | j                  d|j                   d       n| j                  d|j                   d       d d d        y # 1 sw Y   y xY w)NTz(Markup(concat(z.)) if context.eval_ctx.autoescape else concat(r   zMarkup(concat(rC  rA   )rv  r)   r2   r0   r1   rE   r   r   r  s      r4   r   zCodeGenerator.visit_Filter,  s    %%dE48 	6 yy$

499e,((

%ell^ 4CCH<<.PRT **

^ELL><=

WU\\N!45	6 	6 	6s   CCC(c                     | j                  ||d      5  | j                  |j                  |       d d d        y # 1 sw Y   y xY wr   )rv  r2   r)   r  s      r4   r   zCodeGenerator.visit_Test=  s;    %%dE59 	)JJtyy%(	) 	) 	)s	   :Ac                 @    j                         d fd} j                  d        j                  j                          j                  d        j                  j                          j                  d        |         j                  d       y )Nc                      j                   j                  j                           y j                  dj                         d       y )Nz1cond_expr_undefined("the inline if-expression on z6 evaluated to false and no else section was defined."))expr2r2   rE   rh  )r*   r)   r'   s   r4   write_expr2z1CodeGenerator.visit_CondExpr.<locals>.write_expr2F  sL    zz%

4::u-JJMM$'( )*+r6   r?   z if z else rA   r   )r   rE   r2   expr1r  )r'   r)   r*   r|  s   ``` r4   visit_CondExprzCodeGenerator.visit_CondExprB  sl    

		 	

3

4::u%

6

499e$

8

3r6   r  c                 8   | j                   j                  r| j                  d       | j                   j                  r| j                  d       n| j                  d       | j	                  |j
                  |       |rddind }|j                  rddini }|j                  rddini }|r |j                  |fi | n|s|rt        |fi |}| j                  |||       | j                  d       | j                   j                  r| j                  d       y y )	Nrj  zenvironment.call(context, zcontext.call(rG  
_loop_vars_block_varsrA   r   )rB   rB  rE   rC   r2   r)   r   r   r   rx   r$  )r'   r)   r*   r  r  loop_kwargsblock_kwargss          r4   r  zCodeGenerator.visit_CallY  s     $$JJ+,%%JJ34JJ'

499e$/=(+46;6F6F|\2B9>9J9J}5PRL<|<L<|<LtUL1

3$$JJt %r6   c                 x    | j                  |j                  dz          | j                  |j                  |       y )Nr  )rE   r  r2   r_   r  s      r4   visit_KeywordzCodeGenerator.visit_Keywordp  s(    

488c>"

4::u%r6   c                     | j                  d       | j                  |j                  |       | j                  d       y )NzMarkup(rA   rE   r2   r  r  s      r4   visit_MarkSafezCodeGenerator.visit_MarkSafev  s+    

9

499e$

3r6   c                     | j                  d       | j                  |j                  |       | j                  d       y rM  r  r  s      r4   visit_MarkSafeIfAutoescapez(CodeGenerator.visit_MarkSafeIfAutoescape{  s.     	

KL

499e$

3r6   c                 @    | j                  d|j                  z          y )Nzenvironment.rE   rR   r  s      r4   visit_EnvironmentAttributez(CodeGenerator.visit_EnvironmentAttribute  s     	

>DII-.r6   c                 Z    | j                  d|j                  d|j                          y )Nzenvironment.extensions[z].)rE   
identifierrR   r  s      r4   visit_ExtensionAttributez&CodeGenerator.visit_ExtensionAttribute  s'     	

,T__,?r$))MNr6   c                 T    | j                  | j                  |j                            y r.   )rE   r   r  r  s      r4   visit_ImportedNamez CodeGenerator.visit_ImportedName  s    

4&&t78r6   c                 :    | j                  |j                         y r.   r  r  s      r4   visit_InternalNamez CodeGenerator.visit_InternalName  s    

499r6   c                 &    | j                  d       y )Nr   )rE   r  s      r4   visit_ContextReferencez$CodeGenerator.visit_ContextReference  s     	

9r6   c                 D    | j                  | j                  |             y r.   )rE   r  r  s      r4   visit_DerivedContextReferencez+CodeGenerator.visit_DerivedContextReference  s     	

4&&u-.r6   c                 (    | j                  d|       y )Ncontinuerr  r  s      r4   visit_ContinuezCodeGenerator.visit_Continue  s    z4(r6   c                 (    | j                  d|       y )Nbreakrr  r  s      r4   visit_BreakzCodeGenerator.visit_Break  s    w%r6   c                     |j                         }|j                  j                  |       | j                  |       | j	                  |j
                  |       | j                  |       y r.   )r   r   rN  r;  r  rQ  r>  )r'   r)   r*   scope_frames       r4   visit_ScopezCodeGenerator.visit_Scope  sO    kkm((.%		;/%r6   c                    | j                         }| j                  | d| j                  |              | j                  | d       | j                  |j                  |       | j                  |       |j                  d      }|j                  j                  |       | j                  |       | j                  |j                  |       | j                  |       | j                          y )Nr1  z.vars = T)r   )r   r   r  r2   r   r{  r   r   rN  r;  r  rQ  r>  r}  )r'   r)   r*   r   r  s        r4   visit_OverlayScopez CodeGenerator.visit_OverlayScope  s    '')#c$"5"5e"<!=>?#h'(

4<<'##C(kk4k0((.%		;/%""$r6   c                 ~   |j                   D ]  }| j                  d|j                   d       | j                  |j                  |       	 |j                  j                  |j                        }t        |j                  |j                  |        y # t        j                  $ r d|j                  _
        Y w xY w)Nzcontext.eval_ctx.r1  T)optionsr   r  r2   r_   r.  r0   setattrr   r7  r1   )r'   r)   r*   keywordr;  s        r4   visit_EvalContextModifierz'CodeGenerator.visit_EvalContextModifier  s     || 	:GNN.w{{m3?@JJw}}e,:mm,,U^^< S9	:
 ## /*.'/s   %B$B<;B<c                 J   | j                         }|j                  j                         }| j                  | d       | j	                  ||       |j
                  D ]  }| j                  ||        |j                  j                  |       | j                  d| d       y )Nz = context.eval_ctx.save()zcontext.eval_ctx.revert(rA   )r   r0   saver   r  rQ  r2   revert)r'   r)   r*   old_ctx_name	saved_ctxr9  s         r4   visit_ScopedEvalContextModifierz-CodeGenerator.visit_ScopedEvalContextModifier  s     002NN'')	,'ABC&&tU3YY 	%EJJue$	%i(1,qABr6   NFTr   r   )r
   r.   )Nr   )zasync r  )r   r   r   r8   r   rr   TextIOrm   r   propertyrV   rn   r   r   r+   r   r   r   r   r   Noder   r  r  r   r  rE   r   r  r   Callr   r   Mappingr9   r$  r/  r;  r>  rC  rE  r   r   r  r   r^  re  rh  rp  rs  rV  rX  rW  r{  r}  r  r4  r  r  r  r  rY   r  r   r   r  r  Includer  Import
FromImportr  r  r  Forr  Ifr  r  r  FilterBlockr  Withr  ExprStmtr  
NamedTupler  staticmethodr  r  r  r)  r,  r7   r0  r3  r5  Outputr<  AssignrA  AssignBlockrD  r   r   r>  rI  r  rK  r/  rO  rS  r  rU  DictrW  rL   	visit_Add	visit_Sub	visit_Mul	visit_Divvisit_FloorDiv	visit_Pow	visit_Mod	visit_Andvisit_OrrQ   	visit_Pos	visit_Neg	visit_Notr:   Concatrb  Comparere  Operandrh  Getattrrk  Getitemrn  rm  rr  r   Iteratorrv  r   r   CondExprr~  r  Keywordr  MarkSafer  MarkSafeIfAutoescaper  EnvironmentAttributer  ExtensionAttributer  r  r  InternalNamer  ContextReferencer  DerivedContextReferencer  Continuer  Breakr  Scoper  OverlayScoper  EvalContextModifierr  ScopedEvalContextModifierr  r   r6   r4   r(   r(   ,  s    (, G4"G4 jjoG4 **S/	G4
 

188$G4 G4 G4 
G4R *4 * *
L LS L] L,c ,
/E /d / 5:99-19	9("C " "< <ajj.D <PT <u   DH"*+**UZZ*@		

5:: 6 	u 	 	s t  IJJJuzz2BE	*AJJuzz2 *# *d * ;?	7/ggejj%,,

:;7/ 7/ jj3:!67	7/
 
7/r,qzz%**'= ,$ ,\> >4 > B B4 BD BH HC HQT H2 2 2Q GGEKK89Q BGQ 	
	!Q f

8 

E 

d 

UZZ C ! !# !+I I$ I$6C 6D 65S 5T 5,1 1## #UE Uc U3c 3d 3))O )O4 )O\ @Dx9NNx9+,::e+<x9	x9t/ /E /d /b(!%-- (! (!$ (!T8%-- 8 8$ 8tUGGELL%*:*::;UDIU	U	N 	Ne 	N 	N5U%5%5 5e 5 5nIPeii IP IP$ IPVUXX e  */ /E /d /EOO E d 	'e&7&7 	' 	'$ 	'
%uzz 
%% 
%D 
%%5>> %% %D %   155   ,0Iqzz-(/. .`#

155(9 #c #%JJ%',%8E%	%*%JJ%',%8E%	% 	JJ	',	8E			M Me M M^( (e ( (>&e&7&7 & &$ &0uzz % D 20 0E 0d 0" "E "d "u'9'9 % D . .E .d .uzz % D uzz % D  C IC IC IC I &ND!IC IE"I4 H3I3I6"I e    %--  $  %%-- % %$ % 	%-- 	 	$ 	 	 !%-- ! !$ ! !() )E )d ) 'GGELL%**45'>C'PT'	
D	' 'R 6 6e 6 6 6  )uzz )% )D ) ) 5>> % D  , EJJJ',>B	 ,&%-- & &$ &5>> % D 
..7<	/../7</	/
O,,O5:O	O
9u'9'9 9% 9D 9u'9'9 % D **38	
/11/:?/	/
)5>> )% )D )& &E &d && &E &d &%u'9'9 %% %D %:--:6;:	:
C33
C<A
C	
Cr6   r  )Fr   typingr8   
contextlibr   	functoolsr   ior   	itertoolsr   r  r   r  
markupsafer   r	   r  r   
exceptionsr   
idtrackingr   r   r   r   r   r   r/   r   utilsr   r   rI   r   TYPE_CHECKINGtyping_extensionsterB   r   TypeVarr  r9   r   rg  r:   rr   rJ   rL   rP   rQ   rY   r   r  rm   r^   rc   r   r  Setr   r   r+   RuntimeErrorr~   r   r}   r8  r   r(   r   r6   r4   <module>r     s2   6  % $   2    .  & * ( *       ??"(AIIcCJ/0 



		'Q '1 ' C AJJ'PRV'VW *ZZ%//7;TAB0 $(
.. **S/ jjo	
 JJqxx    ZZ_0 4 "::ejj!*+**S/UU3Z& &P PfJ, J'k '&&K &,9 bCK bCr6   