
     fO                       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j#        r
ddl$Z%d
dl&m'Z'  ej(        dej)        dej*        f                   Z+dddddd d!d"d#Z,d$e+d%e+fd&Z-d'e.d%ej)        d(ej/        d)gdf         fd*Z0d'e.d%ej)        d(ej1        d)gdf         fd+Z2	 	 	 dHd.ej3        d/d0d1ej4        e.         d2ej4        e.         d3ej4        ej5                 d4e6d5e6d%ej4        e.         fd6Z7d7ej*        d%e6fd8Z8d9ej9        ej:                 d:ej9        e.         d%ej;        e.         fd;Z< G d< d=          Z= G d> d)          Z> G d? d@e?          Z@ G dA dBe"          ZA G dC dDe"          ZB G dE dFeC          ZD G dG d(e"          ZEdS )Iz0Compiles 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	          t          j        t          |                     S )	NselfCodeGeneratornodeframeFramekwargsr%   c                     | j         H|j        j        s<| j                             ||j                  }||k    r|                     ||          S  | ||fi |S N)	optimizereval_ctxvolatilevisit)r'   r)   r*   r,   new_noder$   s        R/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/jinja2/compiler.pynew_funczoptimizeconst.<locals>.new_func.   sk     >%en.E%~++D%.AAH4zz(E222qtU--f---    )r   ExprtAnyr   castr   )r$   r5   s   ` r4   optimizeconstr;   -   sm    
.
.%*Z
.8?
.KL5
.	

. 
. 
. 
. 
. 
. !&H--q111r6   opr(   r+   c           	      \     t           dddt          j        dt          dd f fd            }|S )Nr'   r(   r)   r*   r%   c                    | j         j        rs| j         j        v re|                     dd           |                     |j        |           |                     d           |                     |j        |           nd|                     d           |                     |j        |           |                     d d           |                     |j        |           |                     d           d S )Nz environment.call_binop(context, , ( ))environment	sandboxedintercepted_binopswriter2   leftrightr'   r)   r*   r<   s      r4   visitorz_make_binop.<locals>.visitor>   s     &	*+-1A1T+T+TJJB"BBBCCCJJty%(((JJtJJtz5))))JJsOOOJJty%(((JJy2yyy!!!JJtz5)))

3r6   )r;   r   BinExprr+   r<   rJ   s   ` r4   _make_binoprM   =   sP    o U] 5 T      ]  Nr6   c           	      \     t           dddt          j        dt          dd f fd            }|S )Nr'   r(   r)   r*   r%   c                 6   | j         j        rC| j         j        v r5|                     dd           |                     |j        |           n3|                     dz              |                     |j        |           |                     d           d S )Nzenvironment.call_unop(context, r?   r@   rB   )rC   rD   intercepted_unopsrF   r2   r)   rI   s      r4   rJ   z_make_unop.<locals>.visitorU   s     &	)+-1A1S+S+SJJAAAABBBJJty%((((JJsRx   JJty%(((

3r6   )r;   r   	UnaryExprr+   rL   s   ` r4   
_make_unoprR   R   sR     
o 
U_ 
U 
t 
 
 
 
 
 ]
 Nr6   FTr)   rC   r   namefilenamestream
defer_init	optimizedc                     t          | t          j                  st          d          |                    ||||||          }|                    |            ||j                                        S dS )z+Generate the python source for a node tree.z Can't compile non template nodesN)
isinstancer   Template	TypeErrorcode_generator_classr2   rU   getvalue)r)   rC   rS   rT   rU   rV   rW   	generators           r4   generater_   e   s|     dEN++ <:;;;00T8VZ I OOD~((***4r6   valuec                    | | t           u s	| t          u rdS t          |           t          t          t
          t          t          t          t          hv rdS t          |           t          t          t          t          hv rt          d | D                       S t          |           t          u r+t          d |                                 D                       S dS )z)Does the node have a safe representation?NTc              3   4   K   | ]}t          |          V  d S r.   has_safe_repr).0vs     r4   	<genexpr>z has_safe_repr.<locals>.<genexpr>   s*      33=##333333r6   c              3   X   K   | ]%\  }}t          |          ot          |          V  &d S r.   rc   re   krf   s      r4   rg   z has_safe_repr.<locals>.<genexpr>   s;      SSTQ=##8a(8(8SSSSSSr6   F)NotImplementedEllipsistypeboolintfloatcomplexrangestrr	   tuplelistset	frozensetalldictitemsr`   s    r4   rd   rd   }   s    }//5H3D3DtE{{tS%%fEEEtE{{udC33333U333333E{{dSSU[[]]SSSSSS5r6   r   namesc                     t          |          }	 | D ]}|                    |           n# t          $ r Y nw xY w|j        S )zCheck if the names passed are accessed undeclared.  The return value
    is a set of all the undeclared names from the sequence of names found.
    )UndeclaredNameVisitorr2   VisitorExit
undeclared)r   r|   rJ   r)   s       r4   find_undeclaredr      sh     $E**G 	  	 DMM$	    s   , 
99c                   L    e Zd Zdej        ej        ej        f         ddfdZdS )MacroRefr)   r%   Nc                 >    || _         d| _        d| _        d| _        d S 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      sF        &QWU[%/%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dS )r+   z&Holds compile time information for us.Nr0   parentlevelr%   c                 @   || _         || _        |+t          |          | _        d| _        d | _        d | _        n?t          |j        |          | _        |j        | _        |j        | _        |j        | _        d| _        d| _        d| _	        d| _
        d| _        d S )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 +/DJJ #6>???DL(.(CD% -DKDJ 
    
  r6   c                     t                               | 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   sG    ^^DN++
4=)))\&&((
	r6   Fisolatedc                 v    |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   s<     	Fdl.@1.DEEEET]D)))r6   c                 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%   r+   F)r   r   r   __doc__r   r8   Optionalro   r   r   rn   r   r   __copy__r   r6   r4   r+   r+      s        00
 '+!%	1  1 1  
7#1  z#	1 
 
1  1  1  1 f   * *d *w * * * *    HHHr6   c                       e Zd ZdZdS )r   z?Exception used by the `UndeclaredNameVisitor` to signal a stop.Nr   r   r   r   r   r6   r4   r   r      s        IIIIr6   r   c                   h    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dS )
DependencyFinderVisitorz.A visitor that collects filter and test calls.r%   Nc                 R    t                      | _        t                      | _        d S r.   )rv   filterstestsr'   s    r4   r   z DependencyFinderVisitor.__init__   s    #&55!$


r6   r)   c                 n    |                      |           | j                            |j                   d S r.   )generic_visitr   addrS   r   s     r4   visit_Filterz$DependencyFinderVisitor.visit_Filter  s4    4   #####r6   c                 n    |                      |           | j                            |j                   d S r.   )r   r   r   rS   r   s     r4   
visit_Testz"DependencyFinderVisitor.visit_Test  s2    4   
ty!!!!!r6   c                     dS )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      s        88' ' ' '$ $$ $ $ $ $"uz "d " " " "' ' ' ' ' ' ' 'r6   r   c                   l    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dS )	r~   zA visitor that checks if a name is accessed without being
    declared.  This is different from the frame visitor as it will
    not stop at closure frames.
    r|   r%   Nc                 T    t          |          | _        t                      | _        d S r.   )rv   r|   r   )r'   r|   s     r4   r   zUndeclaredNameVisitor.__init__  s    ZZ
&)eer6   r)   c                     |j         dk    rM|j        | j        v r?| j                            |j                   | j        | j        k    rt                      d S | j                            |j                   d S )Nload)ctxrS   r|   r   r   r   discardr   s     r4   
visit_Namez UndeclaredNameVisitor.visit_Name  sv    8v$)tz"9"9O	***$*,,!mm# -, Jty)))))r6   c                     dS )zStop visiting a blocks.Nr   r   s     r4   r   z!UndeclaredNameVisitor.visit_Block!  r   r6   )r   r   r   r   r8   Iterablers   r   r   Namer   r   r   r   r6   r4   r~   r~     s         
,ajo ,$ , , , ,*uz *d * * * *& & & & & & & &r6   r~   c                       e Zd ZdZdS )CompilerExitzRaised if the compiler encountered a situation where it just
    doesn't make sense to further process the code.  Any block that
    raises such an exception is not further processed.
    Nr   r   r6   r4   r   r   %  s           r6   r   c                      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j        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j!        eej"        f                  ddfd)Z#d ej        ej                 ddfd*Z$deddfd+Z%dded,eddfd-Z&dd0ed1edefd2Z'dedefd3Z(dej        ej)        ej*        f         dedej+        ee,f         fd4Z-d5e,deddfd6Z.dej        defd7Z/dedefd8Z0dd9Z1deddfd:Z2dd;Z3d<eddfd=Z4d<eddfd>Z5dd?Z6defd@Z7defdAZ8dedefdBZ9d<edefdCZ:ddDZ;deddfdEZ<	 ddej=        dej        e         ddfdFZ>dej?        deddfdGZ@dejA        deddfdHZBdejC        deddfdIZDdej        ejE        ejF        f         deddfdJZGdejE        deddfdKZHdejF        deddfdLZIdejJ        deddfdMZKdejL        deddfdNZMdej)        deddfdOZNdej*        deddfdPZOdejP        deddfdQZQdejR        deddfdRZSdejT        deddfdSZU G dT dUejV                  ZWeXdVej"        dej"        fdW            ZYdZZej        eW         e[dX<   deWfdYZ\dZej        ej"                 defd[Z]dej^        ded\eWdefd]Z_dej^        ded\eWddfd^Z`dej^        ded\eWddfd_Zadejb        deddfd`Zcdejd        deddfdaZedejf        deddfdbZgdejh        deddfdcZidejj        deddfddZkdejl        deddfdeZmdejn        deddfdfZodej+        deddfdgZpdejq        deddfdhZrdejs        deddfdiZt eudj          Zv eudk          Zw eudl          Zx eudm          Zy eudn          Zz eudo          Z{ eudp          Z| eudq          Z} eudr          Z~ edj          Z edk          Z eds          Zedej        deddfdt            Zedej        deddfdu            Zd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            Zdej        deddfdyZedej        ej        ej         f         dedzedej        d         fd{            Zedej        deddfd|            Zedej         deddfd}            Zedej        deddfd~            Ze	 ddej        de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j        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j        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j        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j        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j        deddfdZdS )r(   NFTrC   r   rS   rT   rU   rV   rW   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| _        d S )NFr   r
   Tcontext)r   rC   rS   rT   rU   created_block_contextrV   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'   rC   rS   rT   rU   rV   rW   s          r4   r   zCodeGenerator.__init__-  s    >ZZF&	 %*"$04 	4&{33DN 13 13  
 "'  (*
)+ 6826   ! !"  24 57 *3%%%r6   c                     | j         d uS r.   )r/   r   s    r4   rW   zCodeGenerator.optimizedv  s    ~T))r6   msglinenozte.NoReturnc                 :    t          ||| j        | j                  )z*Fail with a :exc:`TemplateAssertionError`.)r   rS   rT   )r'   r   r   s      r4   failzCodeGenerator.fail|  s    $S&$)T]KKKr6   c                 6    | 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                 r    |                                  |_        |                     |j         d           dS )z7Enable buffering for the frame from that point onwards.z = []N)r   r   	writeliner'   r*   s     r4   r   zCodeGenerator.buffer  s8    0022%,---.....r6   force_unescapedc                 &   |s|j         j        r|                     d           |                                  |                     d|j         d           |                                  |                     d           |                                  |                     d|j         d           |                                  dS |j         j        r |                     d|j         d           dS |                     d|j         d           dS )z(Return the buffer contents of the frame.zif context.eval_ctx.autoescape:zreturn Markup(concat())else:zreturn concat(rB   N)r0   r1   r   indentr   outdent
autoescape)r'   r*   r   s      r4   return_buffer_contentsz$CodeGenerator.return_buffer_contents  s     	~& @AAAGu|GGGHHHw'''????@@@* Gu|GGGHHH777788888r6   c                 &    | xj         dz  c_         dS )zIndent by one.r
   Nr   r   s    r4   r   zCodeGenerator.indent  s    Qr6   r
   stepc                 &    | xj         |z  c_         dS )zOutdent by step.Nr   )r'   r   s     r4   r   zCodeGenerator.outdent  s    T!r6   r)   c                     |j         |                     d|           dS |                     |j          d|           dS )z%Yield or write into the frame buffer.Nyield .append()r   r   )r'   r*   r)   s      r4   start_writezCodeGenerator.start_write  sI    <NN8T*****NNel444d;;;;;r6   c                 B    |j         |                     d           dS dS )z1End the writing process started by `start_write`.NrB   )r   rF   r   s     r4   	end_writezCodeGenerator.end_write  s%    <#JJsOOOOO $#r6   sc                     |                      ||           |                     |           |                     |           dS )z4Simple shortcut for start_write + write + end_write.N)r   rF   r  )r'   r  r*   r)   s       r4   simple_writezCodeGenerator.simple_write  sA     	%%%

1ur6   r   c                     	 |                      d           |D ]}|                     ||           dS # t          $ r Y dS 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  sk    	NN6""" ( (

4''''( ( 	 	 	DD	s   04 
AAxc                    | j         r| j        sk| j                            d| j         z             | xj        | j         z  c_        | j        -| j                            | j        | j        f           d| _        d| _        | j                            d| j        z             d| _         | j                            |           dS )z&Write a string into the output stream.
NFz    r   )	r   r   rU   rF   r   r   r   appendr   )r'   r	  s     r4   rF   zCodeGenerator.write  s    ? 		 $ 2!!$"8999  DO3  )5O**D,BDDT+UVVV-1D* %DKft'88999DO!r6   r   extrac                 \    |                      ||           |                     |           dS )z!Combination of newline and write.N)newlinerF   )r'   r	  r)   r  s       r4   r   zCodeGenerator.writeline  s+     	T5!!!

1r6   c                     t          | j        d|z             | _        |*|j        | j        k    r|j        | _        |j        | _        dS dS dS )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  sR    doq5y99t > >%)[D""kDOOO  > >r6   extra_kwargsc                    t          d t          d |j        D             |pd          D                       }|j        D ]-}|                     d           |                     ||           .|sl|j        D ]-}|                     d           |                     ||           .|5|                                D ] \  }}|                     d| d|            !|j        r0|                     d           |                     |j        |           |r%|j        |                     d           n|                     d	           |j        D ]O}|                     |j	        d
           |                     |j
        |           |                     d           P|5|                                D ] \  }}|                     |d
| d           !|j        G|                     d           |                     |j        |           |                     d           dS |                     d           dS |j        2|                     d           |                     |j        |           dS dS )a+  Writes a function call to the stream for the current node.
        A leading comma is added automatically.  The extra keyword
        arguments may not include python keywords otherwise a syntax
        error could occur.  The extra keyword arguments should be given
        as python dict.
        c              3   d   K   | ]+}t          t          j        t          |                    V  ,d S r.   )is_python_keywordr8   r:   rs   )re   rj   s     r4   rg   z*CodeGenerator.signature.<locals>.<genexpr>  sH       
 
 afS!nn--
 
 
 
 
 
r6   c              3   $   K   | ]}|j         V  d S r.   )keyre   r	  s     r4   rg   z*CodeGenerator.signature.<locals>.<genexpr>  s$      77aAE777777r6   r   r?   N=z, *z
, **dict({z, **{: z}, **rB   }z, **)anyr   r,   argsrF   r2   rz   dyn_args
dyn_kwargsr  r`   )	r'   r)   r*   r  kwarg_workaroundargkwargr  r`   s	            r4   	signaturezCodeGenerator.signature  s     
 
774;7779KLL
 
 
 
 

 9 	# 	#CJJtJJsE"""" 	3 ) )

4   

5%(((('"."4"4"6"6 3 3JCJJ1C11%112222= 	-JJuJJt}e,,, 	/*

<((((

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

ei---...

5;...

4    '"."4"4"6"6 6 6JCJJ#4454445555*

7###

4?E222

3

3_(JJvJJt..... )(r6   c           
      >   t                      }|D ]}|                    |           | j        |j        df| j        |j        dffD ]T\  }}}t	          |          D ]<}||vr|                                 ||<   |                     d           |                                  |                     ||          d| d|d           |                                  |                     d           |                                  |                     d           |                     d	||          d
           |                                  |                     d|dd          d|d           |                                  |                                  >VdS )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   rJ   r)   id_mapr|   
dependencyrS   s           r4   pull_dependencieszCodeGenerator.pull_dependencies  s    *++ 	  	 DMM$ \7?I6
*
 	 	%FE: u  v%%#'#<#<#>#>F4L v&&&&,UUzUUDUUUVVV1222///>fTl>>>???0j"o 0 0"0 0 0   )	 	r6   c           	         g }|j         j                                        D ]\  }\  }}|t          k    r|t          k    r1|                     | d|                                  d|d           P|t          k    r|                     | d|            v|t          k    r|	                    |           t          d          |r-|                     d                    |           d           d S d S )N = r@   rB   zunknown load instruction
 = missing)r   loadsrz   r   r   r   get_resolve_funcr   r   r  NotImplementedErrorjoin)r'   r*   undefstargetactionparams         r4   enter_framezCodeGenerator.enter_frameH  s$   ',}':'@'@'B'B 
	F 
	F#FOVU++++++&QQT-B-B-D-DQQuQQQRRRR>))&44U445555---f%%%%)*DEEE 	>NNejj00<<<=====	> 	>r6   with_python_scopec                     |sUg }|j         j        D ]}|                    |           |r/|                     d                    |           d           d S d S d S )Nr0  r1  )r   r2  r  r   r5  )r'   r*   r;  r6  r7  s        r4   leave_framezCodeGenerator.leave_frameX  s      	BF-- & &f%%%% B%**V"4"4@@@AAAAA	B 	BB Br6   async  async_value
sync_valuec                 "    | j         j        r|n|S r.   )rC   is_async)r'   r@  rA  s      r4   choose_asynczCodeGenerator.choose_async`  s    ".7G{{ZGr6   c                 4    |                                   d| S )Nr(  )rD  )r'   rS   s     r4   funczCodeGenerator.funcc  s"    ##%%114111r6   c           
      P   |                                 }|j                            |           t          |          }d}t	                      }g }t          |j                  D ]g\  }}|j        dk    r|}|j        dv r|                    |j                   |	                    |j        
                    |j                             ht          |j        d          }	d|	v r|O	 |j        |t          |j                  z
            nX# t          $ r |                     d|j                   Y n1w xY w|	                    |j                            d                     d|_        d|	v r8d|vr4|	                    |j                            d                     d|_        d|	v r8d|vr4|	                    |j                            d                     d|_        d	|_        |j                            |           |                     |                     d
           dd                    |           d|           |                                  |                     |           |                     |           |                     |           t          |j                  D ]\  }}|j        
                    |j                  }
|                     d|
 d           |                                  	 |j        |t          |j                  z
           }|                     |
 d           |                     ||           n8# t          $ r+ |                     |
 d|j        d|j        d           Y nw xY w|                     |
           |                                   | !                                 | "                    |j        |           | #                    |d           | $                    |d           |                                   ||fS )z/Dump the function def of a macro or call block.Ncaller)r,   varargs)rH  r,   rI  zhWhen defining macros or call blocks the special "caller" argument must be omitted or be given a default.Tr,   rI  Fmacror@   r?   ):if  is missing:r0  z = undefined("parameter z was not provided", name=rB   )r   r;  )%r   r   analyze_noder   rv   	enumerater  rS   r   r  refr   bodydefaultslen
IndexErrorr   r   declare_parameterr   r   r   r   r   rF  r5  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   rQ  defaults               r4   
macro_bodyzCodeGenerator.macro_bodyf  sM    ""4(((TNN	!ee!$),, 	5 	5HCx8##"%x000#''111KK))#(334444$TY0OPP
z!! *M/C	NN"BCCC!   II1 	     EM;;HEEFFF(,I%z!!h6I&I&IKK77AABBB(,I%
""y8K'K'KKK77	BBCCC)-I& &+"""4((($))G,,BBtyyBBBDIIIE''...!$),, 	 	HC-##CH--CNN2222333KKMMM	+-c$)nn(<= #{{{+++

7E****     + +CH + + X+ + +     &&s+++LLNNNN&&(((	5)))##E4#@@@$777is$   ("D %D32D3?"M2NNrZ  c                 0   d                     d |j        j        D                       }t          |j        dd          }t	          |j        j                  dk    r|dz  }|                     d|d| d	|j        d|j        d|j        d
           dS )z<Dump the macro definition for the def created by macro_body.r?   c              3   >   K   | ]}t          |j                  V  d S r.   )reprrS   r  s     r4   rg   z*CodeGenerator.macro_def.<locals>.<genexpr>  s*      HHqd16llHHHHHHr6   rS   Nr
   ,zMacro(environment, macro, z, (z), z, context.eval_ctx.autoescape))	r5  r)   r  getattrrT  rF   r   r   r   )r'   rZ  r*   	arg_tuplerS   s        r4   	macro_defzCodeGenerator.macro_def  s    IIHHIN4GHHHHH	y~vt44y~"##q((I

L L LI L L)L L/8/IL L)L L L	
 	
 	
 	
 	
r6   c                 @    d|j          }| j        | d| j        }|S )z.Return a human readable position for the node.zline N in )r   rS   )r'   r)   r   s      r4   positionzCodeGenerator.position  s3    "T[""9 ))DI))B	r6   c                     d                     d |j                                                                        D                       }d| dS )Nr?   c              3   *   K   | ]\  }}|d | V  dS r  Nr   )re   rS   r7  s      r4   rg   z3CodeGenerator.dump_local_context.<locals>.<genexpr>  sH       
 
f !!!!
 
 
 
 
 
r6   {r  )r5  r   dump_storesrz   )r'   r*   items_kvs      r4   dump_local_contextz CodeGenerator.dump_local_context  s^    99 
 
 % 9 9 ; ; A A C C
 
 
 
 
 !H    r6   c                     |                      d           |                      d           |                      d           |                      d           |                      d           dS )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  sk    
 	=>>>:;;;4555 	8999)*****r6   c                 h    | j                             |j                                                   dS )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   rW  z(CodeGenerator.push_parameter_definitions  s/     	$$U]%E%E%G%GHHHHHr6   c                 8    | j                                          dS )z+Pops the current parameter definitions set.N)r   popr   s    r4   rY  z'CodeGenerator.pop_parameter_definitions  s    !!#####r6   r7  c                 X    | j         r"| j         d                             |           dS dS )zMarks a parameter in the current parameter definitions as stored.
        This will skip the enforced undefined checks.
        r)  N)r   r   r'   r7  s     r4   rX  z#CodeGenerator.mark_parameter_stored  s;       	6!"%--f55555	6 	6r6   c                 :    | j                             |           d S r.   )r   r  ry  s     r4   push_context_referencez$CodeGenerator.push_context_reference  s    %,,V44444r6   c                 8    | j                                          d S 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dS | dS )Nr)  r   resolvez.resolver  ry  s     r4   r3  zCodeGenerator.get_resolve_func  s.    .r2Y9""""r6   c                 \    |                                   d|                     |           dS )Nz	.derived(rB   )r  rp  r   s     r4   derive_contextzCodeGenerator.derive_context  s3    &&((TT43J3J53Q3QTTTTr6   c                 2    | j         sdS || 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%    $ 	5.r222r6   c                 R    | j                             t                                 dS )z+Pushes a new layer for assignment tracking.N)r   r  rv   r   s    r4   push_assign_trackingz"CodeGenerator.push_assign_tracking  s#    !!#%%(((((r6   c                 z   | j                                         }|j        s|j        s|j        r|sdS d |D             }t          |          dk    rt          t          |                    }|j        	                    |          }|j        r| 
                    d|d|            dS |j        r| 
                    d|d|            dS | 
                    d|d|            n|j        r| 
                    d           n2|j        r| 
                    d	           n| 
                    d
           t          |          D ]P\  }}|r|                     d           |j        	                    |          }|                     |d|            Q|                     d           |j        s|j        s{|r{t          |          dk    r!| 
                    d|d         d           dS d                    t          t          |                    }| 
                    d| d           dS dS dS dS )zoPops the topmost level for assignment tracking and updates the
        context variables if necessary.
        Nc                 .    g | ]}|d d         dk    |S )Nr
   _r   r  s     r4   
<listcomp>z5CodeGenerator.pop_assign_tracking.<locals>.<listcomp>  s%    888a1RaR5C<<<<<r6   r
   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   rB   zcontext.exported_vars.update((r   )r   rw  r   r   r   rT  nextiterr   rQ  r   rP  rF   r5  maprb  )r'   r*   varspublic_namesrS   rQ  r]  	names_strs           r4   pop_assign_trackingz!CodeGenerator.pop_assign_tracking  s    !%%''!	$	 N	 		 F884888t99>>T

##D-##D))C >T>>>>???  ?d??#??@@@NN<4<<s<<==== 845555" 8566666777&t__ / /	T %JJt$$$m''--

d----....JJt  	O)9 	Ol 	O<  A%%PLOPPPQQQQQ IIc$&=&=>>	M	MMMNNNNN	O 	O 	O 	O 	O 	Or6   c           	         |
J d            t          | j        | j                  }ddlm} ddlm} | j        j        rt          ||z             }nt          |          }|                     dd	                    |          z              | j
        rdnd}|                    t          j                  d u}|                    t          j                  D ]C}	|	j        | j        v r$|                     d	|	j        d
|	j                   |	| j        |	j        <   D|                    t          j                  D ]}
|
j        | j        vr||
j        }|                                 x| j        |<   }d|v r8|                    dd          \  }}|                     d| d| d|            q|                     d| d|            |                     d| j                   |                     |                     d           d| dd           |                                  |                                  t7          |          }dt9          |j        d          v r2|j                            d          }|                     | d           |j                             |           dx|_!        |_"        |o| j#         |_$        |r|                     d           | %                    |           | &                    |j                   | '                    |j        |           | (                    |d           | )                                 |r| j#        s)|                                  |                     d           |                                  | j        j        s|                     d           nR|                     d           |                                  |                     d           | )                                 | )                    d| j#         z              | j        *                                D ]\  }}	|                     |                     d|z              d| d|	d           |                                  |                                  t7          |          }d|_+        t9          |	j        d           }d|v r2|j                            d          }|                     | d           d!|v r8|j                            d!          }|                     | d"|d#| d$           |j                             |	           ||_,        |                     d%           | %                    |           | &                    |	j                   | '                    |	j        |           | (                    |d           | )                                 d	                    d& | j        D                       }|                     d'| d(d           d)	                    d* | j-        D                       }|                     d+|           d S ),Nzno root frame allowedr
   )async_exported)exportedzfrom jinja2.runtime import r?   r?  z, environment=environmentzblock z defined twice.zfrom z import z as zimport zname = rootz(context, missing=missingrK  )r  r'   r   z = TemplateReference(context)Tzparent_template = NonerN  if parent_template is not None:z4yield from parent_template.root_render_func(context)z=async for event in parent_template.root_render_func(context):zyield eventblock_)r'   superr  z = context.super(z, block_rB   z_block_vars = {}c              3   $   K   | ]}|d | V  dS )z: block_Nr   r  s     r4   rg   z/CodeGenerator.visit_Template.<locals>.<genexpr>  s0      !K!K!Q"5"5!"5"5!K!K!K!K!K!Kr6   z
blocks = {r  &c              3   *   K   | ]\  }}| d | V  dS )r  Nr   ri   s      r4   rg   z/CodeGenerator.visit_Template.<locals>.<genexpr>  s0      GGtq!1

q

GGGGGGr6   zdebug_info = ).r   rC   rS   runtimer  r  rC  r+  r   r5  rV   findr   Extendsfind_allr   r   r   r   ImportedName
importnamer   r   rsplitrF  r   rs  r+   r   rR  r   rV  rO  r   r   r   r   r:  r.  r  r=  r   rz   r   r   r   )r'   r)   r*   r0   r  r  exported_namesenvenvhave_extendsr   import_impaliasmoduleobjrQ  rS   r   r   blocks_kv_strdebug_kv_strs                        r4   visit_TemplatezCodeGenerator.visit_Template=  s    }}5}}}t/;;++++++%%%%%%$ 	.#H~$=>>NN#H--N4tyy7P7PPQQQ G,G yy//t; ]]5;// 	, 	,EzT[((		?5:???NNN&+DK
## }}U%788 	? 	?G!)<<<(373L3L3N3NN#C(5#::"%**S!"4"4KFCNN#K6#K#K3#K#KE#K#KLLLLNN#=S#=#=e#=#=>>> 	.../// 	yy  EE6EEEQ 	 	
 	
 	
 	 h_TY	::::-11&99CNNc@@@AAA""4(((+//%1%P$:P6P" 	5NN3444ty)))	5)))$777  	;) B@AAAKKMMM#, UVVVVS   }---LL$"889:::  ;,,.. 	 	KD%NN99X_--RRRRR  
 KKMMM     //K&*K#(5FGGJ##!);;FCC#DDDEEE*$$!);;GDD#OOOOOOOPPP,,U333 $KNN-...[)))""5:...OOEJ444[DAAALLNNNN		!K!Kt{!K!K!KKK6]666a@@@xxGGtGGGGG7|7788888r6   c                 V   d}|j         rB| j        rdS | j        dk    r.|                     d           |                                  |dz  }|j        r|                     |          }n|                                 }|j        rf|                     d|j	        d|           |                                  |                     d|j	        d|           | 
                                 | j        j        s*|j        #|                     d	|j	        d
| d|           nt|                     |                                  d|j	        d
| d|           |                                  |                     d|           | 
                                 | 
                    |           dS )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](rB   zfor event in context.blocks[rK  event)r   r   r   r   r   scopedr  r  requiredrS   r   rC   rC  r   rD  r  )r'   r)   r*   r   r   s        r4   r   zCodeGenerator.visit_Block  s   > 	 % "Q&&<===
; 	-))%00GG**,,G= 	NNIDIIII4PPPKKMMMNNWdiWWW   LLNNN( 	U\-ANNITYIIwIII4    NN$$&& A A#'9A A5<A A A  
 KKMMMgu---LLNNNUr6   c                    |j         s|                     d|j                   | j        dk    rn| j        s)|                     d           |                                  |                     d           | j        rt                      |                                  |                     d|           | 	                    |j
        |           |                     d| j        d           |                     d           |                                  |                     d	           |                                  |j        rd
| _        | xj        dz  c_        dS )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?   rB   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   templaterF   rS   r   r'   r)   r*   s      r4   visit_ExtendszCodeGenerator.visit_Extends  sS   ~ 	SIIDdkRRR
 ""
 ) @AAANNRSSS % "nn$DdKKK

4=%(((

&	&&&'''RSSSQRRR
 ? 	*%)D" 	q r6   c                 *   |j         r)|                     d           |                                  d}t          |j        t
          j                  rKt          |j        j        t                    rd}nVt          |j        j        t          t          f          rd}n-t          |j        t
          j        t
          j        f          rd}|                     d| d|           |                     |j        |           |                     d| j        d           |j         r|                                  |                     d	           |                                  |                     d
           |                                  |                     d           |                                  d}|j        rA|                     |                                  d|                     |           d           n9| j        j        r|                     d           n|                     d           d}|s>|                                  |                     d|           |                                  |j         r|                                  dS dS )zHandles includes.r%  get_or_select_templateget_templateselect_templateztemplate = environment.r@   r?   rB   zexcept TemplateNotFound:r  r   FzUfor event in template.root_render_func(template.new_context(context.get_all(), True, z)):zGfor event in (await template._get_default_module_async())._body_stream:z6yield from template._get_default_module()._body_streamTr  N)ignore_missingr   r   rY   r  r   Constr`   rs   rt   ru   TupleListr2   rF   rS   r   with_contextrD  rp  rC   rC  r  )r'   r)   r*   	func_nameskip_event_yields        r4   visit_IncludezCodeGenerator.visit_Include	  s    	NN6"""KKMMM,	dmU[11 	*$--s33 .*		DM/%?? .-	UZ'@AA 	*)I====tDDD

4=%(((

&	&&&''' 	LLNNNNN5666KKMMMNN6"""LLNNNNN7###KKMMM  	$NN$$&& 8 8++E228 8 8   
 & 	$NN!   
 NNSTTT# 	KKMMMgu---LLNNN 	LLNNNNN	 	r6   c                    |                      |                     d           d           |                     |j        |           |                      d| j        d           |j        rHd|                     d           }|                      | d|                     |           d           d S |                      d	|                     d           d
           d S )Nawait zenvironment.get_template(r?   z).make_module_asyncz(context.get_all(), True, rB   _get_default_modulez	(context))rF   rD  r2   r  rS   r  rp  )r'   r)   r*   f_names       r4   _import_commonzCodeGenerator._import_common<  s     	

d''11LLLMMM

4=%(((

'	'''((( 	U@4#4#4X#>#>@@FJJVVT5L5LU5S5SVVV     JJST->->x-H-HSSSTTTTTr6   c                 n   |                      |j                            |j                   d|           |j        r|                     d|j        d           |                     ||           |j        r:|j                            d          s"|                      d|j        d           dS dS dS )zVisit regular imports.r0  r  r  r  context.exported_vars.discard(rB   N)r   r   rQ  r7  r   rF   r  
startswithr  s      r4   visit_ImportzCodeGenerator.visit_ImportK  s    %-++DK88===tDDD> 	<JJ:t{:::;;;D%(((> 	N$+"8"8"="= 	NNNLDKLLLMMMMM	N 	N 	N 	Nr6   c           	      0   |                      |           |                     d           |                     |           g }g }|j        D ]C}t	          |t
                    r|\  }}n|}|                     j                            |           d|d           |                     dj                            |           d           | 	                                 d| 
                    |           d|}|                     j                            |           d|d	|d
           |                                  j        r?|                    |           |                    d          s|                    |           E|rt          |          dk    r<|d         }|                     d|dj                            |                      n:d                    fd|D                       }|                     d| d           |rwt          |          dk    r!|                     d|d         d
           dS d                    t#          t$          |                    }	|                     d|	 d           dS dS )zVisit named imports.zincluded_template = z = getattr(included_template, z
, missing)rL  rM  z9the template {included_template.__name__!r} (imported on z%) does not export the requested name z = undefined(fz, name=rB   r  r
   r   r  r  r?   c              3   V   K   | ]#}|d j                             |           V  $dS rl  )r   rQ  )re   rS   r*   s     r4   rg   z1CodeGenerator.visit_FromImport.<locals>.<genexpr>{  sR       % %?Ct::!2!24!8!8::% % % % % %r6   r  r  r  z)context.exported_vars.difference_update((r   N)r  rF   r  r|   rY   rt   r   r   rQ  r   ri  r   r   r  r  rT  r5  r  rb  )
r'   r)   r*   	var_namesdiscarded_namesrS   r  messagenames_kvr  s
     `       r4   visit_FromImportzCodeGenerator.visit_FromImportV  s   T

)***D%(((	J 	2 	2D$&& "eeNN=$$U++ B B/3B B B   NNG!2!25!9!9GGGHHHKKMMM@!%t!4!4@ @7;@ @ 
 NN=$$U++VV7VVTVVV   LLNNN~ 2  ''''',, 2#**5111 	G9~~"" |TtTT5=;L;LT;R;RTTUUUU99 % % % %GP% % %   EEEEFFF 	?##q((WPQ@RWWWXXXXX IIc$&@&@AA	M	MMM    	 	r6   c                    |                                 }d|_        |                                 }|                                 }|j        p[dt          |                    d          d          v p5t          d |                    t          j                  D                       }d }|r|j	        
                    d          }|j	                            |d           |j        r|j	                            |d	           |j        r|                                 }|j	                            |d
           |                     |                     |           d|j                   |                                  |                     |           |                     |                     dd                     |                     |j        |           |                     d           |                     |                     dd                     |                     d           |                                  |                     d|j                   |                     |j        |           |                     d           |                                  |                     d           |                     |j        |           |                     d           |                     |d           |j        ra|                     |                     d           d|           |                                  |                     |           |j        |_        |r|                     | d           |                    t          j                  D ]3}	|	j        dk    r&|	j        dk    r|                     d|	j                   4|j        r,|                                 }
|                     |
 d           |                     |                     dd          |           |                     |j        |           |r0|                     d| d|                     d           d           n|                     d           |j        r|                     | d           |j        r|                     d           na| j        j         r|s|                     d            |                     |j!        |           | j        j         r|s|                     d!           |j        r|                     d!           |j        r|                     d"           n|                     |rd#nd           |                                  |                     |           |                     d$           | "                    |j#        |           |j        r|                     |
 d%           |                                  |                     ||j        o|j                    |j        r|                     d|
 d           |                                  |                     |           | "                    |j        |           |                     |           |                                  |j        r| $                    |           |                                  | %                    ||           |                     |                     d&           d'           | j        j         r|                     d            |                     |j!        |           | j        j         r|                     d!           |                     d(           | &                    |           | j'        r,| j'        d)         (                    |j	        j)                   d S d S )*NTloop)rR  )only)r  c              3   $   K   | ]}|j         V  d S r.   )r  )re   r   s     r4   rg   z*CodeGenerator.visit_For.<locals>.<genexpr>  s$      HHE5<HHHHHHr6   rR  )
for_branchelsetestz(fiter):z
async for zfor rh  zauto_aiter(fiter)fiter:rL  r      rN  z%(reciter, loop_render_func, depth=0):r1  storez8Can't assign to special loop variable in for-loop targetz = 1r?   AsynczLoopContext(r@   reciterzauto_aiter(rB   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   rV  rO  else_r  r   r   rF  r   r:  rD  r2   r7  rF   r   r=  r   r   r   rS   r   r   rC   rC  r  r  rR  r   r   r  r   difference_updatestores)r'   r)   r*   r   
test_frame
else_frameextended_looploop_refloop_filter_funcrS   iteration_indicators              r4   	visit_ForzCodeGenerator.visit_For  s   [[]]
 $
[[]]
[[]]
 N It44)4DDiPPQI HHT]]5;-G-GHHHHH	 	  	D!);;FCCH'''@@@: 	E++DV+DDD9 	A#88::++DV+DDDNNdii(899CCCTYOOOKKMMMZ(((NN4,,\6BBCCCJJt{J///JJvJJt(()<gFFGGGJJsOOOKKMMMNN5$),,,JJty*---JJsOOOKKMMMNN8$$$JJt{J///LLOOOZ4@@@
 > 	2NN99V$$KKKT   KKMMMKK
### !+ 1J  	4NNh222333MM%*-- 	 	Dx7""tyF':':		NK  
 : 	9"&";";"="=NN1777888t((v>>EEE

4;
+++ 	JJRHRR$*;*;G*D*DRRRSSSSJJv9 	/JJ*---...> 	 JJy!!!!( * *

=)))JJty%((((    

39 	JJsOOO> 	BJJ?@@@@JJ-@SAAA$$$()))	:...: 	9NN1777888$.*K^ 	 	
 	
 	
 : 	NN7!4777888KKMMMZ(((OODJ
333Z(((LLNNN > 	"''
333LLNNNUD)))JJ$++H55<<<===( *

=)))JJty%((((  

3JJy!!!NN5!!!  	Pr"44Z5G5NOOOOO	P 	Pr6   c                 (   |                                 }|                     d|           |                     |j        |           |                     d           |                                  |                     |j        |           |                                  |j	        D ]}|                     d|           |                     |j        |           |                     d           |                                  |                     |j        |           |                                  |j
        rZ|                     d           |                                  |                     |j
        |           |                                  d S d S )NrL  r  zelif r   )r   r   r2   r  rF   r   r  rR  r   elif_r  )r'   r)   r*   if_framer  s        r4   visit_IfzCodeGenerator.visit_If  sN   ::<<ud###

49h'''

3	8,,,Z 	 	ENN7E***JJuz8,,,JJsOOOKKMMMOOEJ111LLNNNN: 	NN7###KKMMMOODJ111LLNNNNN		 	r6   c                    |                      ||          \  }}|                                  |j        rV|j                            d          s|                     d|j        d           |                     d|j        d           |                     |j                            |j                   d           | 	                    ||           d S )Nr  r  rB   r  r  r0  )
r_  r  r   rS   r  rF   r   r   rQ  rf  )r'   r)   r*   macro_framerZ  s        r4   visit_MacrozCodeGenerator.visit_Macro(  s    !%u!=!=Y> 	>9'',, H

F	FFFGGGNN<49<<<===

em''	22777888y+.....r6   c                    |                      ||          \  }}|                     d           |                     ||           |                     ||           |                     |j        |d           |                     |           d S )Nz	caller = T)forward_caller)r_  r   rf  r   
visit_Callcallr  )r'   r)   r*   
call_framerZ  s        r4   visit_CallBlockzCodeGenerator.visit_CallBlock2  s     $e < <
I{###y*---%%%	5>>>ur6   c                    |                                 }|j                            |           |                     |           |                     |           |                     |j        |           |                     ||           |                     |j	        |           | 
                    |           |                     |           d S r.   )r   r   rO  r:  r   r  rR  r   r   filterr  r=  )r'   r)   r*   filter_frames       r4   visit_FilterBlockzCodeGenerator.visit_FilterBlock:  s    {{}}))$///&&&L!!!	<000%%%$+|444u&&&&&r6   c                    |                                 }|j                            |           |                     |           t	          |j        |j                  D ]Z\  }}|                                  |                     ||           | 	                    d           |                     ||           [| 
                    |j        |           |                     |           d S Nr0  )r   r   rO  r:  ziptargetsvaluesr  r2   rF   r  rR  r=  )r'   r)   r*   
with_framer7  exprs         r4   
visit_WithzCodeGenerator.visit_WithE  s    [[]]
''---$$$dk:: 	$ 	$LFDLLNNNJJvz***JJuJJtU####	:...$$$$$r6   c                 f    |                      |           |                     |j        |           d S r.   )r  r2   r)   r  s      r4   visit_ExprStmtzCodeGenerator.visit_ExprStmtQ  s0    T

49e$$$$$r6   c                   j    e Zd ZU ej        ej        def                  ed<   ej        e         ed<   dS )CodeGenerator._FinalizeInfo.constsrcN)r   r   r   r8   r   Callablers   __annotations__r   r6   r4   _FinalizeInfor  U  sB         z!*S#X.////Z_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.
        )rs   r{   s    r4   _default_finalizezCodeGenerator._default_finalizeY  s     5zzr6   	_finalizec                      j          j         S  j        x}d} j        j        rd} j        j        t          j        dt          j        dt          j        di                    t	          j                            }d}| dt          j
        dt          j
        ffd}n-| | d	}|dk    r dt          j
        dt          j
        f fd
}                     ||           _          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_ctxrC   r`   r%   c                 ,      |                     S r.   r   )r`   r^  env_finalizes    r4   finalizez.CodeGenerator._make_finalize.<locals>.finalize  s    "7<<#6#6777r6   r?   c                 8      j         |                     S r.   )rC   )r`   r^  r  r'   s    r4   r  z.CodeGenerator._make_finalize.<locals>.finalize  s"    &w||D4De'L'LMMMr6   )r  r  rC   r  r   r   eval_contextgetfrom_objr8   r9   r  )r'   r  r  pass_argr^  r  s   `   @@r4   _make_finalizezCodeGenerator._make_finalizec  sX    >%>! "337$ 	N)C+4L )%'9$m c!,// 	  H8AE 8ae 8 8 8 8 8 8 8 8 *h***},,N N!% N N N N N 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.
        )rb  r   )r'   r&  s     r4   _output_const_reprz CodeGenerator._output_const_repr  s    
 F5MM"""r6   r  c                     |                     |j                  }|j        j        rt          |          }t	          |t
          j                  rt          |          S |                    |          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   rY   r   TemplateDatars   r  )r'   r)   r*   r  r  s        r4   _output_child_to_constz$CodeGenerator._output_child_to_const  sd     en-->$ 	"5MME dE.// 	u::~~e$$$r6   c                     |j         j        r|                     d           n7|j         j        r|                     d           n|                     d           |j        |                     |j                   dS dS )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   rF   r   r  r'   r)   r*   r  s       r4   _output_child_prezCodeGenerator._output_child_pre  s     >" 	JJJKKKK^& 	JJy!!!!JJv<#JJx|$$$$$ $#r6   c                 l    |                      d           |j        |                      d           dS dS )zWOutput extra source code after visiting a child of an
        ``Output`` node.
        rB   N)rF   r  r.  s       r4   _output_child_postz CodeGenerator._output_child_post  s6     	

3<#JJsOOOOO $#r6   c                    |j         r2| j        rd S |                     d           |                                  |                                 }g }|j        D ]}	 |j        s-t          |t
          j                  st          j	                    | 
                    |||          }n1# t
          j	        t          f$ r |                    |           Y |w xY w|r7t          |d         t                    r|d                             |           |                    |g           |j        bt          |          dk    r|                     |j         d           n|                     |j         d           |                                  |D ]}t          |t                    rN|                     |          }|j        |                     d|z              L|                     |dz              e|j        |                     d|           n|                     |           |                     |||           |                     ||           |                     |||           |j        |                     d           |j        >|                                  |                     t          |          dk    rdnd	           |j         r|                                  d S d S )
Nr  r)  r
   r   z	.extend((r   rc  rB   r   )r   r   r   r   r%  r   r  rY   r+  
Impossibler,  	Exceptionr  ru   r   rT  r(  r  r/  r2   r1  rF   r   )	r'   r)   r*   r  rR  childr  itemvals	            r4   visit_OutputzCodeGenerator.visit_Output  s    % 	% NN8999KKMMM&&((;=
 Z 	% 	%E N- "%);<<-  *,,,33E5(KK$i0    E"""  %
48T22 %R&&&&UG$$$$<#4yyA~~%,8889999%,999:::KKMMM 	$ 	$D$%% $--d33<'NN8c>2222NN39----<'NN8T2222LL&&& &&tUH===

4'''''eX>>><+JJsOOO<#LLNNNNN#d))q..33d;;;% 	LLNNNNN	 	s   AB&&+CCc                    |                                   |                     |           |                     |j        |           |                     d           |                     |j        |           |                     |           d S r  )r  r  r2   r7  rF   r)   r  r  s      r4   visit_AssignzCodeGenerator.visit_Assign  s~    !!###T

4;&&&

5

49e$$$  '''''r6   c                    |                                   |                                }d|_        |j                            |           |                     |           |                     |           |                     |j        |           | 	                    |           | 
                    |j        |           |                     d           |j        |                     |j        |           n|                     d|j         d           |                     d           |                     |           |                     |           d S )NFz9 = (Markup if context.eval_ctx.autoescape else identity)(concat(rB   )r  r   r   r   rO  r:  r   r  rR  r  r2   r7  rF   r  r   r  r=  )r'   r)   r*   r   s       r4   visit_AssignBlockzCodeGenerator.visit_AssignBlock!  s:   !!###kkmm ,1(((...%%%K   	;///T

4;&&&

NOOO;"dk;7777JJ6!3666777

3  '''%%%%%r6   c           	         |j         dk    rA|j        s|j        s|j        r,| j        r%| j        d                             |j                   |j                            |j                  }|j         dk    rh|j        	                    |          }|&|d         t          k    r|                     |          r&|                     d|j        d| d| d           d S |                     |           d S )	Nr  r)  r   r   z(undefined(name=z) if z is missing else rB   )r   r   r   r   r   r   rS   r   rQ  	find_loadr   r  rF   )r'   r)   r*   rQ  r   s        r4   r   zCodeGenerator.visit_Name9  s   8wN #. 272C  ! 6"2&**49555m	**
 8v=**3//D G11144S99 2 

UtyUUUUsUUU   

3r6   c                 0   |j                             |j                  }|                     d| d           |                                  |                     d           |                                  |                     | d|j        d           d S )Nzif not isinstance(z, Namespace):zMraise TemplateRuntimeError("cannot assign attribute on non-namespace object")r&  r'  )r   rQ  rS   r   r   r   attr)r'   r)   r*   rQ  s       r4   visit_NSRefzCodeGenerator.visit_NSRefR  s     m	**>C>>>???B	
 	
 	
 	#..	.../////r6   c                     |                     |j                  }t          |t                    r$|                     t          |                     d S |                     t          |                     d S r.   )r*  r0   rY   rp   rF   rs   rb  )r'   r)   r*   r7  s       r4   visit_ConstzCodeGenerator.visit_Const`  sc    mmEN++c5!! 	"JJs3xx     JJtCyy!!!!!r6   c                     	 |                      t          |                    |j                                       d S # t          j        $ r" |                      d|j        d           Y d S w xY wNz6(Markup if context.eval_ctx.autoescape else identity)(rB   )rF   rb  r*  r0   r   r3  datar  s      r4   visit_TemplateDataz CodeGenerator.visit_TemplateDatag  s    	JJtDMM%.99::;;;;; 	 	 	JJWWWW     	s   :> -A/.A/c                     |                      d           d}t          |j                  D ]2\  }}|r|                      d           |                     ||           3|                      |dk    rdnd           d S )Nr@   r)  r?   r   z,)rB   rF   rP  rz   r2   r'   r)   r*   r]  r6  s        r4   visit_TuplezCodeGenerator.visit_Tupleo  s    

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

4   JJtU####

3!8844-----r6   c                     |                      d           t          |j                  D ]2\  }}|r|                      d           |                     ||           3|                      d           d S )Nr&  r?   r'  rJ  rK  s        r4   
visit_ListzCodeGenerator.visit_Listx  sr    

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

4   JJtU####

3r6   c                 R   |                      d           t          |j                  D ]g\  }}|r|                      d           |                     |j        |           |                      d           |                     |j        |           h|                      d           d S )Nrm  r?   r  r  )rF   rP  rz   r2   r  r`   rK  s        r4   
visit_DictzCodeGenerator.visit_Dict  s    

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

4   JJtx'''JJtJJtz5))))

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

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

4r6   c                     |                      d           |                     |j        |           |j        D ]}|                     ||           |                      d           d S )Nr@   rB   )rF   r2   r  opsrI   s       r4   visit_ComparezCodeGenerator.visit_Compare  sb    

3

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

3r6   c                     |                      dt          |j                  d           |                     |j        |           d S )NrA   )rF   	operatorsr<   r2   r  r  s      r4   visit_OperandzCodeGenerator.visit_Operand  sC    

,y),,,---

49e$$$$$r6   c                 *   | j         j        r|                     d           |                     d           |                     |j        |           |                     d|j        d           | j         j        r|                     d           d S d S )N(await auto_await(zenvironment.getattr(r?   rB   r   )rC   rC  rF   r2   r)   rA  r  s      r4   visit_GetattrzCodeGenerator.visit_Getattr  s    $ 	-JJ+,,,

)***

49e$$$

&	&&&'''$ 	JJt	 	r6   c                 z   t          |j        t          j                  rb|                     |j        |           |                     d           |                     |j        |           |                     d           d S | j        j        r|                     d           |                     d           |                     |j        |           |                     d           |                     |j        |           |                     d           | j        j        r|                     d           d S d S )Nr&  r'  rc  zenvironment.getitem(r?   rB   r   )	rY   r!  r   Slicer2   r)   rF   rC   rC  r  s      r4   visit_GetitemzCodeGenerator.visit_Getitem  s    dh,, 	!JJty%(((JJsOOOJJtx'''JJsOOOOO( 1

/000JJ-...JJty%(((JJtJJtx'''JJsOOO( !

4     ! !r6   c                 *   |j         |                     |j         |           |                     d           |j        |                     |j        |           |j        2|                     d           |                     |j        |           d S d S )Nr  )startr2   rF   stopr   r  s      r4   visit_SlicezCodeGenerator.visit_Slice  s    :!JJtz5)))

39 JJty%(((9 JJsOOOJJty%((((( ! r6   	is_filterc              #   \  K   | j         j        r|                     d           |rM|                     | j        |j                  d           | j         j                            |j                  }nL|                     | j        |j                  d           | j         j                            |j                  }|4|j        s-|rdnd}|                     d| d|j        d|j	                   t          j        dt          j        d	t          j         d
i                    t          j        |                    }||                     | d           d V  |                     ||           |                     d           | j         j        r|                     d           d S d S )Nrc  r@   r  r  zNo r*  r  r   r  rC   r?   rB   r   )rC   rC  rF   r   rS   r"  r   r   r   r   r   r   r!  r#  r#  )r'   r)   r*   rl  rF  	type_namer$  s          r4   _filter_test_commonz!CodeGenerator._filter_test_common  s      $ 	-JJ+,,, 	9JJ$,ty1444555#+//	::DDJJ$*TY/222333#)--di88D
 < 0<$-96III<I<<di<<<dkJJJ i!#5 -
 #d##
 
	 	 JJ(''' 	tU###

3$ 	JJt	 	r6   c                    |                      ||d          5  |j        |                     |j        |           n||j        j        r'|                     d|j         d|j         d           nI|j        j        r|                     d|j         d           n|                     d|j         d           d d d            d S # 1 swxY w Y   d S )NTz(Markup(concat(z.)) if context.eval_ctx.autoescape else concat(r   zMarkup(concat(r<  rB   )ro  r)   r2   r0   r1   rF   r   r   r  s      r4   r   zCodeGenerator.visit_Filter  sH   %%dE488 	6 	6 y$

49e,,,,( 6

Tel T TCH<T T T    * 6

<EL<<<====

4U\444555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   B CC	C	c                     |                      ||d          5  |                     |j        |           d d d            d S # 1 swxY w Y   d S r   )ro  r2   r)   r  s      r4   r   zCodeGenerator.visit_Test  s    %%dE599 	) 	)JJty%(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   AAAc                 l                                     d fd}                     d                                j                                        d                                j                                        d            |                                  d           d S )Nr%   c                      j                             j                     d S                     d                               d           d S )Nz1cond_expr_undefined("the inline if-expression on z6 evaluated to false and no else section was defined."))expr2r2   rF   ri  )r*   r)   r'   s   r4   write_expr2z1CodeGenerator.visit_CondExpr.<locals>.write_expr2   si    z%

4:u---JJ+MM$''+ + +    r6   r@   z if z else rB   r   )r   rF   r2   expr1r  )r'   r)   r*   ru  s   ``` r4   visit_CondExprzCodeGenerator.visit_CondExpr  s    

		 		 		 		 		 		 		 		 	

3

4:u%%%

6

49e$$$

8

3r6   r  c                    | j         j        r|                     d           | j         j        r|                     d           n|                     d           |                     |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 |}| 
                    |||           |                     d           | j         j        r|                     d           d S d S )	Nrc  zenvironment.call(context, zcontext.call(rH  
_loop_vars_block_varsrB   r   )rC   rC  rF   rD   r2   r)   r   r   r   ry   r#  )r'   r)   r*   r  r  loop_kwargsblock_kwargss          r4   r  zCodeGenerator.visit_Call3  sS    $ 	-JJ+,,,% 	(JJ34444JJ'''

49e$$$/=G(++46;6FN|\22B9>9JR}55PR 	=L<<|<<<< 	=L 	=<<|<<LtUL111

3$ 	JJt	 	r6   c                 v    |                      |j        dz              |                     |j        |           d S )Nr  )rF   r  r2   r`   r  s      r4   visit_KeywordzCodeGenerator.visit_KeywordJ  s6    

48c>"""

4:u%%%%%r6   c                     |                      d           |                     |j        |           |                      d           d S )NzMarkup(rB   rF   r2   r  r  s      r4   visit_MarkSafezCodeGenerator.visit_MarkSafeP  s=    

9

49e$$$

3r6   c                     |                      d           |                     |j        |           |                      d           d S rF  r  r  s      r4   visit_MarkSafeIfAutoescapez(CodeGenerator.visit_MarkSafeIfAutoescapeU  s@     	

KLLL

49e$$$

3r6   c                 @    |                      d|j        z              d S )Nzenvironment.rF   rS   r  s      r4   visit_EnvironmentAttributez(CodeGenerator.visit_EnvironmentAttribute\  s#     	

>DI-.....r6   c                 P    |                      d|j        d|j                    d S )Nzenvironment.extensions[z].)rF   
identifierrS   r  s      r4   visit_ExtensionAttributez&CodeGenerator.visit_ExtensionAttributea  s1     	

MT_MM$)MMNNNNNr6   c                 P    |                      | j        |j                            d S r.   )rF   r   r  r  s      r4   visit_ImportedNamez CodeGenerator.visit_ImportedNamef  s$    

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

49r6   c                 0    |                      d           d S )Nr   )rF   r  s      r4   visit_ContextReferencez$CodeGenerator.visit_ContextReferencel  s     	

9r6   c                 V    |                      |                     |                     d S r.   )rF   r  r  s      r4   visit_DerivedContextReferencez+CodeGenerator.visit_DerivedContextReferenceq  s*     	

4&&u--.....r6   c                 2    |                      d|           d S )Ncontinuerr  r  s      r4   visit_ContinuezCodeGenerator.visit_Continuev  s    z4(((((r6   c                 2    |                      d|           d S )Nbreakrr  r  s      r4   visit_BreakzCodeGenerator.visit_Breaky  s    w%%%%%r6   c                     |                                 }|j                            |           |                     |           |                     |j        |           |                     |           d S r.   )r   r   rO  r:  r  rR  r=  )r'   r)   r*   scope_frames       r4   visit_ScopezCodeGenerator.visit_Scope|  sj    kkmm((...%%%	;///%%%%%r6   c                 *   |                                  }|                     | d|                     |                      |                     | d           |                     |j        |           |                     |           |                    d          }|j                            |           | 	                    |           | 
                    |j        |           |                     |           |                                  d S )Nr0  z.vars = T)r   )r   r   r  r2   r   r{  r   r   rO  r:  r  rR  r=  r}  )r'   r)   r*   r   r  s        r4   visit_OverlayScopez CodeGenerator.visit_OverlayScope  s   ''))#>>$"5"5e"<"<>>???#'''(((

4<'''##C(((kk4k00((...%%%	;///%%%""$$$$$r6   c                 D   |j         D ]}|                     d|j         d           |                     |j        |           	 |j                            |j                  }t          |j        |j        |           w# t          j	        $ r d|j        _
        Y w xY wd S )Nzcontext.eval_ctx.r0  T)optionsr   r  r2   r`   r*  r0   setattrr   r3  r1   )r'   r)   r*   keywordr7  s        r4   visit_EvalContextModifierz'CodeGenerator.visit_EvalContextModifier  s     | 	: 	:GNN?w{???@@@JJw}e,,,:m,,U^<< S9999 # / / /*.'''/	: 	:s   A??BBc                 b   |                                  }|j                                        }|                     | d           |                     ||           |j        D ]}|                     ||           |j                            |           |                     d| d           d S )Nz = context.eval_ctx.save()zcontext.eval_ctx.revert(rB   )r   r0   saver   r  rR  r2   revert)r'   r)   r*   old_ctx_name	saved_ctxr5  s         r4   visit_ScopedEvalContextModifierz-CodeGenerator.visit_ScopedEvalContextModifier  s     0022N''))	,BBBCCC&&tU333Y 	% 	%EJJue$$$$i(((A,AAABBBBBr6   NFTr   r   )r
   r.   )Nr   )r>  r?  )r   r   r   r8   r   rs   TextIOrn   r   propertyrW   ro   r   r   r+   r   r   r   r   r   Noder   r  r  r   r  rF   r   r  r   Callr   r   Mappingr9   r#  r.  r:  r=  rD  rF  r   r   r  r   r_  rf  ri  rp  rs  rW  rY  rX  r{  r}  r  r3  r  r  r  r  rZ   r  r   r   r  r  Includer  Import
FromImportr  r  r  Forr  Ifr  r  r  FilterBlockr  Withr  ExprStmtr  
NamedTupler  staticmethodr  r  r  r%  r(  r7   r,  r/  r1  Outputr8  Assignr:  AssignBlockr=  r   r   NSRefrB  r  rD  r+  rH  rL  r  rN  DictrP  rM   	visit_Add	visit_Sub	visit_Mul	visit_Divvisit_FloorDiv	visit_Pow	visit_Mod	visit_Andvisit_OrrR   	visit_Pos	visit_Neg	visit_Notr;   Concatr[  Comparer^  Operandra  Getattrrd  Getitemrg  rf  rk  r   Iteratorro  r   r   CondExprrw  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"G4 joG4 *S/	G4
 
18$G4 G4 G4 
G4 G4 G4 G4R *4 * * * X*
L LS L] L L L L,c , , , ,
/E /d / / / / 5:9 99-19	9 9 9 9(   " "C " " " " "< < <aj.D <PT < < < <u      DH "*+*UZ*@	   	
5: 6 	u 	 	 	 	 	s t     IJ Juz2BE	   * *AJuz2 *# *d * * * * ;?	7/ 7/gej%,
:;7/ 7/ j3:!67	7/
 
7/ 7/ 7/ 7/r,qz%*'= ,$ , , , ,\> >4 > > > > B B B4 BD B B B BH H HC HQT H H H H2 2 2 2 2 2Q GEK89Q BGQ 	
	!Q  Q  Q  Q f

8 

E 

d 

 

 

 

UZ C    ! !# ! ! ! !+ + + +I I$ I I I I$ $ $ $6C 6D 6 6 6 65S 5T 5 5 5 5, , , ,1 1 1 1 1## # # # #UE Uc U U U U3c 3d 3 3 3 3) ) ) ))O )O4 )O )O )O )O\ @Du9 u9Nu9+,:e+<u9	u9 u9 u9 u9n) )E )d ) ) ) )V(!%- (! (!$ (! (! (! (!T1%- 1 1$ 1 1 1 1fUGEL%*::;UDIU	U U U U	N 	Ne 	N 	N 	N 	N 	N0U%5 0e 0 0 0 0 0dIPei IP IP$ IP IP IP IPVUX e     */ /E /d / / / /EO E d    	'e&7 	' 	'$ 	' 	' 	' 	'
%uz 
%% 
%D 
% 
% 
% 
%%5> %% %D % % % %         15    \ ,0Iqz-(///. . . . .`#
15(9 #c # # # #%J%',%8E%	% % % %*%J%',%8E%	% % % % 	J	',	8E			 	 	 	M Me M M M M M^( (e ( ( ( ( (&e&7 & &$ & & & &0uz % D    20 0E 0d 0 0 0 0" "E "d " " " "u'9 % D    . .E .d . . . .uz % D    uz % 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 ) ) ) ) 'GEL%*45'>C'PT'	
D	' ' ' ^'R 6 6e 6 6 6 6 ]6  )uz )% )D ) ) ) ]) 5> % D    ], EJ J',>B	   ],&%- & &$ & & & &5> % D    
.7<	   /./7</	/ / / /
O,O5:O	O O O O
9u'9 9% 9D 9 9 9 9u'9 % D    *38	   
/1/:?/	/ / / /
)5> )% )D ) ) ) )& &E &d & & & && &E &d & & & &%u'9 %% %D % % % %:-:6;:	: : : :
C3
C<A
C	
C 
C 
C 
C 
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   rJ   r   TYPE_CHECKINGtyping_extensionsterC   r   TypeVarr  r9   r   r`  r;   rs   rK   rM   rQ   rR   rZ   r   r  rn   r_   rd   r   r  Setr   r   r+   RuntimeErrorr   r   r~   r4  r   r(   r   r6   r4   <module>r     s   6 6     % % % % % % $ $ $ $ $ $             2 2 2 2 2 2                   . . . . . .       & & & & & & * * * * * * ( ( ( ( ( ( * * * * * *                                          ? )""""((((((AIcCJ/000 



	 		2Q 21 2 2 2 2 C AJ'PRV'VW    *Z%/7;TAB   0 $( 
. *S/ jo	
 Jqx    Z_   0 4    ":ej!*+*S/U3Z   & & & & & & & &P P P P P P P PfJ J J J J, J J J' ' ' ' 'k ' ' '&& & & & &K & & &,    9   |C |C |C |C |CK |C |C |C |C |Cr6   