G[} b d Z ddlmZ ddlmZ ddlmZ ddlmZ G d de Zd Z d Z
d
S )z_Functions that expose information about templates that might be
interesting for introspection.
)nodes) iteritems)string_types)
CodeGeneratorc $ e Zd ZdZd Zd Zd ZdS )TrackingCodeGeneratorz.We abuse the code generator for introspection.c Z t j | |dd t | _ d S )Nz)r __init__setundeclared_identifiers)selfenvironments k/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/jinja2/meta.pyr
zTrackingCodeGenerator.__init__ s- t[2CEVWWW&)ee### c dS )zDon't write.N )r
xs r writezTrackingCodeGenerator.write s r c t j | | t |j j D ]6\ }\ }}|dk r(|| j j vr| j | 7dS )z$Remember all undeclared identifiers.resolveN) r enter_framer symbolsloadsr globalsr add)r
frame_actionparams r r z!TrackingCodeGenerator.enter_frame sw !$..."+EM,?"@"@ 7 7A""uD4D4L'L'L+//666 7 7r N)__name__
__module____qualname____doc__r
r r r r r r r sG 88, , , 7 7 7 7 7r r c b t | j }| | |j S )a Returns a set of all variables in the AST that will be looked up from
the context at runtime. Because at compile time it's not known which
variables will be used depending on the path the execution takes at
runtime, all variables are returned.
>>> from jinja2 import Environment, meta
>>> env = Environment()
>>> ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
>>> meta.find_undeclared_variables(ast) == set(['bar'])
True
.. admonition:: Implementation
Internally the code generator is used for finding undeclared variables.
This is good to know because the code generator might raise a
:exc:`TemplateAssertionError` during compilation and as a matter of
fact this function can currently raise that exception as well.
)r r visitr )astcodegens r find_undeclared_variablesr( s. &