Your IP : 18.219.127.59


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__/meta.cpython-37.opt-1.pyc

B

�:�`,�@s�dZddlZddlmZddlmZddlmZejrBddl	m
Z
Gdd	�d	e�Zejej
ed
�dd�ZejejejejfZejejejejejfZejejejed
�d
d�ZdS)z_Functions that expose information about templates that might be
interesting for introspection.
�N�)�nodes)�
CodeGenerator)�Frame)�EnvironmentcsLeZdZdZddd��fdd�Zedd�dd	�Zedd
��fdd�Z�Z	S)
�TrackingCodeGeneratorz.We abuse the code generator for introspection.rN)�environment�returncst��|dd�t�|_dS)Nz<introspection>)�super�__init__�set�undeclared_identifiers)�selfr)�	__class__��</opt/alt/python37/lib/python3.7/site-packages/jinja2/meta.pyrszTrackingCodeGenerator.__init__)�xr	cCsdS)zDon't write.Nr)rrrrr�writeszTrackingCodeGenerator.write)�framer	csNt��|�x<|jj��D],\}\}}|dkr||jjkr|j�|�qWdS)z$Remember all undeclared identifiers.ZresolveN)	r
�enter_frameZsymbols�loads�itemsr�globalsr
�add)rr�_�actionZparam)rrrrsz!TrackingCodeGenerator.enter_frame)
�__name__�
__module__�__qualname__�__doc__r�strrrr�
__classcell__rr)rrrsr)�astr	cCst|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.
    )rrZvisitr
)r"Zcodegenrrr�find_undeclared_variables!s

r#ccs�x�|�t�D]�}|j}t|tj�svt|tjtjf�rnx>|jD],}t|tj�rbt|j	t
�rh|j	Vq<dVq<WqdVqt|j	t
�r�|j	Vqt|tj�r�t|j	tt
f�r�x&|j	D]}t|t
�r�|Vq�WqdVqWdS)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)Zfind_all�
_ref_types�template�
isinstancerZConstZTupleZListr�valuer �Include�tuple�list)r"Znoder%Z
template_namerrr�find_referenced_templates=s&


r+)r�typing�t�rZcompilerrrZ
TYPE_CHECKINGrrr�Template�Setr r#ZExtendsZ
FromImportZImportr(r$ZUnionZ_RefType�IteratorZOptionalr+rrrr�<module>s

?>