fb4dZddlZddlZddlZddlZddlmZddlmZddlm Z ddlm Z ddl m Z ddl mZd d lmZd d lmZd d lmZd d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlm Z d dlm!Z!d dlm"Z"d dlm#Z#d dlm$Z$d dl%m&Z&d dl%m'Z'd dl%m(Z(d d l%m)Z)d d!l%m*Z*d d"l+m,Z,d d#l+m-Z-d d$l+m.Z.d d%lm/Z/d d&l0m1Z1d d'l2m3Z3d d(l2m4Z4d d)l2m5Z5d d*l6m7Z7d d+l6m8Z8d d,l6m9Z9d d-l6m:Z:d d.l6m;Z;d d/l6mePfd?ffd@ZQdAejejejejfd;ejejejd>ePfd?ffdBZRdCd5dDejejePejdEfd;ejePdEffdFZVdPdGZWGdHd5ZXGdId?ZYGdJdKZZGdLdMZ[GdNdOZ\eYeX_]y)QzKClasses for managing templates and their runtime and compile time options. N)ChainMap) lru_cache)partial)reduce)CodeType)Markup)nodes) CodeGenerator)generate)BLOCK_END_STRING)BLOCK_START_STRING)COMMENT_END_STRING)COMMENT_START_STRING)DEFAULT_FILTERS)DEFAULT_NAMESPACE)DEFAULT_POLICIES) DEFAULT_TESTS)KEEP_TRAILING_NEWLINE)LINE_COMMENT_PREFIX)LINE_STATEMENT_PREFIX) LSTRIP_BLOCKS)NEWLINE_SEQUENCE) TRIM_BLOCKS)VARIABLE_END_STRING)VARIABLE_START_STRING)TemplateNotFound)TemplateRuntimeError)TemplatesNotFound)TemplateSyntaxError)UndefinedError get_lexer)Lexer) TokenStream) EvalContext)Parser)Context) new_context) Undefined)_PassArg)concat)consume) import_string) internalcodeLRUCache)missing) BytecodeCache) Extension) BaseLoader _env_bound Environment)bound )maxsizeclsargsreturnc||}d|_|S)a Return a new spontaneous environment. A spontaneous environment is used for templates created directly rather than through an existing environment. :param cls: Environment class to create. :param args: Positional arguments passed to environment. T)shared)r;r<envs [/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/jinja2/environment.pyget_spontaneous_environmentrBDs t*CCJ Jsizezweakref.ref[t.Any]Templatec2|dk(ry|dkriSt|S)z*Return the cache class for the given size.rNr0)rDs rA create_cacherGRs$ qy ax D>rCcachecX|yt|turiSt|jS)z(Create an empty copy of the given cache.N)typedictr1capacity)rHs rA copy_cacherM_s, } E{d ENN ##rC environment extensionsr4ci}|D]W}t|tr0tjtjdt |}||||j <Y|S)zuLoad the extensions from the list and bind it to the environment. Returns a dict of instantiated extensions. r4) isinstancestrtcastTyper. identifier)rNrOresult extensions rAload_extensionsrYlsWF i %qvvk2M)4LMI'0'=y##$  MrCct|jtsJd|j|jcxk7r|j k7sJdJd|j dvsJd|S)z*Perform a sanity check on the environment.z5'undefined' must be a subclass of 'jinja2.Undefined'.z   z8'newline_sequence' must be one of '\n', '\r\n', or '\r'.) issubclass undefinedr*block_start_stringvariable_start_stringcomment_start_stringnewline_sequence)rNs rA_environment_config_checkrd~s y ?>?  &&  , , ,  + + ,FF F ,FF F ,  ' ', FF F  rCc/eZdZUdZdZdZdZejde d<dZ e Z ejde d<djZeZejee d<ejd e d <eeeeeeeeeeeed d edddd d ddfdededededededejedejede de ddde dejBejDeejdfde dejedejejFd ejHfd!ejDe ejFejege ffd"ejd#d$e%d%e d&ejd'd(e f,d)Z&d*ejDeejdfd+dfd,Z'd-ejHd+dfd.Z(e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)e)dfdededededededejedejede de ddde dejBejDeejdfde dejedejejFd ejHfd!ejDe ejFejege ffd"ejd#d$e%d%e d&ejd'd(e d+df.d/Z*e+d+e,fd0Z-d+ej\dfd1Z/d2ejHd3ejDeejHfd+ejDejHeffd4Z0d2ejHd5ed+ejHfd6Z1d7ejDeefd8ejHd9ejejBejHd:ejejdeejHfd;ejedZ4 dld7ed8ejHd9ejejBejHd:ejejdeejHfd;ejed dmdAed7ejedBejedGejed+e?f dHZ@ dndAe8jrd7ejedBejedIe d+ef dJZAdAedBed+eBfdKZCeDj dodAejDee8jrfd7ejedBejedLdMdIe d+eBf dNZFeDj dpdAejDee8jrfd7ejedBejedLdOdIe d+ef dPZFe7 dodAejDee8jrfd7ejedBejedLe dIe d+ejDeeBff dQZF dqdAedRe d+dSfdTZG drdUejDedVfdejejedWejejFege fdXejedYejejFegdfdZe d+dfd[ZI dmdejejedWejejFege fd+ejefd\ZKdsdAejed+d]fd^ZLd_ed`ed+efdaZMe7d7edbejejeejHfd+d fdcZOe7 dmd7ejDed fd`ejedbejejeejHfd+d fddZPe7 dmdeejejDed fd`ejedbejejeejHfd+d fdfZRe7 dmdgejDed ejejDed ffd`ejedbejejeejHfd+d fdhZS dmdAejDee8jrfdbejejeejHfd ejejd d+d fdiZTdjejejeejHfd+ejeejHffdkZUy)tr7aThe core component of Jinja is the `Environment`. It contains important shared variables like configuration, filters, tests, globals and others. Instances of this class may be modified if they are not shared and if no template was loaded so far. Modifications on environments after the first template was loaded will lead to surprising effects and undefined behavior. Here are the possible initialization parameters: `block_start_string` The string marking the beginning of a block. Defaults to ``'{%'``. `block_end_string` The string marking the end of a block. Defaults to ``'%}'``. `variable_start_string` The string marking the beginning of a print statement. Defaults to ``'{{'``. `variable_end_string` The string marking the end of a print statement. Defaults to ``'}}'``. `comment_start_string` The string marking the beginning of a comment. Defaults to ``'{#'``. `comment_end_string` The string marking the end of a comment. Defaults to ``'#}'``. `line_statement_prefix` If given and a string, this will be used as prefix for line based statements. See also :ref:`line-statements`. `line_comment_prefix` If given and a string, this will be used as prefix for line based comments. See also :ref:`line-statements`. .. versionadded:: 2.2 `trim_blocks` If this is set to ``True`` the first newline after a block is removed (block, not variable tag!). Defaults to `False`. `lstrip_blocks` If this is set to ``True`` leading spaces and tabs are stripped from the start of a line to a block. Defaults to `False`. `newline_sequence` The sequence that starts a newline. Must be one of ``'\r'``, ``'\n'`` or ``'\r\n'``. The default is ``'\n'`` which is a useful default for Linux and OS X systems as well as web applications. `keep_trailing_newline` Preserve the trailing newline when rendering templates. The default is ``False``, which causes a single newline, if present, to be stripped from the end of the template. .. versionadded:: 2.7 `extensions` List of Jinja extensions to use. This can either be import paths as strings or extension classes. For more information have a look at :ref:`the extensions documentation `. `optimized` should the optimizer be enabled? Default is ``True``. `undefined` :class:`Undefined` or a subclass of it that is used to represent undefined values in the template. `finalize` A callable that can be used to process the result of a variable expression before it is output. For example one can convert ``None`` implicitly into an empty string here. `autoescape` If set to ``True`` the XML/HTML autoescaping feature is enabled by default. For more details about autoescaping see :class:`~markupsafe.Markup`. As of Jinja 2.4 this can also be a callable that is passed the template name and has to return ``True`` or ``False`` depending on autoescape should be enabled by default. .. versionchanged:: 2.4 `autoescape` can now be a function `loader` The template loader for this environment. `cache_size` The size of the cache. Per default this is ``400`` which means that if more than 400 templates are loaded the loader will clean out the least recently used template. If the cache size is set to ``0`` templates are recompiled all the time, if the cache size is ``-1`` the cache will not be cleaned. .. versionchanged:: 2.8 The cache size was increased to 400 from a low 50. `auto_reload` Some loaders load templates from locations where the template sources may change (ie: file system or database). If ``auto_reload`` is set to ``True`` (default) every time a template is requested the loader checks if the source changed and if yes, it will reload the template. For higher performance it's possible to disable that. `bytecode_cache` If set to a bytecode cache object, this object will provide a cache for the internal Jinja bytecode so that templates don't have to be parsed if they were not changed. See :ref:`bytecode-cache` for more information. `enable_async` If set to true this enables async template execution which allows using async functions and generators. FN linked_tor code_generator_class context_classrEtemplate_classTir`block_end_stringravariable_end_stringrbcomment_end_stringline_statement_prefixline_comment_prefix trim_blocks lstrip_blocksrcte.Literal['\n', '\r\n', '\r']keep_trailing_newlinerOr4 optimizedr_finalize. autoescapeloaderr5 cache_size auto_reloadbytecode_cacher3 enable_asyncc<||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ ||_ ||_ ||_||_t!j"|_t'j"|_t+j"|_||_t1||_||_||_t9j"|_t=|| |_||_ tC|yN)"r`rlrarmrbrnrorprqrrrcrtr_rurvrwrcopyfiltersrtestsrglobalsrxrGrHr{rzrpoliciesrYrOis_asyncrd)selfr`rlrarmrbrnrorprqrrrcrtrOrur_rvrwrxryrzr{r|s rA__init__zEnvironment.__init__&s J#5 0%:"#6 $8!"4%:"#6 &* 0%:"-6"  $'++- "'') (--/  !*- ,&)--/ *$ ;$ !$'rCrXr=cP|jjt||gy)z\Adds an extension after the environment was created. .. versionadded:: 2.5 N)rOupdaterY)rrXs rA add_extensionzEnvironment.add_extensionrs ti[ABrC attributesc h|jD]\}}t||rt|||!y)zAdd the items to the instance of the environment if they do not exist yet. This is used by :ref:`extensions ` to register callbacks and configuration values without breaking inheritance. N)itemshasattrsetattr)rrkeyvalues rAextendzEnvironment.extendys1 %**,JC4%c5)-rCctt}|d=|d=|d=|d=tj|j}|j j |j d|_||_|jD]\}}|tust||||turt||_ nt|j|_ i|_|jjD]#\}}|j!||j|<%| tur%|jj t#|| |tur||_t'|S)aCreate a new overlay environment that shares all the data with the current environment except for cache and the overridden attributes. Extensions cannot be removed for an overlayed environment. An overlayed environment automatically gets all the extensions of the environment it is linked to plus optional extra extensions. Creating overlays should happen after the initial environment was set up completely. Not all attributes are truly linked, some are just copied over so modifications on the original environment may not shine through. .. versionchanged:: 3.1.2 Added the ``newline_sequence``,, ``keep_trailing_newline``, and ``enable_async`` parameters to match ``__init__``. rryrOr|T)rKlocalsobject__new__ __class____dict__r overlayedrfrr2rrGrHrMrObindrYrrd)rr`rlrarmrbrnrorprqrrrcrtrOrur_rvrwrxryrzr{r|r<rvrrs rAoverlayzEnvironment.overlays#PFH~ L$|,d<.@$~BV ^^DNN + 4==)  **,JCG#C'' W $#J/BH!$**-BH ////1JC!&BBMM# 2 W $ MM Z!@ A w &&BK(,,rCct|S)zThe lexer for this environment.r"rs rAlexerzEnvironment.lexersrCc`tt|jjdS)z)Iterates over the extensions by priority.c|jSr~)priorityxs rAz-Environment.iter_extensions..s1::rC)r)itersortedrOvaluesrs rAiter_extensionszEnvironment.iter_extensionss"F4??1139MNOOrCobjargumentc ||S#tttf$r_t|tr9 t |} t ||cYS#t$rYnwxYw#t $rYnwxYw|j||cYSwxYw)z:Get an item or attribute of an object but prefer the item.rname)AttributeError TypeError LookupErrorrQrRgetattr Exceptionr_)rrrattrs rAgetitemzEnvironment.getitems :x=  ;7 :(C(x=D&sD11) !>>c>9 9 :sO$A: A AA: AA:AA: A!A: A!!A:9A: attributec t||S#t$rYnwxYw ||S#tttf$r|j ||cYSwxYw)zGet an item or attribute of an object but prefer the attribute. Unlike :meth:`getitem` the attribute *must* be a string. r)rrrrr_)rrrs rArzEnvironment.getattrs^ 3 * *    ;y> !;7 ;>>c >: : ;s  #'A  A rrr<kwargscontexteval_ctx is_filterc|r|j}d} n|j}d} |j|} | @d| d|d} t|tr |j t| t| |g||nd}||ni}tj| } | tjur$|td | d |jd |ne| tjur/|| |j}n t|}|jd |n$| tjur|jd || |i|S#t $r} | d| d} Yd} ~ t| d} ~ wwxYw) NfiltertestzNo z named .z (z-; did you forget to quote the callable name?)rkzAttempted to invoke a context z without context.r)rrgetrQr*_fail_with_undefined_errorrrr+from_objrinsert eval_contextrr&rN)rrrr<rrrrenv_map type_namefuncmsgepass_args rA_filter_test_commonzEnvironment._filter_test_commons llG IjjGI{{4  < {'$3C$ *U335's+ +&s+ +;!1r;!-2$$T* x'' '*4YK?PQ KK7 # .. .&&//H*40H KK8 $ -- - KK4 T$V$$7!U EA3&STC&s+ +Us D:: EEEc 0|j||||||dS)a/Invoke a filter on a value the same way the compiler does. This might return a coroutine if the filter is running from an environment in async mode and the filter supports async execution. It's your responsibility to await this if needed. .. versionadded:: 2.7 Trrrrr<rrrs rA call_filterzEnvironment.call_filter%s&"'' %vw$  rCc 0|j||||||dS)aInvoke a test on a value the same way the compiler does. This might return a coroutine if the test is running from an environment in async mode and the test supports async execution. It's your responsibility to await this if needed. .. versionchanged:: 3.0 Tests support ``@pass_context``, etc. decorators. Added the ``context`` and ``eval_ctx`` parameters. .. versionadded:: 2.7 Frrs rA call_testzEnvironment.call_test:s&*'' %vw%  rCsourcefilenamecl |j|||S#t$r|j|YywxYw)aParse the sourcecode and return the abstract syntax tree. This tree of nodes is used by the compiler to convert the template into executable source- or bytecode. This is useful for debugging or to extract information from templates. If you are :ref:`developing Jinja extensions ` this gives you a good overview of the node tree generated. rN)_parser handle_exceptionrrrrs rAparsezEnvironment.parseSs: 1;;vtX6 6" 1  ! ! ! 0 1s 33c:t||||jS)z8Internal parsing function used by `parse` and `compile`.)r'rrs rArzEnvironment._parsegsdFD(399;;rCct|} |jj|||S#t$r|j |YywxYw)aLex the given sourcecode and return a generator that yields tokens as tuples in the form ``(lineno, token_type, value)``. This can be useful for :ref:`extension development ` and debugging templates. This does not perform preprocessing. If you want the preprocessing of the extensions to be applied you have to filter source through the :meth:`preprocess` method. rN)rRr tokeniterr rrs rAlexzEnvironment.lexmsKV 1::''h? ?" 1  ! ! ! 0 1s*AAcVtfd|jt|S)zPreprocesses the source with all extensions. This is automatically called for all parsing and compiling methods but *not* for :meth:`lex` because there you usually only want the actual source tokenized. c*|j|Sr~) preprocess)srrrs rArz(Environment.preprocess..sax8rC)rrrRrs ``rArzEnvironment.preprocesss( 8  " K  rCstatec|j|||}|jj||||}|jD]1}|j |}t |t r%t |||}3|S)zCalled by the parser to do the preprocessing and filtering for all the extensions. Returns a :class:`~jinja2.lexer.TokenStream`. )rrtokenizer filter_streamrQr%)rrrrrstreamexts rA _tokenizezEnvironment._tokenizesrx8$$VT8UC'')C&&v.Ffk2$VT8< *  rC defer_initc8t||||||jS)z|Internal hook that can be overridden to hook a different generate method in. .. versionadded:: 2.5 )rru)r ru)rrrrrs rA _generatezEnvironment._generates'    !nn   rCct||dS)z{Internal hook that can be overridden to hook a different compile method in. .. versionadded:: 2.5 exec)compile)rrrs rA_compilezEnvironment._compiles vx00rCrawzte.Literal[False]cyr~rkrrrrrrs rArzEnvironment.compilesrCzte.Literal[True]cyr~rkrs rArzEnvironment.compilesrCcd} t|tr|}|j|||}|j||||}|r|S|d}|j ||S#t $r|j |YywxYw)aCompile a node or template source code. The `name` parameter is the load name of the template after it was joined using :meth:`join_path` if necessary, not the filename on the file system. the `filename` parameter is the estimated filename of the template on the file system. If the template came from a database or memory this can be omitted. The return value of this method is a python code object. If the `raw` parameter is `True` the return value will be a string with python code equivalent to the bytecode returned otherwise. This method is mainly used internally. `defer_init` is use internally to aid the module code generator. This causes the generated code to be able to import without the global environment variable to be set. .. versionadded:: 2.4 `defer_init` parameter added. N)rz