f-dZddlZddlmZddlmZddlmZejrddl m Z Gdd eZ 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. N)nodes) CodeGenerator)Frame) EnvironmentcHeZdZdZd fd ZdeddfdZdeddffd ZxZ S) TrackingCodeGeneratorz.We abuse the code generator for introspection.returnNcFt||ddt|_y)Nz)super__init__setundeclared_identifiers)self environment __class__s T/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/jinja2/meta.pyr zTrackingCodeGenerator.__init__s  &79JK25%#xcy)z Don't write.N)rrs rwritezTrackingCodeGenerator.writesrframect|||jjj D]B\}\}}|dk(s||j j vs(|jj|Dy)z$Remember all undeclared identifiers.resolveN) r enter_framesymbolsloadsitemsrglobalsradd)rr_actionparamrs rrz!TrackingCodeGenerator.enter_framese E""'--"5"5";";"= A"uD4D4D4L4L'L++//6#>r)rrr N) __name__ __module__ __qualname____doc__r strrrr __classcell__)rs@rr r s688st77477rr astr cft|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 rvisitr)r+codegens rfind_undeclared_variablesr/"s*&$COO4G MM#  ) ))rc#K|jtD]A}|j}t|tj st|tj tjfrZ|jD]J}t|tj r*t|jts8|jGdLndt|jtr|jt|tjrHt|jttfr(|jD]}t|ts|>dDyw)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_typestemplate isinstancerConstTupleListrvaluer)Includetuplelist)r+noder3 template_names rfind_referenced_templatesr>>s" Z(#}}(EKK0(U[[%**$=>%-^^M"-=%m&9&93?"/"5"55# &4  hnnc *.. emm , NNUDM2 "* mS1''"0 JC)sB-E0BEE)r(typingtrcompilerrr TYPE_CHECKINGrrr TemplateSetr)r/Extends FromImportImportr9r2Union_RefTypeIteratorOptionalr>rrrrMs#??(7M7&*5>>*aeeCj*0mmU--u||U]] K 775==%"2"2ELL%--O P25>>2ajjC6Q2r