Your IP : 18.116.24.238


Current Path : /opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/compiler.cpython-37.opt-1.pyc

B

ף�a�
@srdZddlZddlmZddlmZddlmZddl	m
Z
ddlmZ
ddlmZdd	lmZd
dlmZd
dlmZd
d
lmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlmZd
dlm Z d
dl!m"Z"ej#�rddl$Z%d
dl&m'Z'ej(dej)dej*fd�Z+dddddd d!d"d#�Z,e+e+d$�d%d&�Z-e.ej)d'ej/d(gdfd)�d*d+�Z0e.ej)d'ej1d(gdfd)�d,d-�Z2dFej3d0ej4e.ej4e.ej4ej5e6e6ej4e.d1�d2d3�Z7ej*e6d4�d5d6�Z8ej9ej:ej9e.ej;e.d7�d8d9�Z<Gd:d;�d;�Z=Gd<d(�d(�Z>Gd=d>�d>e?�Z@Gd?d@�d@e"�ZAGdAdB�dBe"�ZBGdCdD�dDeC�ZDGdEd'�d'e"�ZEdS)Gz0Compiles nodes from the parser into Python code.�N)�contextmanager)�update_wrapper)�StringIO)�chain)�	iskeyword)�escape)�Markup�)�nodes)�TemplateAssertionError)�Symbols)�VAR_LOAD_ALIAS)�VAR_LOAD_PARAMETER)�VAR_LOAD_RESOLVE)�VAR_LOAD_UNDEFINED)�EvalContext)�	Optimizer)�_PassArg)�concat)�NodeVisitor)�Environment�F.)Zboundz==z!=�>z>=�<z<=�inznot in)�eq�ne�gtZgteq�ltZlteqrZnotin)�f�returncs2dtjdtjtjd��fdd�}tt�t|���S)N�
CodeGenerator�Frame)�self�node�frame�kwargsr csF|jdk	r6|jjs6|j�||j�}||kr6|�||�S�|||f|�S)N)�	optimizer�eval_ctx�volatile�visit)r#r$r%r&Znew_node)r��@/opt/alt/python37/lib/python3.7/site-packages/jinja2/compiler.py�new_func,s
zoptimizeconst.<locals>.new_func)r
�Expr�t�Anyr�castr)rr-r+)rr,�
optimizeconst+s
r2r!r")�opr cs"tdtjtdd��fdd��}|S)Nr!)r#r$r%r cs�|jjrN�|jjkrN|�d��d��|�|j|�|�d�|�|j|�n8|�d�|�|j|�|�d��d��|�|j|�|�d�dS)Nz environment.call_binop(context, z, �(� �))�environment�	sandboxedZintercepted_binops�writer*�left�right)r#r$r%)r3r+r,�visitor<s

z_make_binop.<locals>.visitor)r2r
�BinExprr")r3r<r+)r3r,�_make_binop;sr>cs"tdtjtdd��fdd��}|S)Nr!)r#r$r%r cs`|jjr6�|jjkr6|�d��d��|�|j|�n|�d��|�|j|�|�d�dS)Nzenvironment.call_unop(context, z, r4r6)r7r8Zintercepted_unopsr9r*r$)r#r$r%)r3r+r,r<Tsz_make_unop.<locals>.visitor)r2r
�	UnaryExprr")r3r<r+)r3r,�
_make_unopQs
r@FTr)r$r7�name�filename�stream�
defer_init�	optimizedr cCsHt|tj�std��|�||||||�}|�|�|dkrD|j��SdS)z+Generate the python source for a node tree.z Can't compile non template nodesN)�
isinstancer
�Template�	TypeErrorZcode_generator_classr*rC�getvalue)r$r7rArBrCrDrE�	generatorr+r+r,�generatees


rK)�valuer cCs�|dks|tks|tkrdSt|�ttttttt	hkr:dSt|�t
ttt
hkr`tdd�|D��St|�tkr�tdd�|��D��SdS)z)Does the node have a safe representation?NTcss|]}t|�VqdS)N)�
has_safe_repr)�.0�vr+r+r,�	<genexpr>�sz has_safe_repr.<locals>.<genexpr>css"|]\}}t|�ot|�VqdS)N)rM)rN�krOr+r+r,rP�sF)�NotImplemented�Ellipsis�type�bool�int�float�complex�range�strr�tuple�list�set�	frozenset�all�dict�items)rLr+r+r,rM}srM)r
�namesr cCs@t|�}yx|D]}|�|�qWWntk
r8YnX|jS)z�Check if the names passed are accessed undeclared.  The return value
    is a set of all the undeclared names from the sequence of names found.
    )�UndeclaredNameVisitorr*�VisitorExit�
undeclared)r
rbr<r$r+r+r,�find_undeclared�s
rfc@s*eZdZejejejfdd�dd�ZdS)�MacroRefN)r$r cCs||_d|_d|_d|_dS)NF)r$�accesses_caller�accesses_kwargs�accesses_varargs)r#r$r+r+r,�__init__�szMacroRef.__init__)	�__name__�
__module__�__qualname__r/�Unionr
�Macro�	CallBlockrkr+r+r+r,rg�srgc@sdeZdZdZdeejdejedd�dd�Zdd�dd�Z	de
dd
�dd�Zdd�d
d�Ze	Z
dS)r"z&Holds compile time information for us.N)r(�parent�levelr cCs~||_||_|dkr4t|d�|_d|_d|_d|_n(t|j|d�|_|j|_|j|_|j|_d|_d|_d|_	d|_
d|_dS)N)rsF)r(rrr�symbols�require_output_check�buffer�block�toplevel�	rootlevel�
loop_frame�block_frame�
soft_frame)r#r(rrrsr+r+r,rk�s zFrame.__init__)r cCs2t�tt�|j��}|j�|j�|j�	�|_|S)z!Create a copy of the current one.)
r/r1r"�object�__new__�	__class__�__dict__�updatert�copy)r#�rvr+r+r,r��sz
Frame.copyF)�isolatedr cCs&|rt|j|jjdd�St|j|�S)zReturn an inner frame.r	)rs)r"r(rtrs)r#r�r+r+r,�inner�szFrame.innercCs|��}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�ryr|)r#r�r+r+r,�soft�sz
Frame.soft)NN)F)rlrmrn�__doc__rr/�OptionalrVrkr�rUr�r��__copy__r+r+r+r,r"�s.
c@seZdZdZdS)rdz?Exception used by the `UndeclaredNameVisitor` to signal a stop.N)rlrmrnr�r+r+r+r,rd�srdc@sTeZdZdZdd�dd�Zejdd�dd�Zejdd�d	d
�Z	ej
dd�dd�ZdS)
�DependencyFinderVisitorz.A visitor that collects filter and test calls.N)r cCst�|_t�|_dS)N)r]�filters�tests)r#r+r+r,rk�sz DependencyFinderVisitor.__init__)r$r cCs|�|�|j�|j�dS)N)�
generic_visitr��addrA)r#r$r+r+r,�visit_Filters
z$DependencyFinderVisitor.visit_FiltercCs|�|�|j�|j�dS)N)r�r�r�rA)r#r$r+r+r,�
visit_Tests
z"DependencyFinderVisitor.visit_TestcCsdS)zStop visiting at blocks.Nr+)r#r$r+r+r,�visit_Blocksz#DependencyFinderVisitor.visit_Block)rlrmrnr�rkr
�Filterr��Testr��Blockr�r+r+r+r,r��s
r�c@sJeZdZdZejedd�dd�Zej	dd�dd�Z
ejdd�d	d
�ZdS)rcz�A 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.
    N)rbr cCst|�|_t�|_dS)N)r]rbre)r#rbr+r+r,rks
zUndeclaredNameVisitor.__init__)r$r cCsJ|jdkr8|j|jkr8|j�|j�|j|jkrFt��n|j�|j�dS)N�load)�ctxrArbrer�rd�discard)r#r$r+r+r,�
visit_Names
z UndeclaredNameVisitor.visit_NamecCsdS)zStop visiting a blocks.Nr+)r#r$r+r+r,r�!sz!UndeclaredNameVisitor.visit_Block)
rlrmrnr�r/�IterablerZrkr
�Namer�r�r�r+r+r+r,rcsrcc@seZdZdZdS)�CompilerExitz�Raised if the compiler encountered a situation where it just
    doesn't make sense to further process the code.  Any block that
    raises such an exception is not further processed.
    N)rlrmrnr�r+r+r+r,r�%sr�c	@sJeZdZUd�dejeejeejejeedd�dd�Ze	ed�d	d
��Z
eedd�d
d�Zed�dd�Z
edd�dd�Zd�eedd�dd�Zdd�dd�Zd�edd�dd�Zd�eejejdd�dd�Zedd�d d!�Zd�eeejejdd"�d#d$�Zejejedd%�d&d'�Zedd(�d)d*�Zd�eejejedd,�d-d.�Zd�ejejedd/�d0d1�Zd�ejejejej feejej!eej"fdd2�d3d4�Z#ejejdd5�d6d7�Z$edd�d8d9�Z%d�eedd:�d;d<�Z&d�eeed?�d@dA�Z'eedB�dCdD�Z(ejej)ej*feej+ee,fdE�dFdG�Z-e,eddH�dIdJ�Z.ejedK�dLdM�Z/eed�dNdO�Z0dd�dPdQ�Z1edd�dRdS�Z2dd�dTdU�Z3eddV�dWdX�Z4eddV�dYdZ�Z5dd�d[d\�Z6ed�d]d^�Z7ed�d_d`�Z8eed�dadb�Z9eedV�dcdd�Z:dd�dedf�Z;edd�dgdh�Z<d�ej=ejeddE�didj�Z>ej?eddE�dkdl�Z@ejAeddE�dmdn�ZBejCeddE�dodp�ZDejejEejFfeddE�dqdr�ZGejEeddE�dsdt�ZHejFeddE�dudv�ZIejJeddE�dwdx�ZKejLeddE�dydz�ZMej)eddE�d{d|�ZNej*eddE�d}d~�ZOejPeddE�dd��ZQejReddE�d�d��ZSejTeddE�d�d��ZUGd�d��d�ejV�ZWeXej"ej"d��d�d���ZYdZZejeWe[d�<eWd�d�d��Z\ejej"ed��d�d��Z]ej^eeWed��d�d��Z_ej^eeWdd��d�d��Z`ej^eeWdd��d�d��ZaejbeddE�d�d��ZcejdeddE�d�d��ZeejfeddE�d�d��ZgejheddE�d�d��ZiejjeddE�d�d��ZkejleddE�d�d��ZmejneddE�d�d��Zoej+eddE�d�d��ZpejqeddE�d�d��ZrejseddE�d�d��Zteud��Zveud��Zweud��Zxeud��Zyeud��Zzeud��Z{eud��Z|eud��Z}eud��Z~ed��Z�ed��Z�ed��Z�e�ej�eddE�d�d���Z�e�ej�eddE�d�d���Z�ej�eddE�d�d��Z�e�ej�eddE�d�d���Z�e�ej�eddE�d�d���Z�ej�eddE�d�d��Z�e�ejejej feeej�dd��d�dÄ�Z�e�ejeddE�d�dń�Z�e�ej eddE�d�dDŽ�Z�e�ej�eddE�d�dɄ�Z�e�d�ejeeddʜd�d̄�Z�ej�eddE�d�d΄Z�ej�eddE�d�dЄZ�ej�eddE�d�d҄Z�ej�eddE�d�dԄZ�ej�eddE�d�dքZ�ej�eddE�d�d؄Z�ej�eddE�d�dڄZ�ej�eddE�d�d܄Z�ej�eddE�d�dބZ�ej�eddE�d�d�Z�ej�eddE�d�d�Z�ej�eddE�d�d�Z�ej�eddE�d�d�Z�ej�eddE�d�d�Z�ej�eddE�d�d�Z�dS)�r!NFTr)r7rArBrCrDrEr cCs�|dkrt�}||_||_||_||_d|_||_d|_|rFt|�|_i|_	i|_
d|_d|_d|_
i|_i|_g|_d|_d|_d|_d|_d|_d|_g|_g|_dg|_dS)NFrr	T�context)rr7rArBrCZcreated_block_contextrDr'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#r7rArBrCrDrEr+r+r,rk-s8	
zCodeGenerator.__init__)r cCs
|jdk	S)N)r')r#r+r+r,rEvszCodeGenerator.optimizedzte.NoReturn)�msg�linenor cCst|||j|j��dS)z*Fail with a :exc:`TemplateAssertionError`.N)rrArB)r#r�r�r+r+r,�fail|szCodeGenerator.failcCs|jd7_d|j��S)zGet a new unique identifier.r	Zt_)r�)r#r+r+r,�temporary_identifier�sz"CodeGenerator.temporary_identifier)r%r cCs |��|_|�|j�d��dS)z7Enable buffering for the frame from that point onwards.z = []N)r�rv�	writeline)r#r%r+r+r,rv�s
zCodeGenerator.buffer)r%�force_unescapedr cCs�|s�|jjrl|�d�|��|�d|j�d��|��|�d�|��|�d|j�d��|��dS|jjr�|�d|j�d��dS|�d|j�d��dS)z(Return the buffer contents of the frame.zif context.eval_ctx.autoescape:zreturn Markup(concat(z))zelse:zreturn concat(r6N)r(r)r��indentrv�outdent�
autoescape)r#r%r�r+r+r,�return_buffer_contents�s

z$CodeGenerator.return_buffer_contentscCs|jd7_dS)zIndent by one.r	N)r�)r#r+r+r,r��szCodeGenerator.indentr	)�stepr cCs|j|8_dS)zOutdent by step.N)r�)r#r�r+r+r,r��szCodeGenerator.outdent)r%r$r cCs0|jdkr|�d|�n|�|j�d�|�dS)z%Yield or write into the frame buffer.Nzyield z.append()rvr�)r#r%r$r+r+r,�start_write�s
zCodeGenerator.start_writecCs|jdk	r|�d�dS)z1End the writing process started by `start_write`.Nr6)rvr9)r#r%r+r+r,�	end_write�s
zCodeGenerator.end_write)�sr%r$r cCs$|�||�|�|�|�|�dS)z4Simple shortcut for start_write + write + end_write.N)r�r9r�)r#r�r%r$r+r+r,�simple_write�s
zCodeGenerator.simple_write)r
r%r cCsBy(|�d�x|D]}|�||�qWWntk
r<YnXdS)z�Visit 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�r*r�)r#r
r%r$r+r+r,�
blockvisit�s

zCodeGenerator.blockvisit)�xr cCs�|jrp|jsR|j�d|j�|j|j7_|jdk	rR|j�|j|jf�d|_d|_|j�d|j�d|_|j�|�dS)z&Write a string into the output stream.�
NFz    r)	r�r�rCr9r�r�r��appendr�)r#r�r+r+r,r9�s
zCodeGenerator.writer)r�r$�extrar cCs|�||�|�|�dS)z!Combination of newline and write.N)�newliner9)r#r�r$r�r+r+r,r��szCodeGenerator.writeline)r$r�r cCs:t|jd|�|_|dk	r6|j|jkr6|j|_|j|_dS)z/Add one or more newlines before the next write.r	N)�maxr�r�r�r�)r#r$r�r+r+r,r��szCodeGenerator.newline)r$r%�extra_kwargsr c	Cs�tdd�tdd�|jD�|pd�D��}x$|jD]}|�d�|�||�q0W|s�x$|jD]}|�d�|�||�qZW|dk	r�x*|��D]\}}|�d|�d|���q�W|jr�|�d�|�|j|�|�r�|jdk	r�|�d	�n
|�d
�x8|jD].}|�|j	�d��|�|j
|�|�d�q�W|dk	�rbx,|��D] \}}|�|�d|�d���q>W|jdk	�r�|�d�|�|j|�|�d
�n
|�d�n$|jdk	�r�|�d�|�|j|�dS)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.
        css|]}tt�t|��VqdS)N)�is_python_keywordr/r1rZ)rNrQr+r+r,rP�sz*CodeGenerator.signature.<locals>.<genexpr>css|]}|jVqdS)N)�key)rNr�r+r+r,rP�sr+z, N�=z, *z
, **dict({z, **{z: z}, **r6�}z, **)�anyrr&�argsr9r*raZdyn_argsZ
dyn_kwargsr�rL)	r#r$r%r�Zkwarg_workaround�argZkwargr�rLr+r+r,�	signature�sF 







zCodeGenerator.signature)r
r c
Cst�}x|D]}|�|�qWx�|j|jdf|j|jdffD]�\}}}x�t|�D]�}||krh|��||<|�d�|��|�||�d|�d|�d��|��|�d�|��|�d�|�d	||�d
��|��|�d|dd
��d|�d��|��|��qPWq<Wd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�ztry:z = environment.�[�]zexcept KeyError:z
@internalcodezdef z
(*unused):zraise TemplateRuntimeError("No N���z named z	 found."))	r�r*r�r��sortedr�r�r�r�)r#r
r<r$Zid_maprbZ
dependencyrAr+r+r,�pull_dependenciess.

 

zCodeGenerator.pull_dependenciesc	Cs�g}x�|jj��D]z\}\}}|tkr(q|tkrR|�|�d|���d|�d��q|tkrp|�|�d|���q|tkr�|�	|�qt
d��qW|r�|�d�|��d��dS)Nz = r4r6zunknown load instructionz
 = missing)rt�loadsrarrr��get_resolve_funcr
rr��NotImplementedError�join)r#r%�undefs�target�actionZparamr+r+r,�enter_frameEs"zCodeGenerator.enter_frame)r%�with_python_scoper cCsB|s>g}x|jjD]}|�|�qW|r>|�d�|��d��dS)Nz = z
 = missing)rtr�r�r�r�)r#r%r�r�r�r+r+r,�leave_frameUszCodeGenerator.leave_frame�async �)�async_value�
sync_valuer cCs|jjr|S|S)N)r7�is_async)r#r�r�r+r+r,�choose_async]szCodeGenerator.choose_async)rAr cCs|���d|��S)Nzdef )r�)r#rAr+r+r,�func`szCodeGenerator.func)r$r%r cCs�|��}|j�|�t|�}d}t�}g}xNt|j�D]@\}}|jdkrL|}|jdkrb|�|j�|�	|j�
|j��q6Wt|jd�}	d|	kr�|dk	r�y|j
|t|j�Wq�tk
r�|�d|j�Yq�Xn|�	|j�d��d|_d|	k�rd|k�r|�	|j�d��d|_d|	k�rDd|k�rD|�	|j�d��d|_d	|_|j�|�|�|�d
��dd�|��d
�|�|��|�|�|�|�|�|�x�t|j�D]�\}}|j�
|j�}
|�d|
�d��|��y|j
|t|j�}Wn6tk
�r*|�|
�d|j�d|j�d��YnX|�|
�d��|�||�|�|
�|� ��q�W|�!�|�"|j|�|j#|dd�|j$|dd�|� �||fS)z/Dump the function def of a macro or call block.N�caller)r&�varargs)r�r&r�zhWhen defining macros or call blocks the special "caller" argument must be omitted or be given a default.Tr&r�FZmacror4z, z):zif z is missing:z = undefined("parameter z was not provided", name=r6z = )r�)r�)%r�rt�analyze_nodergr]�	enumerater�rAr�r��refrf�body�defaults�len�
IndexErrorr�r��declare_parameterrhrirjrur�r�r�r�rvr��push_parameter_definitionsr*�mark_parameter_storedr��pop_parameter_definitionsr�r�r�)r#r$r%�	macro_refZexplicit_callerZskip_special_paramsr��idxr�rer��defaultr+r+r,�
macro_bodycsn

$


"
zCodeGenerator.macro_body)r�r%r c
Csrd�dd�|jjD��}t|jdd�}t|jj�dkr>|d7}|�d|�d	|�d
|j�d|j�d|j�d��dS)z<Dump the macro definition for the def created by macro_body.z, css|]}t|j�VqdS)N)�reprrA)rNr�r+r+r,rP�sz*CodeGenerator.macro_def.<locals>.<genexpr>rANr	�,zMacro(environment, macro, z, (z), z, context.eval_ctx.autoescape))	r�r$r��getattrr�r9rirjrh)r#r�r%Z	arg_tuplerAr+r+r,�	macro_def�szCodeGenerator.macro_def)r$r cCs*d|j��}|jdk	r&|�d|j��}|S)z.Return a human readable position for the node.zline Nz in )r�rA)r#r$r�r+r+r,�position�s
zCodeGenerator.positioncCs*d�dd�|j����D��}d|�d�S)Nz, css |]\}}|�d|��VqdS)z: Nr+)rNrAr�r+r+r,rP�sz3CodeGenerator.dump_local_context.<locals>.<genexpr>�{r�)r�rtZdump_storesra)r#r%Zitems_kvr+r+r,�dump_local_context�sz CodeGenerator.dump_local_contextcCs,|�d�|�d�|�d�|�d�dS)z�Writes 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.undefinedzcond_expr_undefined = Undefinedzif 0: yield NoneN)r�)r#r+r+r,�
write_commons�s


zCodeGenerator.write_commonscCs|j�|j���dS)aQPushes 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�rtZdump_param_targets)r#r%r+r+r,r��sz(CodeGenerator.push_parameter_definitionscCs|j��dS)z+Pops the current parameter definitions set.N)r��pop)r#r+r+r,r��sz'CodeGenerator.pop_parameter_definitions)r�r cCs|jr|jd�|�dS)z�Marks a parameter in the current parameter definitions as stored.
        This will skip the enforced undefined checks.
        r�N)r�r�)r#r�r+r+r,r��sz#CodeGenerator.mark_parameter_storedcCs|j�|�dS)N)r�r�)r#r�r+r+r,�push_context_reference�sz$CodeGenerator.push_context_referencecCs|j��dS)N)r�r�)r#r+r+r,�pop_context_reference�sz#CodeGenerator.pop_context_referencecCs
|jdS)Nr�)r�)r#r+r+r,�get_context_ref�szCodeGenerator.get_context_refcCs |jd}|dkrdS|�d�S)Nr�r�Zresolvez.resolve)r�)r#r�r+r+r,r��s
zCodeGenerator.get_resolve_funccCs|���d|�|��d�S)Nz	.derived(r6)r�r�)r#r%r+r+r,�derive_context�szCodeGenerator.derive_contextcCs|js
dS||jdkS)z4Checks if a given target is an undeclared parameter.Fr�)r�)r#r�r+r+r,�parameter_is_undeclaredsz%CodeGenerator.parameter_is_undeclaredcCs|j�t��dS)z+Pushes a new layer for assignment tracking.N)r�r�r])r#r+r+r,�push_assign_trackingsz"CodeGenerator.push_assign_trackingcCs�|j��}|js|js|jr |s$dSdd�|D�}t|�dkr�tt|��}|j�	|�}|jrv|�
d|�d|���dS|jr�|�
d|�d|���dS|�
d|�d|���n||jr�|�
d	�n|jr�|�
d
�n
|�
d�xBt|�D]6\}}|r�|�d�|j�	|�}|�|�d
|���q�W|�d�|j�s�|j�s�|�r�t|�dk�rf|�
d|d�d��n"d�
tt|��}|�
d|�d��dS)zoPops the topmost level for assignment tracking and updates the
        context variables if necessary.
        NcSs g|]}|dd�dkr|�qS)Nr	�_r+)rNr�r+r+r,�
<listcomp>sz5CodeGenerator.pop_assign_tracking.<locals>.<listcomp>r	z_loop_vars[z] = z_block_vars[z
context.vars[z_loop_vars.update({z_block_vars.update({zcontext.vars.update({z, z: z})zcontext.exported_vars.add(rr6zcontext.exported_vars.update((z)))r�r�r{rzrxr��next�iterrtr�r�r�r9r��mapr�)r#r%�varsZpublic_namesrAr�r��	names_strr+r+r,�pop_assign_trackingsB



z!CodeGenerator.pop_assign_trackingc	Cs$|dkstd��t|j|j�}ddlm}m}|jjrDt||�}nt|�}|�	d�|�	dd�
|��|jrtdnd}|�t
j�dk	}xD|�t
j�D]4}	|	j|jkr�|�d	|	j�d
�|	j�|	|j|	j<q�Wx�|�t
j�D]v}
|
j|jkr�|
j}|��|j|<}d|k�r<|�dd�\}
}|�	d|
�d
|�d|���q�|�	d|�d|���q�W|�	d|j���|j	|�d��d|�d�dd�|��|��t|�}dt|jd�k�r�|j� d�}|�	|�d��|j�!|�d|_"|_#|�o�|j$|_%|�r|�	d�|�&|�|�'|j�|�(|j|�|j)|dd�|�*�|�r�|j$�s`|��|�	d�|��|jj�s~|�	d�n$|�	d�|��|�	d�|�*�|�*d|j$��x|j�+�D�]\}}	|�	|�d|��d|�d�|	d�|��|��t|�}d|_,t|	jd �}d|k�r@|j� d�}|�	|�d��d!|k�rr|j� d!�}|�	|�d"|�d#|�d$��|j�!|	�||_-|�	d%�|�&|�|�'|	j�|�(|	j|�|j)|dd�|�*��q�Wd�
d&d'�|jD��}|j	d(|�d)�dd�d*�
d+d'�|j.D��}|�	d,|���dS)-Nzno root frame allowedr	)�exported�async_exportedz%from __future__ import generator_stopzfrom jinja2.runtime import z, r�z, environment=environmentzblock z defined twice�.zfrom z import z as zimport zname = �rootz(context, missing=missingz):)r�r#)r#z = TemplateReference(context)Tzparent_template = None)r�zif parent_template is not None:z4yield from parent_template.root_render_func(context)z=async for event in parent_template.root_render_func(context):zyield eventZblock_)r#�superrz = context.super(z, block_r6z_block_vars = {}css|]}|�d|��VqdS)z: block_Nr+)rNr�r+r+r,rP�sz/CodeGenerator.visit_Template.<locals>.<genexpr>z
blocks = {r��&css |]\}}|�d|��VqdS)r�Nr+)rNrQrOr+r+r,rP�sz
debug_info = )/�AssertionErrorrr7rAZruntimer
rr�r�r�r�rD�findr
�Extends�find_allr�r�r�r��ImportedName�
importnamer�r��rsplitr�r�r�r"rfr�rtr�r�rxryr�rur�r�r�r�r�rar{rwr�)r#r$r%r(r
rZexported_namesZenvenvZhave_extendsrw�import_Zimp�alias�module�objr�rAr{reZ
blocks_kv_strZdebug_kv_strr+r+r,�visit_Template9s�










zCodeGenerator.visit_TemplatecCsd}|jr8|jrdS|jdkr8|�d�|��|d7}|jrJ|�|�}n|��}|jr�|�d|j	�d�|�|��|�d|j	�d�|�|�
�|jjs�|j
dkr�|�d	|j	�d
|�d�|�n@|�|���d|j	�d
|�d
�|�|��|�d|�|�
�|�
|�dS)z.Call a block and register it for the template.rNzif parent_template is None:r	zif len(context.blocks[z]) <= 1:z+raise TemplateRuntimeError("Required block z not found")zyield from context.blocks[z][0](r6zfor event in context.blocks[z):�event)rxr�r�r�r��scopedr�r�ZrequiredrAr�r7r�rvr�r�)r#r$r%rsr�r+r+r,r��s8

zCodeGenerator.visit_BlockcCs�|js|�d|j�|jdkrV|js6|�d�|��|�d�|jrNt��n|��|�d|�|�	|j
|�|�d|j�d��|�d�|��|�d	�|��|j
r�d
|_|jd7_dS)
zCalls the extender.z,cannot use extend from a non top-level scoperzif parent_template is not None:z5raise TemplateRuntimeError("extended multiple times")z+parent_template = environment.get_template(z, r6z9for name, parent_block in parent_template.blocks.items():z8context.blocks.setdefault(name, []).append(parent_block)Tr	N)rxr�r�r�r�r�r�r�r�r*�templater9rAry)r#r$r%r+r+r,�
visit_Extends�s(




zCodeGenerator.visit_ExtendscCsp|jr|�d�|��d}t|jtj�rVt|jjt�r>d}qnt|jjt	t
f�rnd}nt|jtjtjf�rnd}|�d|�d�|�|�
|j|�|�d|j�d��|jr�|��|�d	�|��|�d
�|��|�d�|��d}|j�r|�|���d
|�|��d��n$|jj�r,|�d�n|�d�d}|�s\|��|�d|�|��|j�rl|��dS)zHandles includes.ztry:Zget_or_select_templateZget_templateZselect_templateztemplate = environment.r4z, r6zexcept TemplateNotFound:r�zelse: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_streamTrN)Zignore_missingr�r�rFrr
�ConstrLrZr[r\�Tuple�Listr*r9rAr��with_contextr�r�r7r�r�)r#r$r%�	func_nameZskip_event_yieldr+r+r,�
visit_IncludesJ





zCodeGenerator.visit_IncludecCs�|�|�d��d��|�|j|�|�d|j�d��|jrld|�d���}|�|�d|�|��d��n|�d	|�d��d
��dS)Nzawait zenvironment.get_template(z, z).Zmake_moduleZ_asyncz(context.get_all(), True, r6Z_get_default_modulez	(context))r9r�r*rrAr#r�)r#r$r%Zf_namer+r+r,�_import_common9szCodeGenerator._import_commoncCsl|�|j�|j��d�|�|jr6|�d|j�d��|�||�|jrh|j�d�sh|�d|j�d��dS)zVisit regular imports.z = z
context.vars[z] = rzcontext.exported_vars.discard(r6N)r�rtr�r�rxr9r&�
startswith)r#r$r%r+r+r,�visit_ImportHszCodeGenerator.visit_Importc
	s�|�|�|�d�|�|��g}g}x�|jD]�}t|t�rH|\}}n|}|��j�|��d|�d��|�d�j�|��d��|�	�d|�
|��d|��}|��j�|��d|�d	|�d
��|���jr0|�
|�|�d�s0|�
|�q0W|�r\t|�dk�r2|d
}|�d|�d�j�|����n*d��fdd�|D��}|�d|�d��|�r�t|�dk�r�|�d|d
�d
��n"d�tt|��}	|�d|	�d��dS)zVisit named imports.zincluded_template = z = getattr(included_template, z
, missing)zif z is missing:z9the template {included_template.__name__!r} (imported on z%) does not export the requested name z = undefined(fz, name=r6rr	rz
context.vars[z] = z, c3s$|]}|�d�j�|���VqdS)z: N)rtr�)rNrA)r%r+r,rPysz1CodeGenerator.visit_FromImport.<locals>.<genexpr>zcontext.vars.update({z})zcontext.exported_vars.discard(z)context.exported_vars.difference_update((z))N)r�r9r&rbrFr[r�rtr�r�r�r�rxr�r'r�r�rr�)
r#r$r%Z	var_namesZdiscarded_namesrAr�messageZnames_kvrr+)r%r,�visit_FromImportSsD



 

 zCodeGenerator.visit_FromImportcCs�|��}d|_|��}|��}|jpRdt|jdd�d�kpRtdd�|�tj�D��}d}|rh|j	�
d�}|j	j|dd	�|jr�|j	j|d
d	�|j
�r�|��}|j	j|dd	�|�|�|��d�|j
�|��|�|�|�|�d
d��|�|j|�|�d�|�|�dd��|�d�|��|�d|j
�|�|j
|�|�d�|��|�d�|�|j|�|�d�|j|dd�|j�r�|�|�d��d�|�|��|�|�|j|_|�r�|�|�d��x<|�tj�D],}	|	jdk�r�|	jdk�r�|�d|	j��q�W|j�r4|��}
|�|
�d��|�|�d
d�|�|�|j|�|�r||�d|�d|�d��d��n
|�d�|j
�r�|�|�d��|j�r�|�d �nB|jj �r�|�s�|�d!�|�|j!|�|jj �r�|�s�|�d"�|j
�r|�d"�|j�r|�d#�n|�|�r(d$nd�|��|�|�|�d%�|�"|j#|�|j�rp|�|
�d&��|��|j||j�o�|jd�|j�r�|�d|
�d��|��|�|�|�"|j|�|�|�|��|j�rd|�$|�|��|�%||�|�|�d'��d(��|jj �r.|�d!�|�|j!|�|jj �rP|�d"�|�d)�|�&|�|j'�r�|j'd*�(|j	j)�dS)+NT�loop)r�)Zonly)r+css|]}|jVqdS)N)r)rNrwr+r+r,rP�sz*CodeGenerator.visit_For.<locals>.<genexpr>r�)Z
for_branch�else�testz(fiter):z
async for zfor z in zauto_aiter(fiter)Zfiter�:zif zyield �)r�z%(reciter, loop_render_func, depth=0):z
 = missing�storez8Can't assign to special loop variable in for-loop targetz = 1z, ZAsynczLoopContext(r4Zreciterzauto_aiter(r6z&, undefined, loop_render_func, depth):z
, undefined):z_loop_vars = {}z = 0zawait zloop(z, loop)r�)*r�rz�	recursiverfZiter_child_nodesr�rr
r�rtr�r��else_r-r�r�r�r�r�r�r*r�r9r�r�rvr�r�rAr�r�r7r�rr�r�r�r�r�r��difference_updateZstores)r#r$r%rzZ
test_frameZ
else_frameZ
extended_loopZloop_refZloop_filter_funcrAZiteration_indicatorr+r+r,�	visit_For�s�






 














zCodeGenerator.visit_ForcCs�|��}|�d|�|�|j|�|�d�|��|�|j|�|��xP|j	D]F}|�d|�|�|j|�|�d�|��|�|j|�|��qRW|j
r�|�d�|��|�|j
|�|��dS)Nzif r.zelif zelse:)r�r�r*r-r9r�r�r�r��elif_r2)r#r$r%Zif_framer5r+r+r,�visit_Ifs&


zCodeGenerator.visit_IfcCs||�||�\}}|��|jrR|j�d�s>|�d|j�d��|�d|j�d��|�|j�|j��d��|�	||�dS)Nrzcontext.exported_vars.add(r6z
context.vars[z] = z = )
r�r�rxrAr'r9r�rtr�r�)r#r$r%Zmacro_framer�r+r+r,�visit_Macro%szCodeGenerator.visit_MacrocCsR|�||�\}}|�d�|�||�|�||�|j|j|dd�|�|�dS)Nz	caller = T)�forward_caller)r�r�r�r��
visit_Call�callr�)r#r$r%Z
call_framer�r+r+r,�visit_CallBlock/s
zCodeGenerator.visit_CallBlockcCsh|��}|j�|�|�|�|�|�|�|j|�|�||�|�|j	|�|�
|�|�|�dS)N)r�rtr�r�rvr�r�r�r��filterr�r�)r#r$r%Zfilter_framer+r+r,�visit_FilterBlock7s


zCodeGenerator.visit_FilterBlockcCs�|��}|j�|�|�|�xDt|j|j�D]2\}}|��|�||�|�	d�|�||�q.W|�
|j|�|�|�dS)Nz = )
r�rtr�r��zip�targets�valuesr�r*r9r�r�r�)r#r$r%Z
with_framer��exprr+r+r,�
visit_WithBs

zCodeGenerator.visit_WithcCs|�|�|�|j|�dS)N)r�r*r$)r#r$r%r+r+r,�visit_ExprStmtNs
zCodeGenerator.visit_ExprStmtc@s4eZdZUejejdefed<ejeed<dS)zCodeGenerator._FinalizeInfo.�const�srcN)rlrmrnr/r��CallablerZ�__annotations__r+r+r+r,�
_FinalizeInfoRs
rH)rLr cCst|�S)z�The 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.
        )rZ)rLr+r+r,�_default_finalizeVszCodeGenerator._default_finalize�	_finalizecs��jdk	r�jS�j}�d}�jjr�d}�jj�tjdtjdtjdi�t����}d}|dkr|t	j
t	j
d���fdd�}n2|�|�d	�}|dkr�t	j
t	j
d����fd
d�}��||��_�jS)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.
        Nzenvironment.finalize(r�zcontext.eval_ctxr7)rLr cs��|��S)Nr+)rL)r��env_finalizer+r,�finalize�sz.CodeGenerator._make_finalize.<locals>.finalizez, cs���j|��S)N)r7)rL)r�rKr#r+r,rL�s)rJrIr7rLrr��eval_context�get�from_objr/r0rH)r#rLrE�pass_argr+)r�rKr#r,�_make_finalize`s&


zCodeGenerator._make_finalize)�groupr cCstt|��S)z�Given a group of constant values converted from ``Output``
        child nodes, produce a string to write to the template module
        source.
        )r�r)r#rRr+r+r,�_output_const_repr�sz CodeGenerator._output_const_repr)r$r%rLr cCs:|�|j�}|jjrt|�}t|tj�r0t|�S|�|�S)aCTry 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_constr(r�rrFr
�TemplateDatarZrD)r#r$r%rLrDr+r+r,�_output_child_to_const�s
z$CodeGenerator._output_child_to_constcCsL|jjr|�d�n|jjr(|�d�n
|�d�|jdk	rH|�|j�dS)zXOutput extra source code before visiting a child of an
        ``Output`` node.
        z1(escape if context.eval_ctx.autoescape else str)(zescape(zstr(N)r(r)r9r�rE)r#r$r%rLr+r+r,�_output_child_pre�s

zCodeGenerator._output_child_precCs"|�d�|jdk	r|�d�dS)zWOutput extra source code after visiting a child of an
        ``Output`` node.
        r6N)r9rE)r#r$r%rLr+r+r,�_output_child_post�s

z CodeGenerator._output_child_postc	
Cs�|jr"|jrdS|�d�|��|��}g}x�|jD]�}y,|jsVt|tj�sVt�	��|�
|||�}Wn&tj	tfk
r�|�|�w6YnX|r�t|dt
�r�|d�|�q6|�|g�q6W|jdk	�rt|�dkr�|�|j�d��n|�|j�d��|��x�|D]�}t|t
��rR|�|�}|jdk�rB|�d|�n|�|d�nb|jdk�rl|�d|�n
|�|�|�|||�|�||�|�|||�|jdk	�r|�d��qW|jdk	�r�|��|�t|�dk�r�dnd	�|j�r�|��dS)
Nzif parent_template is None:r�r	z.append(z	.extend((zyield r�r6z)))rur�r�r�rQr
rDrFrU�
ImpossiblerV�	Exceptionr�r\rvr�rSr�rWr*rXr9r�)	r#r$r%rLr��childrD�item�valr+r+r,�visit_Output�sV




zCodeGenerator.visit_OutputcCsF|��|�|�|�|j|�|�d�|�|j|�|�|�dS)Nz = )rr�r*r�r9r$r	)r#r$r%r+r+r,�visit_Assigns

zCodeGenerator.visit_AssigncCs�|��|��}d|_|j�|�|�|�|�|�|�|j|�|�	|�|�
|j|�|�d�|j
dk	r�|�|j
|�n|�d|j�d��|�d�|�|�|�|�dS)NFz9 = (Markup if context.eval_ctx.autoescape else identity)(zconcat(r6)rr�rurtr�r�rvr�r�r�r*r�r9r<r�r	r�)r#r$r%r{r+r+r,�visit_AssignBlocks 






zCodeGenerator.visit_AssignBlockc	Cs�|jdkr4|js|js|jr4|jr4|jd�|j�|j�|j�}|jdkr�|j�	|�}|dk	rv|dt
krv|�|�r�|�d|j�d|�d|�d��dS|�|�dS)	Nr0r�r�rz(undefined(name=z) if z is missing else r6)
r�rxrzr{r�r�rArtr�Z	find_loadrrr9)r#r$r%r�r�r+r+r,r�6s


zCodeGenerator.visit_NamecCsV|j�|j�}|�d|�d��|��|�d�|��|�|�d|j�d��dS)Nzif not isinstance(z
, Namespace):zMraise TemplateRuntimeError("cannot assign attribute on non-namespace object")r�r�)rtr�rAr�r�r��attr)r#r$r%r�r+r+r,�visit_NSRefOszCodeGenerator.visit_NSRefcCs8|�|j�}t|t�r&|�t|��n|�t|��dS)N)rTr(rFrWr9rZr�)r#r$r%r]r+r+r,�visit_Const]s
zCodeGenerator.visit_ConstcCsJy|�t|�|j���Wn*tjk
rD|�d|j�d��YnXdS)Nz6(Markup if context.eval_ctx.autoescape else identity)(r6)r9r�rTr(r
rY�data)r#r$r%r+r+r,�visit_TemplateDatads
z CodeGenerator.visit_TemplateDatacCsZ|�d�d}x0t|j�D]"\}}|r0|�d�|�||�qW|�|dkrPdnd�dS)Nr4r�z, rz,)r6)r9r�rar*)r#r$r%r�r\r+r+r,�visit_Tuplels

zCodeGenerator.visit_TuplecCsJ|�d�x0t|j�D]"\}}|r,|�d�|�||�qW|�d�dS)Nr�z, r�)r9r�rar*)r#r$r%r�r\r+r+r,�
visit_Listus

zCodeGenerator.visit_ListcCsd|�d�xJt|j�D]<\}}|r,|�d�|�|j|�|�d�|�|j|�qW|�d�dS)Nr�z, z: r�)r9r�rar*r�rL)r#r$r%r�r\r+r+r,�
visit_Dict}s


zCodeGenerator.visit_Dict�+�-�*�/z//z**�%�and�orznot cCsd|jjrd}n|jjrd}nd}|�|�d��x$|jD]}|�||�|�d�q8W|�d�dS)Nz8(markup_join if context.eval_ctx.volatile else str_join)Zmarkup_joinZstr_joinz((z, z)))r(r)r�r9r
r*)r#r$r%r$r�r+r+r,�visit_Concat�szCodeGenerator.visit_ConcatcCsB|�d�|�|j|�x|jD]}|�||�q W|�d�dS)Nr4r6)r9r*rAZops)r#r$r%r3r+r+r,�
visit_Compare�s

zCodeGenerator.visit_ComparecCs*|�dt|j�d��|�|j|�dS)Nr5)r9�	operatorsr3r*rA)r#r$r%r+r+r,�
visit_Operand�szCodeGenerator.visit_OperandcCsT|jjr|�d�|�d�|�|j|�|�d|j�d��|jjrP|�d�dS)Nz(await auto_await(zenvironment.getattr(z, r6z)))r7r�r9r*r$ra)r#r$r%r+r+r,�
visit_Getattr�s

zCodeGenerator.visit_GetattrcCs�t|jtj�r@|�|j|�|�d�|�|j|�|�d�n^|jjrR|�d�|�d�|�|j|�|�d�|�|j|�|�d�|jjr�|�d�dS)Nr�r�z(await auto_await(zenvironment.getitem(z, r6z)))	rFr�r
�Slicer*r$r9r7r�)r#r$r%r+r+r,�
visit_Getitem�s




zCodeGenerator.visit_GetitemcCs`|jdk	r|�|j|�|�d�|jdk	r:|�|j|�|jdk	r\|�d�|�|j|�dS)Nr.)�startr*r9�stopr�)r#r$r%r+r+r,�visit_Slice�s




zCodeGenerator.visit_Slice)r$r%�	is_filterr ccs|jjr|�d�|r@|�|j|j�d��|jj�|j�}n(|�|j|j�d��|jj�|j�}|dkr�|js�|r~dnd}|�d|�d|j�d�|j	�t
jdt
jd	t
jd
i�t
�
|��}|dk	r�|�|�d��dV|�||�|�d�|jj�r
|�d�dS)
Nzawait auto_await(r4r<r-zNo z named rr�zcontext.eval_ctxr7z, r6)r7r�r9r�rArNr�r|r�r�rr�rMrOr�)r#r$r%rzr�Z	type_namerPr+r+r,�_filter_test_common�s*



z!CodeGenerator._filter_test_commonc	Cs�|�||d��x|jdk	r*|�|j|�nX|jjrP|�d|j�d|j�d��n2|jjrn|�d|j�d��n|�d|j�d��WdQRXdS)NTz(Markup(concat(z.)) if context.eval_ctx.autoescape else concat(z))zMarkup(concat(zconcat(r6)r{r$r*r(r)r9rvr�)r#r$r%r+r+r,r�s
zCodeGenerator.visit_Filterc	Cs,|�||d��|�|j|�WdQRXdS)NF)r{r*r$)r#r$r%r+r+r,r�szCodeGenerator.visit_Testcsl����dd����fdd�}��d����j����d����j����d�|���d�dS)N)r cs8�jdk	r���j��dS��d�����d��dS)Nz1cond_expr_undefined("the inline if-expression on z6 evaluated to false and no else section was defined."))Zexpr2r*r9r�r+)r%r$r#r+r,�write_expr2s

z1CodeGenerator.visit_CondExpr.<locals>.write_expr2r4z if z else r6)r�r9r*Zexpr1r-)r#r$r%r|r+)r%r$r#r,�visit_CondExprs


zCodeGenerator.visit_CondExpr)r$r%r8r cCs�|jjr|�d�|jjr&|�d�n
|�d�|�|j|�|rJddind}|jr\ddini}|jrnddini}|r�|j|f|�n|s�|r�t	|f|�}|�
|||�|�d�|jjr�|�d�dS)Nzawait auto_await(zenvironment.call(context, z
context.call(r�Z
_loop_varsZ_block_varsr6)r7r�r9r8r*r$rzr{r�r`r�)r#r$r%r8r�Zloop_kwargsZblock_kwargsr+r+r,r90s"


zCodeGenerator.visit_CallcCs"|�|jd�|�|j|�dS)Nr�)r9r�r*rL)r#r$r%r+r+r,�
visit_KeywordGszCodeGenerator.visit_KeywordcCs&|�d�|�|j|�|�d�dS)NzMarkup(r6)r9r*rA)r#r$r%r+r+r,�visit_MarkSafeMs
zCodeGenerator.visit_MarkSafecCs&|�d�|�|j|�|�d�dS)Nz6(Markup if context.eval_ctx.autoescape else identity)(r6)r9r*rA)r#r$r%r+r+r,�visit_MarkSafeIfAutoescapeRs
z(CodeGenerator.visit_MarkSafeIfAutoescapecCs|�d|j�dS)Nzenvironment.)r9rA)r#r$r%r+r+r,�visit_EnvironmentAttributeYsz(CodeGenerator.visit_EnvironmentAttributecCs|�d|j�d|j���dS)Nzenvironment.extensions[z].)r9Z
identifierrA)r#r$r%r+r+r,�visit_ExtensionAttribute^sz&CodeGenerator.visit_ExtensionAttributecCs|�|j|j�dS)N)r9r�r)r#r$r%r+r+r,�visit_ImportedNamecsz CodeGenerator.visit_ImportedNamecCs|�|j�dS)N)r9rA)r#r$r%r+r+r,�visit_InternalNamefsz CodeGenerator.visit_InternalNamecCs|�d�dS)Nr�)r9)r#r$r%r+r+r,�visit_ContextReferenceisz$CodeGenerator.visit_ContextReferencecCs|�|�|��dS)N)r9r�)r#r$r%r+r+r,�visit_DerivedContextReferencensz+CodeGenerator.visit_DerivedContextReferencecCs|�d|�dS)N�continue)r�)r#r$r%r+r+r,�visit_ContinuesszCodeGenerator.visit_ContinuecCs|�d|�dS)N�break)r�)r#r$r%r+r+r,�visit_BreakvszCodeGenerator.visit_BreakcCs:|��}|j�|�|�|�|�|j|�|�|�dS)N)r�rtr�r�r�r�r�)r#r$r%�scope_framer+r+r,�visit_Scopeys

zCodeGenerator.visit_ScopecCs�|��}|�|�d|�|����|�|�d��|�|j|�|�|�|jdd�}|j�|�|�	|�|�
|j|�|�|�|�
�dS)Nz = z.vars = T)r�)r�r�r�r*r�r�r�rtr�r�r�r�r�r�)r#r$r%r�r�r+r+r,�visit_OverlayScope�s


z CodeGenerator.visit_OverlayScopec	Csxxr|jD]h}|�d|j�d��|�|j|�y|j�|j�}Wntjk
r^d|j_	YqXt
|j|j|�qWdS)Nzcontext.eval_ctx.z = T)�optionsr�r�r*rLrTr(r
rYr)�setattr)r#r$r%�keywordr]r+r+r,�visit_EvalContextModifier�sz'CodeGenerator.visit_EvalContextModifiercCsl|��}|j��}|�|�d��|�||�x|jD]}|�||�q6W|j�|�|�d|�d��dS)Nz = context.eval_ctx.save()zcontext.eval_ctx.revert(r6)r�r(Zsaver�r�r�r*Zrevert)r#r$r%Zold_ctx_nameZ	saved_ctxr[r+r+r,�visit_ScopedEvalContextModifier�s
z-CodeGenerator.visit_ScopedEvalContextModifier)NFT)F)r	)N)N)Nr)Nr)N)F)r�r�)N)F)�rlrmrnr/r�rZ�TextIOrUrk�propertyrErVr�r�r"rvr�r�r�r
�Noder�r�r�r�r�r9r�r�roZCallr�r��Mappingr0r�r�r�r�r�r�rprqr!rgr�r�r�r�r�r�r�r�r�r�r�r�r�rrr	rGrr�r�rrZIncluder%ZImportZ
FromImportr&r(r*ZForr4ZIfr6r7r;ZFilterBlockr=ZWithrBZExprStmtrCZ
NamedTuplerH�staticmethodrIrJrGrQrSr.rVrWrXZOutputr^ZAssignr_ZAssignBlockr`r�r�ZNSRefrbr rcrUrerfr"rgZDictrhr>Z	visit_AddZ	visit_SubZ	visit_MulZ	visit_DivZvisit_FloorDivZ	visit_PowZ	visit_ModZ	visit_AndZvisit_Orr@Z	visit_PosZ	visit_NegZ	visit_Notr2ZConcatrpZComparerqZOperandrsZGetattrrtZGetitemrvruryr�Iteratorr{r�r�ZCondExprr}r9ZKeywordr~ZMarkSaferZMarkSafeIfAutoescaper�ZEnvironmentAttributer�ZExtensionAttributer�rr�ZInternalNamer�ZContextReferencer�ZDerivedContextReferencer�ZContinuer�ZBreakr�ZScoper�ZOverlayScoper�ZEvalContextModifierr�ZScopedEvalContextModifierr�r+r+r+r,r!,s
"A,4+Q	.u++4
2
0	O	


'
)NFT)Fr��typingr/�
contextlibr�	functoolsr�ior�	itertoolsrr�rr�Z
markupsaferrr�r
�
exceptionsrZ
idtrackingrr
rrrrr'rZutilsrrr<rZ
TYPE_CHECKINGZtyping_extensionsZter7rZTypeVarrFr0rrrr2rZr=r>r?r@rGr�r�rUrKrMr�r��Setrfrgr"�RuntimeErrorrdr�rcrZr�r!r+r+r+r,�<module>sd" &
S

?>