/usr/local/lib/python3.6/site-packages/jinja2/__pycache__
Edit: /usr/local/lib/python3.6/site-packages/jinja2/__pycache__/meta.cpython-36.pyc (3746B)
3
^TBg, ã @ sº d Z ddlZddlmZ ddlmZ ddlmZ ejrBddl m
Z
G dd „ d eƒZejej
e d
œdd„ZejejejejfZejejejejejf Zejejeje d
œd
d„ZdS )z_Functions that expose information about templates that might be
interesting for introspection.
é Né )Únodes)Ú
CodeGenerator)ÚFrame)ÚEnvironmentc sL e Zd ZdZdddœ‡ fdd„Zeddœdd „Zedd
œ‡ fdd„Z‡ Z S )
ÚTrackingCodeGeneratorz.We abuse the code generator for introspection.r N)ÚenvironmentÚreturnc s t ƒ j|ddƒ tƒ | _d S )Nz
)ÚsuperÚ__init__ÚsetÚundeclared_identifiers)Úselfr )Ú __class__© ú-/tmp/pip-build-0s3hx122/Jinja2/jinja2/meta.pyr s zTrackingCodeGenerator.__init__)Úxr c C s dS )zDon't write.Nr )r r r r r Úwrite s zTrackingCodeGenerator.write)Úframer c sN t ƒ j|ƒ x<|jjjƒ D ],\}\}}|dkr|| jjkr| jj|ƒ qW dS )z$Remember all undeclared identifiers.ÚresolveN) r
Úenter_frameÚsymbolsÚloadsÚitemsr Úglobalsr
Úadd)r r Ú_ÚactionÚparam)r r r r s z!TrackingCodeGenerator.enter_frame)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r Ústrr r r Ú
__classcell__r r )r r r s r )Úastr c C s t | jƒ}|j| ƒ |jS )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) == {'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 Zvisitr
)r% Zcodegenr r r Úfind_undeclared_variables! s
r&