Hacked By AnonymousFox
B
�:�`, � @ 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 � �|dd� t� | _d S )Nz<introspection>)�super�__init__�set�undeclared_identifiers)�selfr )� __class__� �</opt/alt/python37/lib/python3.7/site-packages/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 � �|� x<|jj�� D ],\}\}}|dkr|| jjkr| j�|� 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�}|�| � |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 �visitr
)r% Zcodegenr r r �find_undeclared_variables! s
r'