U aG‘\ôã@sPdZddlmZddlmZddlmZmZGdd„deƒZdd„Z d d „Z d S) a5 jinja2.meta ~~~~~~~~~~~ This module implements various functions that exposes information about templates that might be interesting for various kinds of applications. :copyright: (c) 2017 by the Jinja Team, see AUTHORS for more details. :license: BSD, see LICENSE for more details. é)Únodes)Ú CodeGenerator)Ú string_typesÚ iteritemsc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚTrackingCodeGeneratorz.We abuse the code generator for introspection.cCst ||dd¡tƒ|_dS)Nz)rÚ__init__ÚsetÚundeclared_identifiers)ÚselfÚ environment©r ú-/usr/lib/python3/dist-packages/jinja2/meta.pyrs ÿzTrackingCodeGenerator.__init__cCsdS)z Don't write.Nr )r Úxr r r ÚwriteszTrackingCodeGenerator.writecCs>t ||¡t|jjƒD] \}\}}|dkr|j |¡qdS)z$Remember all undeclared identifiers.ZresolveN)rÚ enter_framerZsymbolsÚloadsr Úadd)r ÚframeÚ_ÚactionZparamr r r rs z!TrackingCodeGenerator.enter_frameN)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrr r r r rsrcCst|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) == 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. )rr Zvisitr )ÚastZcodegenr r r Úfind_undeclared_variables$s  rccsä| tjtjtjtjf¡D]Ä}t|jtjƒs€t|jtj tj fƒrx|jj D],}t|tjƒrnt|j t ƒrt|j VqHdVqHqdVqt|jj t ƒrš|jj Vqt|tjƒrØt|jj ttfƒrØ|jj D]}t|t ƒrÀ|VqÀqdVqdS)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_allrZExtendsZ FromImportZImportZIncludeÚ isinstanceÚtemplateZConstZTupleZListÚitemsÚvaluerÚtupleÚlist)rZnodeZ template_namer r r Úfind_referenced_templates<s*ÿ        ÿ   r"N) rZjinja2rZjinja2.compilerrZjinja2._compatrrrrr"r r r r Ús