lfw$dZddlZddlmZddlmZddlmZddlmZddlm Z dd l m Z dd l m Z dd l m Z dd l mZdd l mZddl mZddl mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z gdZ!eZ"dZ#dZ$dZ% d8d Z&Gd!d"e'Z(d#Z)Gd$d%e*Z+efd&Z,Gd'd(ee+Z-e j./e-Gd)d*e'Z0e Gd+d,Z1Gd-d.e'Z2eGd/d0e'Z3d9d1Z4Gd2d3e3Z5eGd4d5e3Z6eGd6d7e3Z7e3`8e5`8e6`8e7`8dS):z;The runtime functions and state used by compiled templates.N)chain) MethodType)escape)Markup) soft_unicode)abc)imap)implements_iterator)implements_to_string) iteritems)PY2) string_types) text_type)with_metaclass)TemplateNotFound)TemplateRuntimeError)UndefinedError) EvalContext)concat)evalcontextfunction) internalcode)missing) Namespace)object_type_repr) LoopContextTemplateReferenceMacrorrrrr markup_join unicode_join to_stringidentityrr Undefinedc|S)zLReturns its argument. Useful for certain things in the environment. xs n/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/jinja2/runtime.pyr"r"7s  Hcg}tt|}|D]Y}||t|dr2t dt ||cSZt|S)z@Concatenation that escapes if necessary and converts to unicode.__html__)r rappendhasattrrjoinrr)seqbufiteratorargs r(rr>s CL#&&H:: 3 3 # # :#;;##E#x$8$899 9 9 9 : #;;r)cFttt|S)z4Simple args to unicode conversion and concatenation.)rr r)r0s r(r r Is $y#&& ' ''r)c|i}|r|}nt|pdfi|}|r4|rt|}t|D]\}} | tur| ||<|||||S)z%Internal helper for context creation.Nr%)dictr r context_class) environment template_nameblocksvarssharedglobalslocalsparentkeyvalues r( new_contextrBNs | -gm,,t,, $  "&\\F#F++ $ $JCG###s  $ $[&- P PPr)c$eZdZdZdZdZdZdS)rzThe `self` in templates.c||_dSN)_TemplateReference__context)selfcontexts r(__init__zTemplateReference.__init__ls  r)cT|jj|}t||j|dSNr)rFr:BlockReference)rGnamer:s r( __getitem__zTemplateReference.__getitem__os'&t,dDNFA>>>r)c<d|jjd|jjdS)N< >) __class____name__rFrMrGs r(__repr__zTemplateReference.__repr__ss% N333T^5H5H5HIIr)N)rT __module__ __qualname____doc__rIrNrVr%r)r(rrisL""!!!???JJJJJr)rc$t|d|S)N__func__)getattrr&s r( _get_funcr]ws 1j! $ $$r)ceZdZdZdS) ContextMetacBt||||}|dkr|St|j}ttj}t|j}ttj}||ur ||urd|_n||ur ||urd|_|S)Nr%T)type__new__r]resolveContextresolve_or_missing_legacy_resolve_mode_fast_resolve_mode) mcsrMbasesdrvrcdefault_resolveredefault_resolve_or_missings r(rbzContextMeta.__new__|s \\#tUA . . B;;IBJ''#GO44&r'<==%.w/I%J%J" ? * *"&@@@&*B # #  & &"&@@@$(B ! r)N)rTrWrXrbr%r)r(r_r_{s#r)r_c^||jvr |j|S||jvr |j|S|SrEr;r?)rHr@rs r(reres; gl|C   gn~c"" Nr)ceZdZdZdZdZdZdZddZdZ dZ d Z d Z e d Zdd Zd ZedZedZedZer!edZedZedZ[dZdZdZdS)rdaThe template context holds the variables of a template. It stores the values passed to the template and also the names the template exports. Creating instances is neither supported nor useful as it's created automatically at various stages of the template evaluation and should not be created by hand. The context is immutable. Modifications on :attr:`parent` **must not** happen and modifications on :attr:`vars` are allowed from generated template code only. Template filters and global functions marked as :func:`contextfunction`\s get the active context passed as first argument and are allowed to access the context read-only. The template context supports read only dict operations (`get`, `keys`, `values`, `items`, `iterkeys`, `itervalues`, `iteritems`, `__getitem__`, `__contains__`). Additionally there is a :meth:`resolve` method that doesn't fail with a `KeyError` but returns an :class:`Undefined` object for missing variables. Fc4||_i|_||_t|j||_t |_||_tdt|D|_ |j rtt||_ dSdS)Nc3&K|] \}}||gfV dSrEr%.0kvs r( z#Context.__init__..s,BB1As8BBBBBBr))r?r;r8reval_ctxset exported_varsrMr6r r:rgrre)rGr8r?rMr:s r(rIzContext.__init__s  &#D$4d;;  UU BB &0A0ABBBBB   " K&01CT&J&JD # # # K Kr)c |j|}||dz}||n/#t$r"|jd|zdcYSwxYwt ||||S)zRender a parent block.r#there is no parent block called %r.superrM)r:index LookupErrorr8 undefinedrL)rGrMcurrentr:rs r(r}z Context.supers [&FLL))A-E 5MMM   #--5<7.    dD&%888s-0)AANc8 ||S#t$r|cYSwxYw)zfReturns an item from the template context, if it doesn't exist `default` is returned. )KeyError)rGr@defaults r(getz Context.gets5 9    NNN s  c|jrt||}n||}|tur|j|S|S)zLooks up a variable like `__getitem__` or `get` but returns an :class:`Undefined` object with the name of the name looked up. r~)rfrerr8rrGr@rks r(rczContext.resolves[  $ .#D#..BB((--B ==#--3-77 7 r)c|jr3||}t|trt}|St ||S)zxResolves a variable like :meth:`resolve` but returns the special `missing` value if it cannot be found. )rfrc isinstancer#rrers r(rezContext.resolve_or_missingsL  $ c""B"i(( I!$,,,r)cDtfdjDS)z+Get a new dict with the exported variables.c36K|]}|j|fVdSrE)r;)rtrurGs r(rwz'Context.get_exported..s.BB!Q ! %BBBBBBr))r6rzrUs`r( get_exportedzContext.get_exporteds)BBBBt/ABBBBBBr)ch|js|jS|js|jSt|jfi|jS)zReturn the complete context as dict including the exported variables. For optimizations reasons this might not return an actual copy so be careful with using it. )r;r?r6rUs r(get_allzContext.get_allsB y ; { 9 DK--49---r)c d}t|dr |j}dD]}t||r|}nt|rWt|dddur|f|z}n=t|dddur |jf|z}nt|dddur |jf|z} ||i|S#t $r|jdcYSwxYw) zCall the callable with the arguments and keyword arguments provided but inject the active context or environment as first argument if the callable is a :func:`contextfunction` or :func:`environmentfunction`. T__call__)contextfunctionrenvironmentfunctionrFrrzGvalue was undefined because a callable raised a StopIteration exception)r.rcallabler\rxr8 StopIterationr)_Context__self _Context__objargskwargs__traceback_hide__fnfn_types r(callz Context.callsB &!%  5* % % B   2w''EE E?? 4u/774??y4' 5u==EE)D0 5u==EE*,t3 5$)&)) )   %//*    sB##$C  C c t|j|ji|dd|}|j|_|jdt|jD|S)zInternal helper function to create a derived context. This is used in situations where the system needs a new context in the same template that is independent. TNc3>K|]\}}|t|fVdSrE)listrss r(rwz"Context.derived..3s0NNtq!q$q''lNNNNNNr))rBr8rMrrxr:updater )rGr>rHs r(derivedzContext.derived*so   diT\\^^T4   =NNy7M7MNNNNNNr)c^fd}ttj|_|_|S)NcXt|SrE)r\r)rGmeths r(proxyzContext._all..proxy7s#074<<>>40022 2r))r\r6rYrT)rrs` r(_allz Context._all6s> 3 3 3 3 3 d++3  r)keysvaluesitemsiterkeys itervaluesr c&||jvp||jvSrErorGrMs r( __contains__zContext.__contains__Isty 7DDK$77r)c`||}|turt||S)zTLookup a variable or raise `KeyError` if the variable is undefined. )rerr)rGr@items r(rNzContext.__getitem__Ls1&&s++ 7??3--  r)cvd|jjdt|d|jdS)NrPrQz of rR)rSrTreprrrMrUs r(rVzContext.__repr__Us> N # # #  III  r)rE)rTrWrXrYrfrgrIr}rrcrerrrrrrrrrrrrr rrNrVr%r)r(rdrdso*!KKK$ 9 9 9    - - -CCC . . .##\#J     4<||_||_||_||_dSrE)rM_context_stack_depth)rGrMrHstackdepths r(rIzBlockReference.__init__cs"    r)c|jdzt|jkr)|jjd|jzdSt|j|j|j|jdzS)zSuper the block.rr|r}r~)rlenrrr8rrMrLrUs r(r}zBlockReference.superisp ;?c$+.. . .=,665 A7 di T[ST_UUUr)ct|j|j|j}|jjjrt |}|SrE)rrrrrx autoescaperrGrks r(rzBlockReference.__call__rsE ,DK ,T];; < < = ! , B r)N) rTrWrXrYrIpropertyr}rrr%r)r(rLrL`sb,, VVXV\r)rLcNeZdZdZdZdZeZeZeZ eZ ddZ e dZ edZdZed Zed Zed Zed Zed ZdZedZedZedZdZdZdZdZedZdZ dS)rzeA wrapper iterable for dynamic ``for`` loops, with information about the loop and iteration. Nrcr||_|||_||_||_||_dS)a@ :param iterable: Iterable to wrap. :param undefined: :class:`Undefined` class to use for next and previous items. :param recurse: The function to render the loop body when the loop is marked recursive. :param depth0: Incremented when looping recursively. N) _iterable _to_iterator _iterator _undefined_recursedepth0)rGiterablerrecursers r(rIzLoopContext.__init__s9"**844#  r)c t|SrE)iter)rs r(rzLoopContext._to_iteratorsH~~r)c4|j|jS t|j|_ni#t$r\t |j}|||_t||jz|jtuz|_YnwxYw|jS)zLength of the iterable. If the iterable is a generator or otherwise does not have a size, it is eagerly evaluated to get a size. ) _lengthrr TypeErrorrrrr_afterrrGrs r(lengthzLoopContext.lengths < #<  Ut~..DLL U U UDN++H!..x88DNx==4:5G9STDLLL U |s*A#BBc|jSrE)rrUs r(__len__zLoopContext.__len__s {r)c|jdzS)zBHow many levels deep a recursive loop currently is, starting at 1.r)rrUs r(rzLoopContext.depth{Qr)c|jdzS)z-Current iteration of the loop, starting at 1.rindex0rUs r(rzLoopContext.indexrr)c |j|jz S)zrNumber of iterations from the end of the loop, ending at 0. Requires calculating :attr:`length`. )rrrUs r( revindex0zLoopContext.revindex0s {TZ''r)c |j|jz S)zrNumber of iterations from the end of the loop, ending at 1. Requires calculating :attr:`length`. )rrrUs r(revindexzLoopContext.revindexs {T[((r)c|jdkS)z0Whether this is the first iteration of the loop.rrrUs r(firstzLoopContext.firsts{ar)cx|jtur|jSt|jt|_|jS)a Return the next element in the iterable, or :data:`missing` if the iterable is exhausted. Only peeks one item ahead, caching the result in :attr:`_last` for use in subsequent checks. The cache is reset when :meth:`__next__` is called. )rrnextrrUs r( _peek_nextzLoopContext._peek_nexts4 ;g % %; 4>733 {r)c8|tuS)zWhether this is the last iteration of the loop. Causes the iterable to advance early. See :func:`itertools.groupby` for issues this can cause. The :func:`groupby` filter avoids that issue. )rrrUs r(lastzLoopContext.lasts  G++r)cH|jr|dS|jS)zZThe item in the previous iteration. Undefined during the first iteration. zthere is no previous item)rr_beforerUs r(previtemzLoopContext.previtems* : @??#>?? ?|r)cj|}|tur|dS|S)zThe item in the next iteration. Undefined during the last iteration. Causes the iterable to advance early. See :func:`itertools.groupby` for issues this can cause. The :func:`groupby` filter avoids that issue. zthere is no next item)rrrrs r(nextitemzLoopContext.nextitems4__   ==??#:;; ; r)c^|std||jt|zS)zReturn a value from the given args, cycling through based on the current :attr:`index0`. :param args: One or more values to cycle through. zno items for cycling given)rrr)rGrs r(cyclezLoopContext.cycles3  :899 9DK#d))+,,r)c.|j|kr ||_dSdS)zReturn ``True`` if previously called with a different value (including when called for the first time). :param value: One or more values to compare to the last call. TF)_last_changed_value)rGrAs r(changedzLoopContext.changed s$  #u , ,',D $4ur)c|SrEr%rUs r(__iter__zLoopContext.__iter__ r)c|jtur|j}t|_nt|j}|xjdz c_|j|_||_||fS)Nr)rrrrr_currentrrs r(__next__zLoopContext.__next__sW ;g % %B!DKKdn%%B q }  4xr)cr|jtd|||j|jS)zWhen iterating over nested data, render the body of the loop recursively with the given inner iterable data. The loop must have the ``recursive`` marker for this to work. NzCThe loop must have the 'recursive' marker to be called recursively.)r)rrrrs r(rzLoopContext.__call__(s? = U }}Xt}DJ}GGGr)c:d|jj|j|jfzS)Nz <%s %d/%d>)rSrTrrrUs r(rVzLoopContext.__repr__6st~6 DKPPPr)rK)!rTrWrXrYrrrrrrrrI staticmethodrrrrrrrrrrrrrrrrrrrrVr%r)r(rrzs FG FHG! \X$XX((X())X)  X    ,,X,X  X  - - -       H H\ HQQQQQr)rcNeZdZdZ ddZeedZdZdZ dS)rzWraps a macro function.Nc ||_||_t||_||_||_||_||_||_d|v|_ ||j }||_ dS)Ncaller) _environment_funcr_argument_countrM arguments catch_kwargs catch_varargsrexplicit_callerr_default_autoescape) rGr8funcrMrrrrdefault_autoescapes r(rIzMacro.__init__=sp( "9~~ "(* '94  %!,!7 #5   r)c T|r3t|dtr|dj}|dd}n|j}t |d|j}t |}d}||jkrk|jt |dD]M} ||}n#t$r t}YnwxYw|dkrd}| |Nn|j }|j rK|sI|dd} | |jdd} | | |jr| |nQ|rOd|vrt#d|jzt#d |jd t't)||jr#| ||jdnCt ||jkr+t#d |jt |jfz|||S) NrrFrTzNo caller definedr~zamacro %r was invoked with two values for the special caller argument. This is most likely a bug.zmacro z takes no keyword argument z+macro %r takes not more than %d argument(s))rrrrrrrrpoprrr-rrrrrrrMrrr_invoke) rGrrrroff found_callerrMrArs r(rzMacro.__call__Us&  2JtAw 44 2a+J8DD1J4 44566 )nn $& & &s9~~'7'78 ( ($"JJt,,EE$$$#EEE$8###'L  '''' ( /L ; %| %ZZ$//F~*445Hx4XX   V $ $ $      V $ $ $ $  6!!)+/95 )999d4<<0002       T$"6"8"89 : : : : YY- - -=9c$.1123  ||Iz222sB**B>=B>c<|j|}|rt|}|S)z=This method is being swapped out by the async implementation.)rr)rGrrrks r(rz Macro._invokes( TZ #  B r)cbd|jjd|jdurdpt|jdS)NrPrQ anonymousrR)rSrTrMrrUs r(rVzMacro.__repr__s> N # # # I  -+ @di @ @  r)rE) rTrWrXrYrIrrrrrVr%r)r(rr:s{!! 66660L3L3\L3\     r)rceZdZdZdZdedefdZedZ e dZ e dZ e xZ xZxZxZxZxZxZxZxZxZxZxZxZxZxZxZxZxZxZxZ xZ!xZ"xZ#xZ$xZ%xZ&Z'dZ(d Z)d Z*d Z+d Z,d Z-dZ.e.Z/dZ0dS)r#ahThe default undefined type. This undefined type can be printed and iterated over, but every other access will raise an :exc:`UndefinedError`: >>> foo = Undefined(name='foo') >>> str(foo) '' >>> not foo True >>> foo + 42 Traceback (most recent call last): ... jinja2.exceptions.UndefinedError: 'foo' is undefined _undefined_hint_undefined_obj_undefined_name_undefined_exceptionNc>||_||_||_||_dSrEr)rGhintobjrMexcs r(rIzUndefined.__init__s(#!#$'!!!r)c|jr|jS|jtur d|jzSt |jt st |jd|jSt |jd|jS)zXBuild a message about the undefined value based on how it was accessed. z%r is undefined has no element  has no attribute )rrrrrrrrUs r(_undefined_messagezUndefined._undefined_messages   (' '  ' ) )$t';; ;$. ==  !45555$$  T0 1 1 1 1    r)c6||j)zeRaise an :exc:`UndefinedError` when operations are performed on the undefined value. )rr)rGrrs r(_fail_with_undefined_errorz$Undefined._fail_with_undefined_errors ''(?@@@r)cd|dddkrt||S)N__)AttributeErrorrrs r( __getattr__zUndefined.__getattr__s5 8t   && &..000r)c>t|t|uSrE)rarGothers r(__eq__zUndefined.__eq__!sDzzT%[[((r)c.|| SrE)r&r$s r(__ne__zUndefined.__ne__$s;;u%%%%r)c:tt|SrE)idrarUs r(__hash__zUndefined.__hash__'s$t**~~r)cdS)Nr,r%rUs r(__str__zUndefined.__str__*ssr)cdSrKr%rUs r(rzUndefined.__len__-sqr)c# KdSrEr%rUs r(rzUndefined.__iter__0s  r)cdS)NFr%rUs r( __nonzero__zUndefined.__nonzero__4sur)cdS)Nr#r%rUs r(rVzUndefined.__repr__9s{r))1rTrWrXrY __slots__rrrIrrrrr"__add____radd____mul____rmul____div____rdiv__ __truediv__ __rtruediv__ __floordiv__ __rfloordiv____mod____rmod____pos____neg__rrN__lt____le____gt____ge____int__ __float__ __complex____pow____rpow____sub____rsub__r&r(r+r-rrr1__bool__rVr%r)r(r#r#sK  I!gDn((((   X *AA\A 11\1b3MY,MG,M,M ,M  ,M ,M ,M ,M ,M ,M" #,M& ',M* +,M. /,M2 3,M6 7,M: ;,M> ?,MB C,MF G,MJ K,MN O,MR S,MV W,MX Y,MXY,MX%x)))&&&Hr)r#cPddl}|t|t jtfdGfdd}|S)akGiven a logger object this returns a new undefined class that will log certain failures. It will log iterations and printing. If no logger is given a default logger is created. Example:: logger = logging.getLogger(__name__) LoggingUndefined = make_logging_undefined( logger=logger, base=Undefined ) .. versionadded:: 2.8 :param logger: the logger to use. If not provided, a default logger is created. :param base: the base class to add logging functionality to. This defaults to :class:`Undefined`. Nrc2|jq|jtur d|jz}n_t |jt st |jd|j}n&t |jd|j}n|j}d|dS)Nz%s is undefinedrrzTemplate variable warning: %s)rrrrrrrwarning)undefrloggers r( _log_messagez,make_logging_undefined.._log_messageYs  (#w..(5+@@ 5|DD $U%9::::)) %U%9::::)) (D6=====r)c`eZdZfdZfdZfdZerfdZfdZdSfdZ dS)0make_logging_undefined..LoggingUndefinedc j|g|Ri|S#|j$r*}dt||d}~wwxYw)NzTemplate variable error: %s)rrerrorstr)rGrrebaserRs r(rzKmake_logging_undefined..LoggingUndefined._fail_with_undefined_errorlsm 6t6tMdMMMfMMM,    :CFFCCC s A%AAcH|}||SrEr-rGrkrSrZs r(r-z8make_logging_undefined..LoggingUndefined.__str__ss)d##B L   Ir)cH|}||SrE)rr]s r(rz9make_logging_undefined..LoggingUndefined.__iter__xs)t$$B L   Ir)cH|}||SrE)r1r]s r(r1z.LoggingUndefined.__nonzero__+%%d++ T""" r)cH|}||SrE) __unicode__r]s r(rbz.LoggingUndefined.__unicode__r`r)cH|}||SrE)rMr]s r(rMz9make_logging_undefined..LoggingUndefined.__bool__s)]]4(( T""" r)N) rTrWrXrr-rrr1rbrM)rSrZrRsr(LoggingUndefinedrUks                                            r)rd)logging getLoggerrT addHandler StreamHandlersysstderrr#)rRrZrerdrSs`` @r(make_logging_undefinedrk=s(~""8,,'// ;;<<< |>>>>>$#########4###J r)c&eZdZdZdZdZdZeZdS)ChainableUndefinedaAn undefined that is chainable, where both ``__getattr__`` and ``__getitem__`` return itself rather than raising an :exc:`UndefinedError`. >>> foo = ChainableUndefined(name='foo') >>> str(foo.bar['baz']) '' >>> foo.bar['baz'] + 42 Traceback (most recent call last): ... jinja2.exceptions.UndefinedError: 'foo' is undefined .. versionadded:: 2.11.0 r%c*|SrEr\rUs r(r+zChainableUndefined.__html__s||~~r)c|SrEr%)rG_s r(r"zChainableUndefined.__getattr__rr)N)rTrWrXrYr3r+r"rNr%r)r(rmrmsD  IKKKr)rmceZdZdZdZdZdS)DebugUndefinedaAn undefined that returns the debug info when printed. >>> foo = DebugUndefined(name='foo') >>> str(foo) '{{ foo }}' >>> not foo True >>> foo + 42 Traceback (most recent call last): ... jinja2.exceptions.UndefinedError: 'foo' is undefined r%c|j8|jtur d|jzSdt |jd|jdSd|jzS)Nz{{ %s }}z{{ no such element: [z] }}z!{{ undefined value printed: %s }})rrrrrrUs r(r-zDebugUndefined.__str__sh   '"g--"T%999.!!45555$$$ 4d6JJJr)N)rTrWrXrYr3r-r%r)r(rrrrs9  IKKKKKr)rrc@eZdZdZdZejxZxZxZ xZ xZ xZ xZ ZdS)StrictUndefinedasAn undefined that barks on print and iteration as well as boolean tests and all kinds of comparisons. In other words: you can do nothing with it except checking if it's defined using the `defined` test. >>> foo = StrictUndefined(name='foo') >>> str(foo) Traceback (most recent call last): ... jinja2.exceptions.UndefinedError: 'foo' is undefined >>> not foo Traceback (most recent call last): ... jinja2.exceptions.UndefinedError: 'foo' is undefined >>> foo + 42 Traceback (most recent call last): ... jinja2.exceptions.UndefinedError: 'foo' is undefined r%N)rTrWrXrYr3r#rrr-rr1r&r(rMr+r%r)r(rvrvsq&I1:0T UHUU U  U  U  U #XXXr)rv)NNNN)NN)9rYri itertoolsrtypesr markupsaferrr_compatr r r r r rrrr exceptionsrrrnodesrutilsrrrrrrexportedr!r"rr rBobjectrr]rar_rerdMappingregisterrLrrr#rkrmrrrvr3r%r)r(rsAA ######(((((())))))!!!!!!######((((((,,,,,,&&&&&&&&&&&&######   (     (((    QQQQ6 J J J J J J J J%%%$6.5| | | | | nn[))| | | ~ WV4|Q|Q|Q|Q|Q|Q|Q|Q~v v v v v Fv v v rFFFFFFFFRSSSSr6KKKKKYKKK6UUUUUiUUUB r)