V?qdZddlZddlZddlZddlmZddlmZddlmZGddZGdd e Z Gd d Z e Z d Z Gd dZGddZGddZGddZGddeZGddeZdZdZdZdZdZdZdZd(d Zd)d"Zd#Zd$Zd%Zd*d&Z d'Z!dS)+zdprovides runtime services for templates, including Context, Namespace, and various helper functions.N)compat) exceptions)utilceZdZdZdZdZedZedZdZ dZ dZ d Z d Z d Zd Zd ZddZdZdZdZdZdZdS)ContextzProvides runtime namespace, output buffer, and various callstacks for templates. See :ref:`runtime_toplevel` for detail on the usage of :class:`.Context`. c |g|_||_||_d|_d|_i|_tjt||jd<tx|_ |jd<dS)Ncapturecaller) _buffer_stack_datacopy_kwargs_with_template_outputting_as_unicode namespaces functoolspartialr CallerStack caller_stack)selfbufferdatas /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/mako/runtime.py__init__zContext.__init__st$X yy{{ "&*#!* 1'4 @ @ 94?==@DJx000c||_|j|j}|r*t jdd|zdS)Nz%Reserved words passed to render(): %sz, )rreserved_names intersectionr rNameConflictErrorjoin)rt illegal_namess r_set_with_templatezContext._set_with_template.s`(55djAA  .7))M**+   rc|jjS)z]Return the :class:`.TemplateLookup` associated with this :class:`.Context`. )rlookuprs rr%zContext.lookup7s "))rc4|jS)a]Return the dictionary of top level keyword arguments associated with this :class:`.Context`. This dictionary only includes the top-level arguments passed to :meth:`.Template.render`. It does not include names produced within the template execution such as local variable names or special names such as ``self``, ``next``, etc. The purpose of this dictionary is primarily for the case that a :class:`.Template` accepts arguments via its ``<%page>`` tag, which are normally expected to be passed via :meth:`.Template.render`, except the template is being called in an inheritance context, using the ``body()`` method. :attr:`.Context.kwargs` can then be used to propagate these arguments to the inheriting template:: ${next.body(**context.kwargs)} )rr r&s rkwargszContext.kwargs?s(|  """rc:|j|dS)zQPush a ``caller`` callable onto the callstack for this :class:`.Context`.N)rappend)rr s r push_callerzContext.push_callerUs!   (((((rc|jd=dS)zPPop a ``caller`` callable onto the callstack for this :class:`.Context`.N)rr&s r pop_callerzContext.pop_caller[s  b ! ! !rcNt|jS)zAReturn a list of all names established in this :class:`.Context`.)listr keysr&s rr1z Context.keysasDJOO%%&&&rcR||jvr |j|Stj|SN)r builtins__dict__rkeys r __getitem__zContext.__getitem__fs) $*  :c? "$S) )rcjtj}|j||jS)zUpush a capturing buffer onto this Context and return the new writer function.)rFastEncodingBufferr r*writerbufs r _push_writerzContext._push_writerls1%'' !!#&&&yrc\|j}||jdjfS)zupop the most recent capturing buffer from this Context and return the current writer after the pop. r-)r popr;r<s r_pop_buffer_and_writerzContext._pop_buffer_and_writerts.  $$&&D&r*000rc.|dS)z*push a capturing buffer onto this Context.N)r>r&s r _push_bufferzContext._push_buffer}s rc4|jS)z7pop the most recent capturing buffer from this Context.)r r@r&s r _pop_bufferzContext._pop_buffers!%%'''rNct|j|tj||S)z+Return a value from this :class:`.Context`.)r getr4r5)rr7defaults rrGz Context.gets-z~~c8#4#8#8g#F#FGGGrcF|jd|dS)zSWrite a string to this :class:`.Context` object's underlying output buffer.r-Nr r;)rstrings rr;z Context.writes& 2$$V,,,,,rc&|jdjS)z#Return the current writer function.r-rJr&s rwriterzContext.writers!"%++rctt}|j|_|j|_|j|_|j|_|j|_|j|_|j |_ |Sr3) r__new__r r r rrrrr)rcs r_copyz Context._copysg OOG $ $,*//##L .#'#>  *rcj|s|S|}|j||S)zCreate a new :class:`.Context` with a copy of this :class:`.Context`'s current state, updated with the given dictionary. The :attr:`.Context.kwargs` collection remains unaffected. )rQr update)rdrPs r_localszContext._localss7 K JJLL qrc|}|j}|dd|dd|dd|S)zfcreate a new copy of this :class:`.Context`. with tokens related to inheritance state removed.rNparentnext)rQr r@)rrPxs r_clean_inheritance_tokensz!Context._clean_inheritance_tokenssY JJLL G fd h fdrr3)__name__ __module__ __qualname____doc__rr#propertyr%r(r+r.r1r8r>rArCrErGr;rMrQrUrZrrrrsPAAA"**X*##X#*))) """ ''' *** 111 ((( HHHH --- ,,,   "     rrc8eZdZdZdZdZdZdZdZdZ dS) rcd|_dSr3) nextcallerr&s rrzCallerStack.__init__s rc*|Sr3__bool__r&s r __nonzero__zCallerStack.__nonzero__}}rcPt|r|rdpdS)NTF)len _get_callerr&s rrfzCallerStack.__bool__s)4yy8T--//8DAEArc|dSNr-r`r&s rrkzCallerStack._get_callers BxrcFt||Sr3)getattrrkr6s r __getattr__zCallerStack.__getattr__st''))3///rcP|jpd}||d|_|Sr3)rcr*)rframes r _push_framezCallerStack._push_frames,'4 E rc8||_dSr3)r@rcr&s r _pop_framezCallerStack._pop_frames((**rN) r[r\r]rrgrfrkrprsrur`rrrrsBBB 000 %%%%%rrc$eZdZdZdZdZdZdS) UndefinedzRepresents an undefined value in a template. All template modules have a constant value ``UNDEFINED`` present which is an instance of this object. c td)Nrw) NameErrorr&s r__str__zUndefined.__str__s $$$rc*|Sr3rer&s rrgzUndefined.__nonzero__rhrcdS)NFr`r&s rrfzUndefined.__bool__surN)r[r\r]r^rzrgrfr`rrrwrwsK%%%rrwcReZdZdZdZdZdZedZdZ dZ dZ d Z d S) LoopStackza stack for LoopContexts that implements the context manager protocol to automatically pop off the top of the stack on context exit cg|_dSr3stackr&s rrzLoopStack.__init__s  rc:|||jSr3)_push_topriterables r_enterzLoopStack._enters 8yrc8||jSr3)_poprr&s r_exitzLoopStack._exits yrc.|jr |jdS|Srmrr&s rrzLoopStack._tops : :b> !Krc4|jSr3)rr@r&s rrzLoopStack._pop sz~~rct|}|jr|jd|_|j|Srm) LoopContextrrWr*)rrnews rrzLoopStack._pushs<(## : (BCJz  %%%rc*tjd)NzNo loop context is established)rRuntimeExceptionr6s rrpzLoopStack.__getattr__s)*JKKKrc*t|jSr3)iterrr&s r__iter__zLoopStack.__iter__sDIrN) r[r\r]r^rrrr_rrrrprr`rrrrsX    &&& LLLrrceZdZdZdZdZejdZe dZ e dZ e dZ e dZ e d Zd Zd S) raA magic loop variable. Automatically accessible in any ``% for`` block. See the section :ref:`loop_context` for usage notes. :attr:`parent` -> :class:`.LoopContext` or ``None`` The parent loop, if one exists. :attr:`index` -> `int` The 0-based iteration count. :attr:`reverse_index` -> `int` The number of iterations remaining. :attr:`first` -> `bool` ``True`` on the first iteration, ``False`` otherwise. :attr:`last` -> `bool` ``True`` on the last iteration, ``False`` otherwise. :attr:`even` -> `bool` ``True`` when ``index`` is even. :attr:`odd` -> `bool` ``True`` when ``index`` is odd. c0||_d|_d|_dSNr) _iterableindexrWrs rrzLoopContext.__init__3s!  rc#FK|jD]}|V|xjdz c_dSN)rr)ris rrzLoopContext.__iter__8s;  AGGG JJ!OJJJ  rc*t|jSr3)rjrr&s r__len__zLoopContext.__len__=s4>"""rc6t||jz dz Sr)rjrr&s r reverse_indexzLoopContext.reverse_indexAs4yy4:%))rc|jdkSr)rr&s rfirstzLoopContext.firstEszQrc8|jt|dz kSr)rrjr&s rlastzLoopContext.lastIszSYY]**rc|j Sr3)oddr&s revenzLoopContext.evenMs 8|rc0t|jdzS)N)boolrr&s rrzLoopContext.oddQsDJN###rc^|std||jt|zS)z,Cycle through values as the loop progresses.z(You must provide values to cycle through) ValueErrorrrj)rvaluess rcyclezLoopContext.cycleUs2 IGHH Hdj3v;;.//rN)r[r\r]r^rrrmemoized_instancemethodrr_rrrrrrr`rrrrs,   !##"!#**X*X++X+X$$X$00000rrceZdZdZdZdS)_NSAttrc||_dSr3)_NSAttr__parent)rrWs rrz_NSAttr.__init__]s  rc|j}|r3t|j|rt|j|S|j}|3t |r3)rhasattrmoduleroinheritsAttributeError)rr7nss rrpz_NSAttr.__getattr__`sX ] !ry#&& !ry#...[  ! S!!!rN)r[r\r]rrpr`rrrr\s2"""""rrceZdZdZ ddZdZdZ dZ dZ dZ dZ dZ e j dZdZdZd Zed Zd Zd Zd ZdZdS) NamespaceaProvides access to collections of rendering methods, which can be local, from other templates, or from imported modules. To access a particular rendering method referenced by a :class:`.Namespace`, use plain attribute access: .. sourcecode:: mako ${some_namespace.foo(x, y, z)} :class:`.Namespace` also contains several built-in attributes described here. NTcZ||_||_||_|d|D|_dSdS)Nci|] }|j| Sr`r[.0rPs r z&Namespace.__init__..???aj!???r)namecontextr callables)rrrrr populate_self calling_uris rrzNamespace.__init__{s@     ??Y???DNNN ! rr`c t|S)a-Access module level attributes by name. This accessor allows templates to supply "scalar" attributes which are particularly handy in inheritance relationships. .. seealso:: :ref:`inheritance_attr` :ref:`namespace_attr_for_includes` )rr&s rattrzNamespace.attrst}}rc||f}||jjvr|jj|St||j||j}||jj|<|S)a]Return a :class:`.Namespace` corresponding to the given ``uri``. If the given ``uri`` is a relative URI (i.e. it does not contain a leading slash ``/``), the ``uri`` is adjusted to be relative to the ``uri`` of the namespace itself. This method is therefore mostly useful off of the built-in ``local`` namespace, described in :ref:`namespace_local`. In most cases, a template wouldn't need this function, and should instead use the ``<%namespace>`` tag to load namespaces. However, since all ``<%namespace>`` tags are evaluated before the body of a template ever runs, this method can be used to locate namespaces using expressions that were generated within the body code of the template, or to conditionally use a particular namespace. ) templateurir)rrTemplateNamespacerQ _templateuri)rurir7rs r get_namespacezNamespace.get_namespacest(Sk $,) ) )<*3/ /   L   )     (* $ rc8t|j||jS)zReturn a :class:`.Template` from the given ``uri``. The ``uri`` resolution is relative to the ``uri`` of this :class:`.Namespace` object's :class:`.Template`. )_lookup_templaterr)rrs r get_templatezNamespace.get_templates  c43DEEErc (|jj|fi|S)aReturn a value from the :class:`.Cache` referenced by this :class:`.Namespace` object's :class:`.Template`. The advantage to this method versus direct access to the :class:`.Cache` is that the configuration parameters declared in ``<%page>`` take effect here, thereby calling up the same configured backend as that configured by ``<%page>``. )cacherG)rr7r(s r get_cachedzNamespace.get_cacheds tz~c,,V,,,rc|jjS)zReturn the :class:`.Cache` object referenced by this :class:`.Namespace` object's :class:`.Template`. )templaterr&s rrzNamespace.caches}""rc 8t|j||jfi|dS)z$Include a file at the given ``uri``.N) _include_filerr)rrr(s r include_filezNamespace.include_file s) dlC):EEfEEEEErc|D];}|dkr |D] \}}|||< (t||||< 1~ 1 1DN3/00000 1 1 1 1rc||jvr|j|}n8|jrt|j|}ntd|jd|dt ||||SNz Namespace 'z' has no member '')rrrorrsetattr)rr7vals rrpzNamespace.__getattr__sy $. .%CC ] $---CC .7;yyy###F  c3 rNNTN)r[r\r]r^rrrrrfilenamerrrmemoized_propertyrrrrr_rrrrrpr`rrrrjs4  & @ @ @ @I FH GH CL  @FFF - - -##X#FFF 000111     rrcteZdZdZ d dZedZedZedZdZ d Z dS) rz@A :class:`.Namespace` specific to a :class:`.Template` instance.NTc D||_||_||_|d|D|_|-t ||||_|jjj|_n*|||_|jj|_ntd|rt||j|\} } dSdS)Nci|] }|j| Sr`rrs rrz.TemplateNamespace.__init__..?rrz 'template' argument is required.)self_ns) rrrrrrr _template_urir TypeError_populate_self_namespace) rrrrrrrrr lclcallable lclcontexts rrzTemplateNamespace.__init__0s     ??Y???DN  ",Wk;OODM $ 4 BD    !$DM ( =D  >?? ?  &>''' #K  rc|jjS)zThe Python module referenced by this :class:`.Namespace`. If the namespace references a :class:`.Template`, then this module is the equivalent of ``template.module``, i.e. the generated module for the template. )rrr&s rrzTemplateNamespace.moduleOs}##rc|jjSzhThe path of the filesystem file used for this :class:`.Namespace`'s module or template. )rrr&s rrzTemplateNamespace.filenameZs }%%rc|jjS)zThe URI for this :class:`.Namespace`'s template. I.e. whatever was sent to :meth:`.TemplateLookup.get_template()`. This is the equivalent of :attr:`.Template.uri`. )rrr&s rrzTemplateNamespace.urias}  rc#KjrjD]}|j|fVfd}jjjD]}|||fVdS)Nclj|}tj|jSr3)r_get_def_callablerrr)r7 callable_rs rrGz(TemplateNamespace._get_star..getqs- 77< 1~ 1 1DN3/00000 > > > > >%.  Acc!ff+      rcd||jvr|j|}n|j|r5|j|}t j||j}n8|jrt|j|}ntd|j d|dt||||Sr) rrhas_defrrrrrrorrrrr7rrs rrpzTemplateNamespace.__getattr__xs $. .%CC ] " "3 ' '  77<$$X$&&X& !!X!   rrcDeZdZdZ ddZedZdZdZdS) ModuleNamespacez;A :class:`.Namespace` specific to a Python module instance.NTc||_||_||_|d|D|_t |}|dddD]} t || }||_dS)Nci|] }|j| Sr`rrs rrz,ModuleNamespace.__init__..rr.r)rrrr __import__splitror) rrrrrrrrmodtokens rrzModuleNamespace.__init__s     ??Y???DN  \\#&&qrr* & &E#u%%CC rc|jjSr)r__file__r&s rrzModuleNamespace.filenames {##rc#K|jr|jD]}||j|fVt|jD]P}|ddkrBt|j|}t |r|t j||jfVQdS)Nr_)rdirrrocallablerrr)rr7rs rrzModuleNamespace._get_stars > 1~ 1 1DN3/00000t{## J JC1v}}#DK55 I&&Jy0DLIIIIII  J JrcP||jvr|j|}n}t|j|r0t|j|}t j||j}n8|jrt|j|}ntd|j d|dt||||Sr) rrrrorrrrrrrrs rrpzModuleNamespace.__getattr__s $. .%CC T[# & &  S11I#It|<.wrap_stackframesm((*** .41$111&11  + + - - - -G + + - - - -s AAr`)rrs` rsupports_callerrs$..... rct|stjd| ||i||}n#|}wxYw|S)zExecute the given template def, capturing the output into a buffer. See the example in :ref:`namespaces_python_modules`. z[capture() function expects a callable as its argument (i.e. capture(func, *args, **kwargs)))rrrrCrEgetvalue)rrrr(r=s rr r s I   ) A    $ 4"6"""!!##g!!###### <<>>s AA,cfd}|S)Ncfd}|S)Ncfd} jdd|_n#t$rYnwxYw|g|Ri|S)Ncg|Ri|Sr3r`)rkwr render_fns ryzB_decorate_toplevel..decorate_render..go..ys# y646662666r)r[r)rrrr!fnr s` rgoz7_decorate_toplevel..decorate_render..gos 7 7 7 7 7 7 &/3     22a55.4...2.. .s  ,,r`)r r$r#s` rdecorate_renderz+_decorate_toplevel..decorate_renders) / / / / / / rr`)r#r%s` r_decorate_toplevelr&s$      rcfd}|S)Nc,|fd}|S)Ncg|Ri|Sr3r`)rrrdecs rr$z5_decorate_inline..decorate_render..gos#3w,,,,,, ,rr`)r r$r*rr#s @rr%z)_decorate_inline..decorate_renders6bmm - - - - - - rr`)rr#r%s`` r_decorate_inliner+s* rc Ft|||}t||\}}t||jfi|}|jrG ||fi|dS#t $r.||tj}|sYdSwxYw||fi|dS)zPlocate the template from the given uri and include it in the current output.N) rrrZ_kwargs_for_includer include_error_handler Exceptionr exception_as)rrrr(rrctxresults rrrs k::H/))++XY!GM D DV D DF%!  Ic $ $V $ $ $ $ $   33C9L9N9NOOF       #       s A4BBc|dSt|||}|d}|}|j|j}|j|d|i}td|jz||d|_|jx|jd<|jd<t |jd d}||||}|r|St |jd d} | | ||j|fS) zcalled by the _inherit method in template modules to set up the inheritance chain at the start of a template's execution.NrrXself:%sFrrrWlocal _mako_inherit_mako_generate_namespaces) rrrUrrr rorr) rrrrrihrrretgen_nss r _inherit_fromr<s   {tk::HfoG B + ! [ + !&"..J#HL  BK ;=+EGM(j.w7$??Ii*--  J X_&A4 H HF w   ++rcL|jj}|!tjd|jjz|||} ||S#tj$r8}tjttj |d}~wwxYw)Nz.Template '%s' has no TemplateLookup associated) rr%rTemplateLookupExceptionr adjust_urirTopLevelLookupExceptionstrrr0)rr relativetor%es rrr<s  # *F ~0 <$( )      C , ,C""3'''  -0 #%% & &   sAB#+3BB#c|td|jz||d}|x|jd<|jd<t|jdr|j||}|r|S|j|fS)Nr4Fr5rr6r7)rrr rrr7r)rrrr:s rrrLs#  $      6=>  J   ((rFcL|rtj}n tj|j|j}t |fi|}||_||t|||g|Rit||| S)z^create a Context and return the string output of the given template and template callable.)encodingerrors) rr:output_encodingencoding_errorsrrr#_render_context_kwargs_for_callablerEr)rrrr as_unicoder=rs r_renderrM\s %''%-h6N   c""T""G%/G" x(((   y$ / /     ) ) + ++rctj|}|dr|S|dd|ddDz}i}|D]}|dkr||vr||vr ||||<|S)Nrrcg|]}||Sr3r`rrs r z(_kwargs_for_callable..{GGGAarrrrinspect_getargspec)rrargspec namedargsr(args rrKrKts' 22Gqz  GG1GGGGI F$$ )  t 60A0As)F3K Mrc tj|}|dd|ddDz}|D]}|dkr||vr||vr ||||<|S)Nrcg|]}||Sr3r`rPs rrQz'_kwargs_for_include..rRrrrSrrT)rrr(rVrWrXs rr-r-sv' 22G GG1GGGGI$$ )  t 60A0As)F3K Mrcddlm}t||js(t ||\}}t ||||dSt ||j\}}t ||||dS)Nr)rr() mako.templater isinstance DefTemplater_exec_templaterW)tmplrrrr(rinheritrs rrJrJs$$$$$$ dH0 1 1E 8$ G G*w fEEEEEE!9$+ N N*y'VDDDDDDrc*|j}|}|js|jro ||g|Ri|dS#t$r&t ||t jYdStjd}t |||YdSxYw||g|Ri|dS)zexecute a rendering callable given the callable, a Context, and optional explicit arguments the contextual Template will be located if it exists, and the error handling options specified on that Template will be interpreted here. Nr) rformat_exceptions error_handlerr/ _render_errorrr0sysexc_info)rrrr(rrCs rr_r_s%H"&.&< 0 Ig / / / / / / / / / D D D (GV-@-B-B C C C C C C 0 q!A (GQ / / / / / / '+D+++F+++++s ',B+Bc|jrL|||}|s2tj\}}}|r|r|||dSt j}|jrtjg|j dd<n*tj|j |j g|j dd<| || ||dS)N)error)rdrfrgwith_tracebackrhtml_error_templaterrr:r rHrIr#render_context)rrrir2tpvaluetberror_templates rreres<''77 LNNMBr  **2...   $799  ) (,(?(A(A'BG !!!! $ $'"2"2(G !!!! $ "">222%%gU%;;;;;rr3)F)NN)"r^r4rrfmakorrrrr0rrw UNDEFINEDSTOP_RENDERINGrrrrrrrr r&r+rr<rrrMrKr-rJr_rer`rrrts,, iiiiiiiiX%%%%%$%%%8( IKK %%%%%%%%P>0>0>0>0>0>0>0>0B " " " " " " " "DZZZZZ ZZZz77777i777t$*$   !!!(,,,@    ) ) ) ) ,,,,0    E E E,,,,.<<<<