B ^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_funcdepthreturncCsdS)N)selfrrrrr?/opt/alt/python37/lib/python3.7/site-packages/jinja2/runtime.py__call__#szLoopRenderFunc.__call__N)r) __name__ __module__ __qualname__tIterablerintstrr!rrrr r"sr LoopContextTemplateReferenceMacrorr rrr markup_joinstr_joinidentityr r UndefinedrAsyncLoopContextrr )xrcCs|S)zLReturns its argument. Useful for certain things in the environment. r)r1rrr r.Es)seqrcCsLg}tt|}x4|D],}||t|drtdt||SqWt|S)z?Concatenation that escapes if necessary and converts to string.__html__)maprappendhasattrrjoinrr)r2bufiteratorargrrr r,Ls    cCsttt|S)z3Simple args to string conversion and concatenation.)rr5r()r2rrr 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-)r2r>rrr unicode_join\s rAFrContext) environment template_nameblocksvarssharedglobalslocalsrc Csp|dkr i}|r|}nt|pdf|}|r\|r6t|}x$|D]\}} | tk r@| ||<q@W|j|||||dS)z%Internal helper for context creation.Nr)rH)dictitemsrZ context_class) rCrDrErFrGrHrIparentkeyvaluerrr new_contexths  rOc@s@eZdZdZdddddZeejddd Zed d d Z dS) r*zThe `self` in templates.rBN)contextrcCs ||_dS)N)_TemplateReference__context)rrPrrr __init__szTemplateReference.__init__)namercCs|jj|}t||j|dS)Nr)rQrEBlockReference)rrSrErrr __getitem__s zTemplateReference.__getitem__)rcCsdt|jd|jjdS)N< >)typer"rQrS)rrrr __repr__szTemplateReference.__repr__) r"r#r$__doc__rRr(r%AnyrUrZrrrr r*s) dict_methodrcs,tdtjdfdd }tt|S)NrB)rrcs |S)N)get_all)r)r]rr f_allsz_dict_method_all..f_all) functoolswrapsr%r\castr)r]r_r)r]r _dict_method_allsrcc @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)-rBaThe 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_modeN)rcCsDd|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__rdr>r?r@)clsr>rrr __init_subclass__s zContext.__init_subclass__r)rCrLrSrErHcCs^||_i|_||_t|j||_t|_||_|dkrsz$Context.__init__..) rLrFrCr eval_ctxset exported_varsrSZ globals_keysrKrE)rrCrLrSrErHrrr rRszContext.__init__)rTr/)rScurrentrcCs\y$|j|}||d}||Wn(tk rL|jjd|dddSXt||||S)zRender a parent block.rz there is no parent block called .super)rS)rEindex LookupErrorrC undefinedrT)rrSrqrErtrrr rss  z Context.super)rMdefaultrcCs"y||Stk r|SXdS)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)rrMrwrrr getsz Context.getr/)rMrcCs`|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. )rS)rdrFrLrCrvrer)rrMrvrrr rfs      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. )rdrf isinstancer/rrFrL)rrMrzrrr res       zContext.resolve_or_missingcsfddjDS)z+Get a new dict with the exported variables.csi|]}j||qSr)rF)rjrk)rrr rm*sz(Context.get_exported..)rp)rr)rr 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. )rFrLrJ)rrrr r^,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| ddy |||St k r|j dSXdS)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) r7rZfrom_objr!rPryderivedZ eval_contextrnrCpop StopIterationrv)Z_Context__selfr}r~rZ__traceback_hide__Zpass_argrrr call7s,             z Context.call)rIrcCsDt|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|fVqdS)N)list)rjrkrlrrr msz"Context.derived..)rOrCrSr^rnrEupdaterK)rrIrPrrr rds zContext.derived)rSrcCs||jkp||jkS)N)rFrL)rrSrrr __contains__tszContext.__contains__cCs||}|tkrt||S)zpLook up a variable by name with ``[]`` syntax, or raise a ``KeyError`` if the key is not found. )rerrx)rrMitemrrr rUws zContext.__getitem__cCs$dt|jd|d|jdS)NrVrWz of rX)rYr"r^rS)rrrr rZszContext.__repr__)N)N)N)$r"r#r$r[rdr%ClassVarbool__annotations__riDictr(r\OptionalCallableIteratorMutableMappingrRUnionrsryrfrer|r^rrrrcrJkeysvaluesrKrrUrZrrrr rBs* X    *$    c@szeZdZdZedejejdgejefe ddddZ e ej ddd d Z eedd d Zeedd dZdS)rTz"One block on a template reference.rBN)rSrPstackrrcCs||_||_||_||_dS)N)rS_context_stack_depth)rrSrPrrrrr rRszBlockReference.__init__)rTr/)rcCsJ|jdt|jkr0|jjjd|jdddSt|j|j|j|jdS)zSuper the block.rz there is no parent block called rrrs)rS)rlenrrrCrvrSrT)rrrr rsszBlockReference.supercs<tdd|j|j|j2IdH}|jjjr8t|S|S)Nc s.g|y 3dH}Wn tk s"X|qYS)N)StopAsyncIteration)rjr1rrr s z.BlockReference._async_call..)rrrrrn autoescaper)rrzrrr _async_calls $ zBlockReference._async_callcCs>|jjjr|St|j|j|j}|jjjr:t |S|S)N) rrCis_asyncrrrrrnrr)rrzrrr r!s   zBlockReference.__call__)r"r#r$r[r(r%Listrrr'rRpropertyrrsrrr!rrrr rTs rTc@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_valuerr/r)iterablervrecursedepth0rcCs(||_|||_||_||_||_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)rrrvrrrrr rRs  zLoopContext.__init__)rrcCst|S)N)iter)rrrr rszLoopContext._to_iterator)rcCsl|jdk r|jSyt|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 TypeErrorrrrrtrr)rrrrr lengths    zLoopContext.lengthcCs|jS)N)r)rrrr __len__szLoopContext.__len__cCs |jdS)zBHow many levels deep a recursive loop currently is, starting at 1.r)r)rrrr rszLoopContext.depthcCs |jdS)z-Current iteration of the loop, starting at 1.r)index0)rrrr rtszLoopContext.indexcCs |j|jS)zrNumber of iterations from the end of the loop, ending at 0. Requires calculating :attr:`length`. )rrt)rrrr revindex0szLoopContext.revindex0cCs |j|jS)zrNumber of iterations from the end of the loop, ending at 1. Requires calculating :attr:`length`. )rr)rrrr revindexszLoopContext.revindexcCs |jdkS)z0Whether this is the first iteration of the loop.r)r)rrrr 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. )rrnextr)rrrr _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. )rr)rrrr lastszLoopContext.lastcCs|jr|dS|jS)zZThe item in the previous iteration. Undefined during the first iteration. zthere is no previous item)rrr)rrrr 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. zthere is no next item)rrr)rrzrrr nextitem3s  zLoopContext.nextitem)r~rcGs|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)rr~rrr cycleCszLoopContext.cycle)rNrcGs|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)rrNrrr changedNs zLoopContext.changedcCs|S)Nr)rrrr __iter__ZszLoopContext.__iter__cCsF|jtk r|j}t|_n t|j}|jd7_|j|_||_||fS)Nr)rrrrrrr)rrzrrr __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)rrr)rrrrr r!is zLoopContext.__call__cCs"dt|jd|jd|jdS)NrVrW/rX)rYr"rtr)rrrr rZwszLoopContext.__repr__)Nr).r"r#r$r[rrr%rr'rrrr\rrrr&rTyperR staticmethodrrrrrrrtrrrrrrrrrrrrTuplerrr(r!rZrrrr r)sN        c@seZdZUejejed<eejej e ej e feje dddZ e edddZe eddd Ze edd d Zejdd d Ze edddZe ejejdfdddZddddZejejdfdddZdS)r0r)rrcCst|S)N)r)rrrr r~szAsyncLoopContext._to_iterator)rcsx|jdk r|jSyt|j|_WnPtk rpdd|j2IdH}|||_t||j|jtk |_YnX|jS)Nc s.g|y 3dH}Wn tk s"X|qYS)N)r)rjr1rrr rs z+AsyncLoopContext.length..) rrrrrrrtrr)rrrrr rs   zAsyncLoopContext.lengthcs|jIdH|jS)N)rrt)rrrr rszAsyncLoopContext.revindex0cs|jIdH|jS)N)rr)rrrr rszAsyncLoopContext.revindexcsH|jtk r|jSy|jIdH|_Wntk r@t|_YnX|jS)N)rrr __anext__r)rrrr rs  zAsyncLoopContext._peek_nextcs|IdHtkS)N)rr)rrrr rszAsyncLoopContext.lastr/cs$|IdH}|tkr |dS|S)Nzthere is no next item)rrr)rrzrrr rs zAsyncLoopContext.nextitemcCs|S)Nr)rrrr __aiter__szAsyncLoopContext.__aiter__csL|jtk r|j}t|_n|jIdH}|jd7_|j|_||_||fS)Nr)rrrrrrr)rrzrrr rs zAsyncLoopContext.__anext__N)r"r#r$r% AsyncIteratorr\rrrr&r AsyncIterablerrr'rrrrrrrrrrrrrr r0{s"   c @seZdZdZddejdefeejeeeeej edddZ e e ej ej edd d Zejej eed d d Zejej eed ddZedddZdS)r+zWraps a macro function.Nr.)rCfuncrS arguments catch_kwargs catch_varargscallerdefault_autoescapec Csl||_||_t||_||_||_||_||_||_d|k|_ |dkrbt |j r\| d}n|j }||_ dS)Nr) _environment_funcr_argument_countrSrrrrexplicit_callercallabler_default_autoescape) rrCrrSrrrrrrrr rRs     zMacro.__init__)r~rrc Os|r*t|dtr*|dj}|dd}n|j}t|d|j}t|}d}||jkrx`|jt|dD]B}y||}Wnt k rt }YnX|dkrd}| |qlWn|j }|j r|s|dd} | dkr|jjddd} | | |jr| |n@|rFd|kr(td|jd td|jd tt||jrd| ||jdn.t||jkrtd|jd t|jd |||S) NrrFrTzNo caller defined)rSzmacro 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))r{r rrrrrrrrxrr6rrrrvrrrSrrr_invoke) rr~rrroffZ found_callerrSrNrrrr r!sH        zMacro.__call__)rrrcs |j|IdH}|rt|S|S)N)rr)rrrrzrrr _async_invoke0szMacro._async_invokecCs.|jjr|||S|j|}|r*t|}|S)N)rrrrr)rrrrzrrr r8s   z Macro._invoke)rcCs0|jdkrdnt|j}dt|jd|dS)NZ anonymousrVrWrX)rSreprrYr")rrSrrr rZCszMacro.__repr__)N)r"r#r$r[r%rr(rrrrRrrr\r!rrrZrrrr r+s 4L c@seZdZdZdZdedefeje ej eje ej e ddddZ ee ddd Zeej ej d d d d Zee ej dddZeZZZZeZZZZeZZeZZeZZ eZ!Z"eZ#Z$eZ%Z&Z'Z(eZ)Z*Z+eZ,Z-ej e.dddZ/ej e.dddZ0e1dddZ2e dddZ3e1dddZ4ej5ej dddZ6ej7ej dddZ8e.dd d!Z9e dd"d#Z:dS)$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_exceptionN)hintobjrSexcrcCs||_||_||_||_dS)N)rrrr)rrrrSrrrr rR^szUndefined.__init__)rcCsZ|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 )rrrrr{r(r)rrrr _undefined_messagejs   zUndefined._undefined_messagez te.NoReturn)r~rrcOs||jdS)zeRaise an :exc:`UndefinedError` when operations are performed on the undefined value. N)rr)rr~rrrr _fail_with_undefined_errorsz$Undefined._fail_with_undefined_error)rSrcCs |dddkrt||S)Nr<__)AttributeErrorr)rrSrrr __getattr__szUndefined.__getattr__)otherrcCst|t|kS)N)rY)rrrrr __eq__szUndefined.__eq__cCs || S)N)r)rrrrr __ne__szUndefined.__ne__cCs tt|S)N)idrY)rrrr __hash__szUndefined.__hash__cCsdS)Nr4r)rrrr __str__szUndefined.__str__cCsdS)Nrr)rrrr rszUndefined.__len__ccsdEdHdS)Nrr)rrrr rszUndefined.__iter__cCsxdD] }dVqWdS)Nrr)r_rrr rs zUndefined.__aiter__cCsdS)NFr)rrrr __bool__szUndefined.__bool__cCsdS)Nr/r)rrrr rZszUndefined.__repr__);r"r#r$r[ __slots__rr r%rr(r\rr rRrrrrr__add____radd____sub____rsub____mul____rmul__Z__div__Z__rdiv__ __truediv__ __rtruediv__ __floordiv__ __rfloordiv____mod____rmod____pos____neg__r!rU__lt____le____gt____ge____int__ __float__ __complex____pow____rpow__rrrr'rrrrrrrrrZrrrr r/HsB   zlogging.Logger)loggerbasercsZdkr,ddl}|t|tjtddfdd Gfddd|}|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`. Nr)undefrcsd|jdS)NzTemplate variable warning: %s)warningr)r)rrr _log_messagesz,make_logging_undefined.._log_messagecsteZdZdZejejddfdd Zedfdd Zej ejdfd d Z e dfd d Z Z S) z0make_logging_undefined..LoggingUndefinedrz te.NoReturn)r~rrc sLytj||Wn4|jk rF}zd||Wdd}~XYnXdS)NzTemplate variable error: %s)rsrrerror)rr~re) __class__rrr rs  zKmake_logging_undefined..LoggingUndefined._fail_with_undefined_error)rcs|tS)N)rsr)r)r rrr rsz8make_logging_undefined..LoggingUndefined.__str__cs|tS)N)rsr)r)r rrr rsz9make_logging_undefined..LoggingUndefined.__iter__cs|tS)N)rsr)r)r rrr rsz9make_logging_undefined..LoggingUndefined.__bool__)r"r#r$rr%r\rr(rrrrr __classcell__r)rr)r r LoggingUndefineds r )logging getLoggerr" addHandler StreamHandlersysstderrr/)rrr r r)rrr make_logging_undefineds rc@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)rcCst|S)N)r()rrrr r3szChainableUndefined.__html__)rrcCs|S)Nr)rrrrr r szChainableUndefined.__getattr__N) r"r#r$r[rr(r3rrUrrrr rs rc@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)rcCsL|jrd|j}n,|jtkr&|j}ndt|jd|jd}d|dS)Nzundefined value printed: zno such element: []z{{ z }})rrrrr)rmessagerrr rs  zDebugUndefined.__str__N)r"r#r$r[rr(rrrrr rs rc@s:eZdZdZdZejZZZ ejZ Z Z Z ejZdS)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 rN)r"r#r$r[rr/rrrrrrrrrrrrr r/s r)NFNN)Ir[r`rtypingr% collectionsr itertoolsrZ markupsaferrrZ async_utilsrr exceptionsr r r Znodesr utilsrrrrrrrTypeVarrrr\r TYPE_CHECKINGr Ztyping_extensionsterCrZProtocolrZexportedZasync_exportedr.r&r(r,r-rArrrrrMappingrOr*rcregisterrBrTr)r0r+r/rrrrrrrrrr s                      hl0FGq: