lfndZddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z dd l m Z dd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%dd lm&Z&dd!lm'Z'dd"lm(Z(dd#l)m*Z*dd$l)m+Z+dd%l)m,Z,dd&l)m-Z-dd'l)m.Z.dd(l/m0Z0dd)l/m1Z1dd*l m2Z2dd+l3m4Z4dd,l5m6Z6dd-l5m7Z7dd.l5m8Z8dd/l9m:Z:dd0l9m;Z;dd1l9mZ>dd4l9m?Z?dd5l9m@Z@e?d6ZAd7ZBd8ZCd9ZDd:ZEd;ZFd<ZGGd=d>eHZIGd?d@eHZJeGdAdBeHZKGdCdDeHZLe GdEdFeHZMeJeI_NdS)GzKClasses for managing templates and their runtime and compile time options. N)partial)reduce)Markup)nodes)encode_filename)implements_iterator)implements_to_string) iteritems)PY2)PYPY)reraise) string_types) text_type) 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) TokenStream) EvalContext)Parser)Context) new_context) Undefined)concat)consume)have_async_gen) import_string) internalcodeLRUCache)missing cv||f} t|S#t$r||xt|<}d|_|cYSwxYw)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)_spontaneous_environmentsKeyErrorshared)clsargskeyenvs r/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/jinja2/environment.pyget_spontaneous_environmentrAAs^ +C(-- /2sDz9!#&  s "88c@|dkrdS|dkriSt|S)z*Return the cache class for the given size.rNr4)sizes r@ create_cacherDSs* qyyt axx D>>cb|dSt|turiSt|jS)z(Create an empty copy of the given cache.N)typedictr5capacity)caches r@ copy_cacherK\s2 }t e   EN # ##rEci}|D]9}t|trt|}||||j<:|S)zwLoad the extensions from the list and bind it to the environment. Returns a dict of instantiated environments. ) isinstancerr2 identifier) environment extensionsresult extensions r@load_extensionsrSesVF>> i . . 1%i00I'0y'='=y#$$ MrEc||z}t|tr5 |n#t$r}|d|d}Yd}~nd}~wwxYwt |)Nz (z-; did you forget to quote the callable name?))rMr._fail_with_undefined_error Exceptionr$)stringnamemsges r@fail_for_missing_callabler[qs 4-C$ ""S S  + + - - - - S S SKN33PQPQPQRCCCCCC S s # ##s1 A AA ct|jts Jd|j|jcxkr |jks nJd|jdvs Jd|S)z*Perform a sanity check on the environment.zGundefined must be a subclass of undefined because filters depend on it.z;block, variable and comment start strings must be different) z  z3newline_sequence set to unknown line ending string.) issubclass undefinedr.block_start_stringvariable_start_stringcomment_start_stringnewline_sequence)rOs r@_environment_sanity_checkre{s y  QQPQQ  &  , , , , ,  + , , , , ,E , , ,  ',   =     rEceZdZdZdZdZdZdZeZ e Z e e eeeeeeeeeeddedddddddfdZdZd Zeeeeeeeeeeeeeeeeeeefd Zeed Z d Z!dZ"dZ# d&dZ$d'dZ%e&d'dZ'dZ(d'dZ)d'dZ*d'dZ+d(dZ,dZ-e&d)dZ.d*dZ/ d+dZ0d'dZ1d,dZ2dZ3e&d Z4e&d'd!Z5e&d'd"Z6e&d'd#Z7d'd$Z8d%Z9dS)- EnvironmentaThe 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 you to take advantage of newer Python features. This requires Python 3.6 or later. FNTic||_||_||_||_||_||_||_||_| |_| |_ | |_ | |_ ||_ ||_ ||_||_t!j|_t'j|_t+j|_||_t1||_||_||_t9j|_t=|| |_||_ |j otB|_"|j"rddl#m$}tK|dS)Nr) asyncsupport)&rablock_end_stringrbvariable_end_stringrccomment_end_stringline_statement_prefixline_comment_prefix trim_blocks lstrip_blocksrdkeep_trailing_newliner` optimizedfinalize autoescapercopyfiltersrtestsrglobalsloaderrDrJbytecode_cache auto_reloadrpoliciesrSrP enable_asyncr1is_asyncrjre)selfrarkrbrlrcrmrnrorprqrdrrrPrsr`rtrurz cache_sizer|r{r~rjs r@__init__zEnvironment.__init__ sIJ#5 0%:"#6 $8!"4%:"#6 &* 0%:"#"  $'+-- "')) (-//  !*-- ,&)-// *$ ;;()` to register callbacks and configuration values without breaking inheritance. N)r hasattrsetattr)r attributesr>values r@extendzEnvironment.extendxsN $J// * *JC4%% *c5))) * *rEctt}|d=|d=|d=t|j}|j|jd|_||_t|D]\}}|turt||| |turt||_ nt|j |_ i|_t|jD]"\}}|||j|<#| tur(|jt#|| t%|S)agCreate 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. rrrPT)rHlocalsobject__new__ __class____dict__r overlayed linked_tor r6rrDrJrKrPbindrSre)rrarkrbrlrcrmrnrorprqrPrsr`rtrurzrr|r{r=rvr>rs r@overlayzEnvironment.overlays<BFHH~~ L$|,d<.@ ^^DN + + 4=)))  #D// ( (JCG##C''' W $ $#J//BHH!$*--BH #DO44 0 0JC!&BBM#   W $ $ M Z!@!@ A A A(,,,rEzThe lexer for this environment.)doccntt|jdS)z)Iterates over the extensions by priority.c|jSN)priorityxs r@z-Environment.iter_extensions..s1:rE)r>)itersortedrPvaluesrs r@iter_extensionszEnvironment.iter_extensionss/F4?11339M9MNNNOOOrEc, ||S#tttf$rrt|trC t |} t ||cYS#t$rYnwxYw#t$rYnwxYw|||cYSwxYw)z:Get an item or attribute of an object but prefer the item.objrX) AttributeError TypeError LookupErrorrMrstrgetattrrVr`)rrargumentattrs r@getitemzEnvironment.getitems :x=  ;7 : : :(L11 x==D&sD11111) !D>>c>99 9 9 9 :sP ,BA)AB A&#B%A&&B) A63B5A66BBc t||S#t$rYnwxYw ||S#tttf$r|||cYSwxYw)zGet an item or attribute of an object but prefer the attribute. Unlike :meth:`getitem` the attribute *must* be a bytestring. r)rrrrr`)rr attributes r@rzEnvironment.getattrs 3 ** *    D  ;y> !;7 ; ; ;>>c >:: : : : ;s +.AAc|j|}|td||gt|pdz}t |dddur(|t d|d|nnt |d ddur2|||j}nt|}|d|n)t |d ddur|d|||i|piS) aWInvokes a filter on a value the same way the compiler does it. Note that on Python 3 this might return a coroutine in case 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 Nzno filter named %rrh contextfilterFTz2Attempted to invoke context filter without contextrevalcontextfilterenvironmentfilter) rwgetr[listrr$inserteval_ctxr*)rrXrr=kwargscontextrfuncs r@ call_filterzEnvironment.call_filters(|%% < %&:D A A Awdjb))) 4% 0 0D 8 8*H KK7 # # # # T. 6 6$ > >&&/HH*400H KK8 $ $ $ $ T. 6 6$ > > KK4 tT,fl,,,rEcz|j|}|td|||g|pdRi|piS)zdInvokes a test on a value the same way the compiler does it. .. versionadded:: 2.7 Nzno test named %rrh)rxrr[)rrXrr=rrs r@ call_testzEnvironment.call_testsU z~~d## < %&8$ ? ? ?tE;TZR;;;V\r;;;rEc ||||S#t$r||YdSwxYw)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. sourceN)_parser&handle_exceptionrrrXfilenames r@parsezEnvironment.parse sX 1;;vtX66 6" 1 1 1  ! ! ! 0 0 0 0 0 0 1s  ==cdt|||t|S)z8Internal parsing function used by `parse` and `compile`.)r+rrrs r@rzEnvironment._parses*dFD/(*C*CDDJJLLLrEct|} |j|||S#t$r||YdSwxYw)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)rlexer tokeniterr&rrs r@lexzEnvironment.lexsk6"" 1:''h?? ?" 1 1 1  ! ! ! 0 0 0 0 0 0 1s- AAcntfd|t|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. c2||Sr) preprocess)srZrrXs r@rz(Environment.preprocess..3sax88rE)rrrrs ``r@rzEnvironment.preprocess-sA  8 8 8 8 8  " " f     rEc||||}|j||||}|D]=}||}t |t st |||}>|S)zCalled by the parser to do the preprocessing and filtering for all the extensions. Returns a :class:`~jinja2.lexer.TokenStream`. )rrtokenizer filter_streamrMr))rrrXrstatestreamexts r@ _tokenizezEnvironment._tokenize8sx88$$VT8UCC'')) = =C&&v..Ffk22 =$VT8<< rEc6t||||||jS)z|Internal hook that can be overridden to hook a different generate method in. .. versionadded:: 2.5 ) defer_initrs)rrs)rrrXrrs r@ _generatezEnvironment._generateDs/     !n     rEc$t||dS)z{Internal hook that can be overridden to hook a different compile method in. .. versionadded:: 2.5 exec)compile)rrrs r@_compilezEnvironment._compileSs vx000rEc@d} t|tr|}||||}|||||}|r|S|d}nt |}|||S#t $r||YdSwxYw)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