Files
intellecton/venv/lib/python3.12/site-packages/jinja2/__pycache__/meta.cpython-312.pyc
T

54 lines
5.4 KiB
Plaintext
Raw Normal View History

Ë
j-ãóÖdZddlZddlmZddlmZddlmZejrddl m
Z
Gdd e«Z d
ejd ejefd Zej ej"ej$ej&fZej*ej ej"ej$ej&fZd
ejd ej.ej0efd
Zy)z_Functions that expose information about templates that might be
interesting for introspection.
é)Únodes)Ú
CodeGenerator)ÚFrame)Ú EnvironmentcóHeZdZdZd ˆfd ZdeddfdZdeddfˆfd ZˆxZ S)
ÚTrackingCodeGeneratorz.We abuse the code generator for introspection.ÚreturnNcóFt||dd«t«|_y)Nz<introspection>)ÚsuperÚ__init__ÚsetÚundeclared_identifiers)ÚselfÚ environmentÚ __class__s €úN/home/antigravity/intellecton/venv/lib/python3.12/site-packages/jinja2/meta.pyr
zTrackingCodeGenerator.__init__s ø€Ü
јÐ&7Ð9JÔKÜ25³%ˆÕÚxcóy)z Don't write.N©)rrs rÚwritezTrackingCodeGenerator.writesrÚframecóöt||«|jjj «D]B\}\}}|dk(sŒ||j
j vsŒ(|jj|«ŒDy)z$Remember all undeclared identifiers.ÚresolveN) r Ú enter_frameÚsymbolsÚloadsÚitemsrÚglobalsrÚadd)rrÚactionÚparamrs €rrz!TrackingCodeGenerator.enter_framesjø€ä
ј"à"'§-¡-×"5Ñ"5×";Ñ";Ó"=ò ˆA‰˜Ø˜Ó" u°D×4DÑ4D×4LÑ4LÒ'LØ×+×Õ 7r)rrr
N)
Ú__name__Ú
__module__Ú __qualname__Ú__doc__r
ÚstrrrrÚ
__classcell__)rs@rr r s6ø„Ù˜tóðð7¨4÷7rr Úastr
cóft|j«}|j|«|jS)aReturns 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) == {'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)r+Úcodegens rÚfind_undeclared_variablesr/"s*ô&$ C§O¡OÓ4€GØ ‡MMØ × )rc#óÀK|jt«D]A}|j}t|tj
«s‰t|tj tjf«rZ|jD]J}t|tj
«r*t|jt«sŒ8|jŒGdŒLndŒ³t|jt«r|jŒÜt|tj«rHt|jttf«r(|jD]}t|t«sŒ|ŒŒ>dŒDy­w)abFinds all the referenced templates from the AST. This will return an
iterator over all the hardcoded template extensions, inclusions and
imports. If dynamic inheritance or inclusion is used, `None` will be
yielded.
>>> from jinja2 import Environment, meta
>>> env = Environment()
>>> ast = env.parse('{% extends "layout.html" %}{% include helper %}')
>>> list(meta.find_referenced_templates(ast))
['layout.html', None]
This function is useful for dependency tracking. For example if you want
to rebuild parts of the website after a layout template has changed.
N)Úfind_allÚ
_ref_typesÚtemplateÚ