U aň@s2dZddlZddlZddlZddlmZddlmZddl m Z ddl m Z ddl m Z dd l mZdd l mZdd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZedZejdej dej!fdZ"ej#rNddl$Z$ddl%Z&ddl'm(Z(Gddde&j)Z*dddd d!d"d#d$d%d&d'd(d)d*d+gZ+d,d-d.gZ,eed/d0d'Z-ej.ej!e/d1d2d%Z0ej.ej!e/d1d3d&Z1ej.ej!e/d1d4d5Z2dQd7ej3e/ej4e/ej d8gej5e/ffej3ej4e/ej!fe6ej3ej7e/ej!fej3ej8e/ej!fd8d9d:d;Z9Gdd?Z;ej8jGdCddZ?GdDd,d,e?Z@GdEddZAGdFd*d*ZBdeBfej3dGejCeBejCeBdHdIdJZDGdKdLdLeBZEGdMdNdNeBZFGdOdPdPeBZGeB`HeE`HeF`HeG`HdS)Rz;The runtime functions and state used by compiled templates.N)abc)chain)escape)Markup)soft_str auto_aiter) auto_await)TemplateNotFound)TemplateRuntimeError)UndefinedError) EvalContext)_PassArg)concat) internalcode)missing) Namespace)object_type_repr)pass_eval_contextVF.)bound) Environmentc@s(eZdZdejedeedddZdS)LoopRenderFuncr)reciterloop_render_funcdepthreturncCsdSN)selfrrrr r OC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-8gbwd15f\jinja2\runtime.py__call__#szLoopRenderFunc.__call__N)r) __name__ __module__ __qualname__tIterablerintstrr#r r r r"r"sr LoopContextTemplateReferenceMacrorr rrr markup_joinstr_joinidentityr r UndefinedrAsyncLoopContextr r )xrcCs|S)zLReturns its argument. Useful for certain things in the environment. r )r3r r r"r0Es)seqrcCsLg}tt|}|D]0}||t|drtdt||Sqt|S)z?Concatenation that escapes if necessary and converts to string.__html__)maprappendhasattrrjoinrr)r4bufiteratorargr r r"r.Ls   cCsttt|S)z3Simple args to string conversion and concatenation.)rr7r*)r4r r r"r/WscCs ddl}|jdtddt|S)NrzWThis template must be recompiled with at least Jinja 3.0, or it will fail in Jinja 3.1. stacklevel)warningswarnDeprecationWarningr/)r4rAr r r" unicode_join\srDFrContext) environment template_nameblocksvarssharedglobalslocalsrc Csl|dkr i}|r|}nt|pdf|}|rX|r6t|}|D]\}} | tk r>| ||<q>|j|||||dS)z%Internal helper for context creation.Nr )rK)dictitemsrZ context_class) rFrGrHrIrJrKrLparentkeyvaluer r r" new_contexths$  rRc@s@eZdZdZdddddZeejddd Zed d d Z dS) r,zThe `self` in templates.rEN)contextrcCs ||_dSr)_TemplateReference__context)r!rSr r r"__init__szTemplateReference.__init__namercCs|jj|}t||j|dSNr)rTrHBlockReference)r!rWrHr r r" __getitem__s zTemplateReference.__getitem__rcCsdt|jd|jjdS)N< >)typer$rTrWr!r r r"__repr__szTemplateReference.__repr__) r$r%r&__doc__rUr*r'AnyrZrar r r r"r,s) dict_methodrcs,tdtjdfdd }tt|S)NrE)r!rcs |Sr)get_allr`rdr r"f_allsz_dict_method_all..f_all) functoolswrapsr'rccastr)rdrgr rfr"_dict_method_allsrkc @seZdZUdZdZejeed<ddddZ d*dej e ej fej e ej e ejdgeje ffej eje ej fd d d Ze ejdgeje fejd d ddZd+e ej ej dddZe ejej dfdddZe ej dddZej e ej fdddZej e ej fdddZeejej ej ejej dfdddZd,ej ej e ej fdd d!d"ZeejZeejZeej Z e ed#d$d%Z!e ej dd&d'Z"e dd(d)Z#dS)-rEaThe 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:`pass_context` 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. F_legacy_resolve_modeNr[cCsDd|jkrd|_n.d|jks"|jr@ddl}|jdtddd|_dS) Nresolve_or_missingFresolverzOverriding 'resolve' is deprecated and will not have the expected behavior in Jinja 3.1. Override 'resolve_or_missing' instead r>r?T)__dict__rlrArBrC)clsrAr r r"__init_subclass__s zContext.__init_subclass__r)rFrOrWrHrKcCs^||_i|_||_t|j||_t|_||_|dkrsz$Context.__init__..) rOrIrFreval_ctxset exported_varsrWZ globals_keysrNrH)r!rFrOrWrHrKr r r"rUszContext.__init__rYr1)rWcurrentrcCs`z$|j|}||d}||Wn,tk rP|jjd|dddYSXt||||S)zRender a parent block.r there is no parent block called .superrW)rHindex LookupErrorrF undefinedrY)r!rWr{rHrr r r"r~s    z Context.super)rPdefaultrcCs(z ||WStk r"|YSXdS)zLook up a variable by name, or return a default if the key is not found. :param key: The variable name to look up. :param default: The value to return if the key is not found. N)KeyError)r!rPrr r r"gets z Context.getr1)rPrcCs`|jr<||jkr|j|S||jkr.|j|S|jj|dS||}|tkr\|jj|dS|S)aNLook up a variable by name, or return an :class:`Undefined` object if the key is not found. If you need to add custom behavior, override :meth:`resolve_or_missing`, not this method. The various lookup functions use that method, not this one. :param key: The variable name to look up. r)rlrIrOrFrrmrr!rPrvr r r"rns      zContext.resolvecCsN|jr"||}t|trtS|S||jkr6|j|S||jkrJ|j|StS)aNLook up a variable by name, or return a ``missing`` sentinel if the key is not found. Override this method to add custom lookup behavior. :meth:`resolve`, :meth:`get`, and :meth:`__getitem__` use this method. Don't call this method directly. :param key: The variable name to look up. )rlrn isinstancer1rrIrOrr r r"rms       zContext.resolve_or_missingcsfddjDS)z+Get a new dict with the exported variables.csi|]}|j|qSr )rI)rsrtr`r r"rv*sz(Context.get_exported..)ryr`r r`r" get_exported(szContext.get_exportedcCs(|js |jS|js|jSt|jf|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. )rIrOrMr`r r r"re,s zContext.get_all) _Context__objargskwargsrcOsd}t|dr$t|jdk r$|j}t|}|tjkrt|drP||d}|drh||d}|f|}n.|tjkr|jf|}n|tj kr|j f|}| dd| ddz |||WSt k r|j dYSXdS)zCall the callable with the arguments and keyword arguments provided but inject the active context or environment as first argument if the callable has :func:`pass_context` or :func:`pass_environment`. Tr#NZ _loop_varsZ _block_varszGvalue was undefined because a callable raised a StopIteration exception) r9rZfrom_objr#rSrderivedZ eval_contextrwrFpop StopIterationr)Z_Context__selfrrrZ__traceback_hide__Zpass_argr r r"call7s2            z Context.call)rLrcCsDt|j|ji|dd|}|j|_|jdd|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. TNcss|]\}}|t|fVqdSr)listrrr r r" msz"Context.derived..)rRrFrWrerwrHupdaterN)r!rLrSr r r"rdszContext.derivedrVcCs||jkp||jkSr)rIrOr!rWr r r" __contains__tszContext.__contains__cCs||}|tkrt||S)zpLook up a variable by name with ``[]`` syntax, or raise a ``KeyError`` if the key is not found. )rmrr)r!rPitemr r r"rZws zContext.__getitem__cCs$dt|jd|d|jdS)Nr\r]z of r^)r_r$rerWr`r r r"raszContext.__repr__)N)N)N)$r$r%r&rbrlr'ClassVarbool__annotations__rqDictr*rcOptionalCallableIteratorMutableMappingrUUnionr~rrnrmrrerrrrkrMkeysvaluesrNrrZrar r r r"rEsB     ,$    c@szeZdZdZedejejdgejefe ddddZ e ej ddd d Z eedd d Zeedd dZdS)rYz"One block on a template reference.rEN)rWrSstackrrcCs||_||_||_||_dSr)rW_context_stack_depth)r!rWrSrrr r r"rUszBlockReference.__init__rzr[cCsJ|jdt|jkr0|jjjd|jdddSt|j|j|j|jdS)zSuper the block.rr|r}r~r)rlenrrrFrrWrYr`r r r"r~s  zBlockReference.supercs<tdd|j|j|j2IdH}|jjjr8t|S|S)Ncsg|z3dHW}|q6Srr rsr3r r r" sz.BlockReference._async_call..)rrrrrw autoescaperr!rr r r" _async_calls   zBlockReference._async_callcCs>|jjjr|St|j|j|j}|jjjr:t |S|Sr) rrFis_asyncrrrrrwrrrr r r"r#s   zBlockReference.__call__)r$r%r&rbr*r'Listrrr)rUpropertyrr~rrr#r r r r"rYs  rYc@seZdZUdZdZdZejee d<e Z ej e d<e Z ej e d<e Zej e d<e Zej e d<d7ejeejd ejd edd d dZeejeejedddZeedddZedddZeedddZeedddZeedddZeedddZeeddd Zej dd!d"Z eedd#d$Z!eej"ej d fdd%d&Z#eej"ej d fdd'd(Z$eed)d*d+Z%ej ed,d-d.Z&ddd/d0Z'ej(ej dfdd1d2Z)e*ejee+dd3d4Z,e+dd5d6Z-dS)8r+zeA wrapper iterable for dynamic ``for`` loops, with information about the loop and iteration. N_length_after_current_before_last_changed_valuerr1r)iterablerrecursedepth0rcCs(||_|||_||_||_||_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_recurser)r!rrrrr r r"rUs  zLoopContext.__init__rrcCst|Sr)iterrr r r"rszLoopContext._to_iteratorr[cCsl|jdk r|jSzt|j|_WnDtk rdt|j}|||_t||j|jt k |_YnX|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. N) rrr TypeErrorrrrrrrr!rr r r"lengths    zLoopContext.lengthcCs|jSr)rr`r r r"__len__szLoopContext.__len__cCs |jdS)zBHow many levels deep a recursive loop currently is, starting at 1.r)rr`r r r"rszLoopContext.depthcCs |jdS)z-Current iteration of the loop, starting at 1.rindex0r`r r r"rszLoopContext.indexcCs |j|jS)zrNumber of iterations from the end of the loop, ending at 0. Requires calculating :attr:`length`. rrr`r r r" revindex0szLoopContext.revindex0cCs |j|jS)zrNumber of iterations from the end of the loop, ending at 1. Requires calculating :attr:`length`. rrr`r r r"revindexszLoopContext.revindexcCs |jdkS)z0Whether this is the first iteration of the loop.rrr`r r r"firstszLoopContext.firstcCs$|jtk r|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. )rrnextrr`r r r" _peek_nexts zLoopContext._peek_nextcCs |tkS)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. rrr`r r r"lastszLoopContext.lastcCs|jr|dS|jS)zZThe item in the previous iteration. Undefined during the first iteration. zthere is no previous item)rrrr`r r r"previtem)s zLoopContext.previtemcCs|}|tkr|dS|S)a The 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:`jinja-filters.groupby` filter avoids that issue. there is no next itemrrrrr r r"nextitem3s  zLoopContext.nextitem)rrcGs|s td||jt|S)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)r!rr r r"cycleCszLoopContext.cycle)rQrcGs|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)r)r!rQr r r"changedNs zLoopContext.changedcCs|Srr r`r r r"__iter__ZszLoopContext.__iter__cCsF|jtk r|j}t|_n t|j}|jd7_|j|_||_||fSNr)rrrrrrrrr r r"__next__]s  zLoopContext.__next__cCs&|jdkrtd|j||j|jdS)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)rrrrr r r"r#is  zLoopContext.__call__cCs"dt|jd|jd|jdS)Nr\r]/r^)r_r$rrr`r r r"rawszLoopContext.__repr__)Nr).r$r%r&rbrrr'rr)rrrrcrrrr(rTyperU staticmethodrrrrrrrrrrrrrrrrrrrTuplerrr*r#rar r r r"r+sZ         c@seZdZUejejed<eejej e ej e feje dddZ e edddZe eddd Ze edd d Zejdd d Ze edddZe ejejdfdddZddddZejejdfdddZdS)r2rrcCst|Srrrr r r"r~szAsyncLoopContext._to_iteratorr[csx|jdk r|jSzt|j|_WnPtk rpdd|j2IdH}|||_t||j|jtk |_YnX|jS)Ncsg|z3dHW}|q6Srr rr r r"rsz+AsyncLoopContext.length..) rrrrrrrrrrr r r"rs   zAsyncLoopContext.lengthcs|jIdH|jSrrr`r r r"rszAsyncLoopContext.revindex0cs|jIdH|jSrrr`r r r"rszAsyncLoopContext.revindexcsH|jtk r|jSz|jIdH|_Wntk r@t|_YnX|jSr)rrr __anext__StopAsyncIterationr`r r r"rs  zAsyncLoopContext._peek_nextcs|IdHtkSrrr`r r r"rszAsyncLoopContext.lastr1cs$|IdH}|tkr |dS|S)Nrrrr r r"rs zAsyncLoopContext.nextitemcCs|Srr r`r r r" __aiter__szAsyncLoopContext.__aiter__csL|jtk r|j}t|_n|jIdH}|jd7_|j|_||_||fSr)rrrrrrrrr r r"rs zAsyncLoopContext.__anext__N)r$r%r&r' AsyncIteratorrcrrrr(r AsyncIterablerrr)rrrrrrrrrrr r r r"r2{s$   c @seZdZdZddejdefeejeeeeej edddZ e e ej ej edd d Zejej eed d d Zejej eed ddZedddZdS)r-zWraps a macro function.Nr.)rFfuncrW arguments catch_kwargs catch_varargscallerdefault_autoescapec Csl||_||_t||_||_||_||_||_||_d|k|_ |dkrbt |j r\| d}n|j }||_ dS)Nr) _environment_funcr_argument_countrWrrrrexplicit_callercallabler_default_autoescape) r!rFrrWrrrrrr r r"rUs     zMacro.__init__rrrc Os|r*t|dtr*|dj}|dd}n|j}t|d|j}t|}d}||jkr|jt|dD]B}z||}Wnt k rt }YnX|dkrd}| |qjn|j }|j r|s|dd} | dkr|jjddd} | | |jr| |n@|rBd|kr$td|jd td|jd tt||jr`| ||jdn.t||jkrtd|jd t|jd |||S) NrrFrTzNo caller definedrzmacro zX was invoked with two values for the special caller argument. This is most likely a bug.z takes no keyword argument z takes not more than z argument(s))rrrrrrrrrrrr8rrrrrrrWrrr_invoke) r!rrrroffZ found_callerrWrQrr r r"r#sN         zMacro.__call__)rrrcs |j|IdH}|rt|S|Sr)rrr!rrrr r r" _async_invoke0szMacro._async_invokecCs.|jjr|||S|j|}|r*t|}|Sr)rrrrrrr r r"r8s   z Macro._invoker[cCs0|jdkrdnt|j}dt|jd|dS)NZ anonymousr\r]r^)rWreprr_r$rr r r"raCszMacro.__repr__)N)r$r%r&rbr'rr*rrrrUrrrcr#rrrar r r r"r-s$   L c@seZdZdZdZdedefeje ej eje ej e ddddZ ee ddd Zeej ej d d d d Zee ej dddZeZZZZeZZZZeZZeZZeZZ eZ!Z"eZ#Z$Z%eZ&Z'Z(Z)eZ*Z+Z,eZ-Z.ej e/dddZ0ej e/dddZ1e2dddZ3e dddZ4e2dddZ5ej6ej dddZ7ej8ej dddZ9e/dd d!Z:e dd"d#Z;dS)$r1ahThe 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_exceptionN)hintobjrWexcrcCs||_||_||_||_dSrr)r!rrrWrr r r"rU^szUndefined.__init__r[cCsZ|jr |jS|jtkr"|jdSt|jtsDt|jd|jSt|jd|jS)zXBuild a message about the undefined value based on how it was accessed. z is undefinedz has no element z has no attribute )rrrrrr*rr`r r r"_undefined_messagejs   zUndefined._undefined_message te.NoReturnrcOs||jdS)zeRaise an :exc:`UndefinedError` when operations are performed on the undefined value. N)rr)r!rrr r r"_fail_with_undefined_errorsz$Undefined._fail_with_undefined_errorrVcCs |dddkrt||S)Nr>__)AttributeErrorrrr r r" __getattr__szUndefined.__getattr__)otherrcCst|t|kSr)r_r!rr r r"__eq__szUndefined.__eq__cCs || Sr)rrr r r"__ne__szUndefined.__ne__cCs tt|Sr)idr_r`r r r"__hash__szUndefined.__hash__cCsdS)Nr6r r`r r r"__str__szUndefined.__str__cCsdSrXr r`r r r"rszUndefined.__len__ccsdEdHdSNr r r`r r r"rszUndefined.__iter__cCsdD] }dVqdSrr r!_r r r"rszUndefined.__aiter__cCsdS)NFr r`r r r"__bool__szUndefined.__bool__cCsdS)Nr1r r`r r r"raszUndefined.__repr__)._log_messagecsteZdZdZejejddfdd Zedfdd Zej ejdfd d Z e dfd d Z Z S) z0make_logging_undefined..LoggingUndefinedr rrc sLztj||Wn4|jk rF}zd||W5d}~XYnXdS)NzTemplate variable error: %s)r~rrerror)r!rre) __class__r$r r"rs  zKmake_logging_undefined..LoggingUndefined._fail_with_undefined_errorr[cs|tSr)r~rr`r+r(r r"rsz8make_logging_undefined..LoggingUndefined.__str__cs|tSr)r~rr`r,r r"rsz9make_logging_undefined..LoggingUndefined.__iter__cs|tSr)r~r r`r,r r"r sz9make_logging_undefined..LoggingUndefined.__bool__)r$r%r&r r'rcrr*rrrrr  __classcell__r r(r$)r+r"LoggingUndefineds r/)logging getLoggerr$ addHandler StreamHandlersysstderrr1)r$r%r0r/r r.r"make_logging_undefineds r6c@s6eZdZdZdZedddZeddddZeZd S) 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 r[cCst|Sr)r*r`r r r"r5szChainableUndefined.__html__)r rcCs|Srr r r r r"r szChainableUndefined.__getattr__N) r$r%r&rbr r*r5rrZr r r r"r7s r7c@s"eZdZdZdZedddZdS)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 r[cCsL|jrd|j}n,|jtkr&|j}ndt|jd|jd}d|dS)Nzundefined value printed: zno such element: []z{{ z }})rrrrr)r!messager r r"rs zDebugUndefined.__str__N)r$r%r&rbr r*rr r r r"r8s r8c@s4eZdZdZdZejZZZ ejZ Z Z Z dS)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)r$r%r&rbr r1rrrrrrr rr r r r"r</sr<)NFNN)Irbrhr4typingr' collectionsr itertoolsrZ markupsaferrrZ async_utilsr r exceptionsr r r ZnodesrutilsrrrrrrrTypeVarrrrcr TYPE_CHECKINGr0Ztyping_extensionsterFrProtocolrZexportedZasync_exportedr0r(r*r.r/rDrrrrrMappingrRr,rkregisterrErYr+r2r-r1rr6r7r8r<r r r r r"s                       k0FGq <