• File: runtime.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/mako/__pycache__/runtime.cpython-37.pyc
  • Date Modified: 06/27/2022 10:09 PM
  • File size: 27.06 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

C]m@sXdZddlZddlZddlmZddlmZddlmZddlmZGddde	Z
Gd	d
d
eZGddde	Z
e
Zd
ZGddde	ZGddde	ZGddde	ZGddde	ZGdddeZGdddeZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd7d(d)Zd8d+d,Zd-d.Zd/d0Z d1d2Z!d9d3d4Z"d5d6Z#dS):zdprovides runtime services for templates, including Context,
Namespace, and various helper functions.N)compat)
exceptions)util)compat_builtinsc@seZdZdZddZddZeddZedd	Zd
dZ	dd
Z
ddZddZddZ
ddZddZddZd'ddZddZdd Zd!d"Zd#d$Zd%d&ZdS)(ContextzProvides runtime namespace, output buffer, and various
    callstacks for templates.

    See :ref:`runtime_toplevel` for detail on the usage of
    :class:`.Context`.

     cKsR|g|_||_||_d|_d|_i|_tt	||jd<t
|_|jd<dS)Ncapturecaller)
_buffer_stack_datacopy_kwargs_with_template_outputting_as_unicode
namespaces	functoolspartialrCallerStackcaller_stack)selfbufferdatar=/opt/alt/python37/lib/python3.7/site-packages/mako/runtime.py__init__s
zContext.__init__cCs0||_|j|j}|r,tdd|dS)Nz%Reserved words passed to render(): %sz, )r
Zreserved_namesintersectionr
rZNameConflictErrorjoin)rtZ
illegal_namesrrr_set_with_template.szContext._set_with_templatecCs|jjS)z]Return the :class:`.TemplateLookup` associated
        with this :class:`.Context`.

        )r
lookup)rrrrr7szContext.lookupcCs
|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)}

        )rr)rrrrkwargs?szContext.kwargscCs|j|dS)zQPush a ``caller`` callable onto the callstack for
        this :class:`.Context`.N)rappend)rrrrrpush_callerUszContext.push_callercCs|jd=dS)zPPop a ``caller`` callable onto the callstack for this
        :class:`.Context`.N)r)rrrr
pop_caller[szContext.pop_callercCst|jS)zAReturn a list of all names established in this :class:`.Context`.)listr
keys)rrrrr%aszContext.keyscCs"||jkr|j|Stj|SdS)N)r
r__dict__)rkeyrrr__getitem__fs

zContext.__getitem__cCst}|j||jS)zUpush a capturing buffer onto this Context and return
        the new writer function.)rFastEncodingBufferr	r write)rbufrrr_push_writerlszContext._push_writercCs|j}||jdjfS)zupop the most recent capturing buffer from this Context
        and return the current writer after the pop.

        r")r	popr*)rr+rrr_pop_buffer_and_writerts
zContext._pop_buffer_and_writercCs|dS)z*push a capturing buffer onto this Context.N)r,)rrrr_push_buffer}szContext._push_buffercCs
|jS)z7pop the most recent capturing buffer from this Context.)r	r-)rrrr_pop_bufferszContext._pop_bufferNcCs|j|tj||S)z+Return a value from this :class:`.Context`.)r
getrr&)rr'defaultrrrr1szContext.getcCs|jd|dS)zSWrite a string to this :class:`.Context` object's
        underlying output buffer.r"N)r	r*)rstringrrrr*sz
Context.writecCs|jdjS)z#Return the current writer function.r")r	r*)rrrrwriterszContext.writercCsJtt}|j|_|j|_|j|_|j|_|j|_|j|_|j	|_	|S)N)
r__new__r	r
rrr
rrr)rcrrr_copys
z
Context._copycCs |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.


        )r7r
update)rdr6rrr_localss
zContext._localscCs6|}|j}|dd|dd|dd|S)zfcreate a new copy of this :class:`.Context`. with
        tokens related to inheritance state removed.rNparentnext)r7r
r-)rr6xrrr_clean_inheritance_tokenssz!Context._clean_inheritance_tokens)N)__name__
__module____qualname____doc__rrpropertyrrr!r#r%r(r,r.r/r0r1r*r4r7r:r>rrrrrs&		
rc@sDeZdZddZddZddZddZd	d
ZddZd
dZ	dS)rcCs
d|_dS)N)
nextcaller)rrrrrszCallerStack.__init__cCs|S)N)__bool__)rrrr__nonzero__szCallerStack.__nonzero__cCst|r|rdpdS)NTF)len_get_caller)rrrrrEszCallerStack.__bool__cCs|dS)Nr"r)rrrrrHszCallerStack._get_callercCst||S)N)getattrrH)rr'rrr__getattr__szCallerStack.__getattr__cCs|jpd}||d|_|S)N)rDr )rframerrr_push_frames

zCallerStack._push_framecCs||_dS)N)r-rD)rrrr
_pop_frameszCallerStack._pop_frameN)
r?r@rArrFrErHrJrLrMrrrrrsrc@s(eZdZdZddZddZddZdS)		UndefinedzRepresents an undefined value in a template.

    All template modules have a constant value
    ``UNDEFINED`` present which is an instance of this
    object.

    cCstddS)NrN)	NameError)rrrr__str__szUndefined.__str__cCs|S)N)rE)rrrrrFszUndefined.__nonzero__cCsdS)NFr)rrrrrEszUndefined.__bool__N)r?r@rArBrPrFrErrrrrNsrNc@sTeZdZdZddZddZddZedd	Zd
dZ	dd
Z
ddZddZdS)	LoopStackza stack for LoopContexts that implements the context manager protocol
    to automatically pop off the top of the stack on context exit
    cCs
g|_dS)N)stack)rrrrrszLoopStack.__init__cCs|||jS)N)_push_top)riterablerrr_enters
zLoopStack._entercCs||jS)N)_poprU)rrrr_exitszLoopStack._exitcCs|jr|jdS|SdS)Nr")rS)rrrrrUs
zLoopStack._topcCs
|jS)N)rSr-)rrrrrXszLoopStack._popcCs&t|}|jr|jd|_|j|S)Nr")LoopContextrSr;r )rrVnewrrrrTszLoopStack._pushcCstddS)NzNo loop context is established)rRuntimeException)rr'rrrrJszLoopStack.__getattr__cCs
t|jS)N)iterrU)rrrr__iter__szLoopStack.__iter__N)
r?r@rArBrrWrYrCrUrXrTrJr^rrrrrRsrRc@sreZdZdZddZddZejddZe	dd	Z
e	d
dZe	dd
Ze	ddZ
e	ddZddZdS)rZaA 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.
    cCs||_d|_d|_dS)Nr)	_iterableindexr;)rrVrrrr3szLoopContext.__init__ccs(x"|jD]}|V|jd7_qWdS)N)r_r`)rirrrr^8szLoopContext.__iter__cCs
t|jS)N)rGr_)rrrr__len__=szLoopContext.__len__cCst||jdS)Nra)rGr`)rrrr
reverse_indexAszLoopContext.reverse_indexcCs
|jdkS)Nr)r`)rrrrfirstEszLoopContext.firstcCs|jt|dkS)Nra)r`rG)rrrrlastIszLoopContext.lastcCs|jS)N)odd)rrrrevenMszLoopContext.evencCst|jdS)N)boolr`)rrrrrgQszLoopContext.oddcGs|std||jt|S)z5Cycle through values as the loop progresses.
        z(You must provide values to cycle through)
ValueErrorr`rG)rvaluesrrrcycleUszLoopContext.cycleN)r?r@rArBrr^rZmemoized_instancemethodrcrCrdrerfrhrgrmrrrrrZsrZc@seZdZddZddZdS)_NSAttrcCs
||_dS)N)_NSAttr__parent)rr;rrrr^sz_NSAttr.__init__cCs:|j}x&|r,t|j|r$t|j|S|j}qWt|dS)N)rohasattrmodulerIinheritsAttributeError)rr'nsrrrrJas
z_NSAttr.__getattr__N)r?r@rArrJrrrrrn]srnc@seZdZdZdddZdZdZdZdZdZ	dZ
dZej
ddZd	d
ZddZd
dZeddZddZddZddZddZdS)	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.

      NTcCs2||_||_||_|dk	r.tdd|D|_dS)NcSsg|]}|j|fqSr)r?).0r6rrr
<listcomp>sz&Namespace.__init__.<locals>.<listcomp>)namecontextrrdict	callables)rrxryr{rr
populate_selfcalling_urirrrr|s
	zNamespace.__init__rcCst|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`

        )rn)rrrrattrszNamespace.attrcCsL||f}||jjkr |jj|St||j||jd}||jj|<|SdS)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}N)ryrTemplateNamespacer7_templateuri)rurir'rtrrr
get_namespaces
zNamespace.get_namespacecCst|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_templateryr)rrrrrget_templateszNamespace.get_templatecKs|jj|f|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>``.

        )cacher1)rr'rrrr
get_cachedszNamespace.get_cachedcCs|jjS)zReturn the :class:`.Cache` object referenced
        by this :class:`.Namespace` object's
        :class:`.Template`.

        )templater)rrrrrszNamespace.cachecKst|j||jf|dS)z$Include a file at the given ``uri``.N)
_include_fileryr)rrrrrrinclude_fileszNamespace.include_filecCsHxB|D]:}|dkr2x,|D]\}}|||<qWqt||||<qWdS)N*)	_get_starrI)rr9lZidentkvrrr	_populates

zNamespace._populateccs*|jr&x|jD]}||j|fVqWdS)N)r{)rr'rrrrszNamespace._get_starcCsL||jkr|j|}n&|jr*t|j|}ntd|j|ft||||S)Nz!Namespace '%s' has no member '%s')r{rrrIrsrxsetattr)rr'valrrrrJ!s
zNamespace.__getattr__)NNTN)r?r@rArBrr{rqrryfilenamerrrZmemoized_propertyr~rrrrCrrrrrJrrrrruks*
		!		ruc@sNeZdZdZdddZeddZedd	Zed
dZdd
Z	ddZ
dS)rz@A :class:`.Namespace` specific to a :class:`.Template` instance.NTc	Cs||_||_||_|dk	r.tdd|D|_|dk	rRt||||_|jjj|_	n"|dk	rl||_|jj|_	nt
d|rt||j|d\}	}
dS)NcSsg|]}|j|fqSr)r?)rvr6rrrrwAsz.TemplateNamespace.__init__.<locals>.<listcomp>z 'template' argument is required.)self_ns)rxryrrrzr{rrrqZ
_template_urir	TypeError_populate_self_namespace)rrxryrrr{rrr|r}Zlclcallable
lclcontextrrrr2szTemplateNamespace.__init__cCs|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.

        )rrq)rrrrrqQs	zTemplateNamespace.modulecCs|jjS)zhThe path of the filesystem file used for this
        :class:`.Namespace`'s module or template.
        )rr)rrrrr\szTemplateNamespace.filenamecCs|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`.

        )rr)rrrrrcs	zTemplateNamespace.uric#sXjr&xjD]}|j|fVqWfdd}x jjjD]}|||fVq>WdS)Ncsj|}t|jS)N)r_get_def_callablerrry)r'	callable_)rrrr1ssz(TemplateNamespace._get_star.<locals>.get)r{rrqZ_exports)rr'r1rr)rrrnszTemplateNamespace._get_starcCst||jkr|j|}nN|j|r>|j|}t||j}n&|jrRt|j|}nt	d|j
|ft||||S)Nz!Namespace '%s' has no member '%s')r{rZhas_defrrrryrrrIrsrxr)rr'rrrrrrJzs
zTemplateNamespace.__getattr__)NNNNTN)r?r@rArBrrCrqrrrrJrrrrr.s
rc@s6eZdZdZdddZeddZdd	Zd
dZdS)
ModuleNamespacez;A :class:`.Namespace` specific to a Python module instance.NTc
Csf||_||_||_|dk	r.tdd|D|_t|}x$|dddD]}	t||	}qJW||_dS)NcSsg|]}|j|fqSr)r?)rvr6rrrrwsz,ModuleNamespace.__init__.<locals>.<listcomp>.ra)	rxryrrrzr{
__import__splitrIrq)
rrxryrqr{rrr|r}modtokenrrrrs
zModuleNamespace.__init__cCs|jjS)zhThe path of the filesystem file used for this
        :class:`.Namespace`'s module or template.
        )rq__file__)rrrrrszModuleNamespace.filenameccsr|jr&x|jD]}||j|fVqWxFt|jD]8}|ddkr2t|j|}t|r2|t||jfVq2WdS)Nr_)r{dirrqrIcallablerrry)rr'rrrrrszModuleNamespace._get_starcCst||jkr|j|}nNt|j|r>t|j|}t||j}n&|jrRt|j|}ntd|j	|ft
||||S)Nz!Namespace '%s' has no member '%s')r{rprqrIrrryrrrsrxr)rr'rrrrrrJs
zModuleNamespace.__getattr__)NNTN)	r?r@rArBrrCrrrJrrrrrs


rcsfdd}|S)zApply a caller_stack compatibility decorator to a plain
    Python function.

    See the example in :ref:`namespaces_python_modules`.

    cs,|jz|f||S|jXdS)N)rrLrM)ryargsr)funcrrwrap_stackframes
z(supports_caller.<locals>.wrap_stackframer)rrr)rrsupports_callersrcOs<t|std|z|||Wd|}X|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))N)rrr\r/r0getvalue)ryrrrr+rrrrs
rcsfdd}|S)Ncsfdd}|S)NcsLfdd}yjdd|_Wntk
r6YnX|f||S)Ncsf||S)Nr)rkw)ry	render_fnrryszB_decorate_toplevel.<locals>.decorate_render.<locals>.go.<locals>.y)r?r)ryrrr)fnr)ryrgosz7_decorate_toplevel.<locals>.decorate_render.<locals>.gor)rr)r)rrdecorate_rendersz+_decorate_toplevel.<locals>.decorate_renderr)rrr)rr_decorate_toplevelsrcsfdd}|S)Ncs|fdd}|S)Ncsf||S)Nr)rr)rydecrrrsz5_decorate_inline.<locals>.decorate_render.<locals>.gor)rr)ryr)rrrsz)_decorate_inline.<locals>.decorate_renderr)ryrrr)ryrr_decorate_inlinesrcKst|||}t||\}}t||jf|}|jr~y||f|Wqtk
rz||t}|svtj	t
YqXn||f|dS)zPlocate the template from the given uri and include it in
    the current output.N)rrr>_kwargs_for_includer
Zinclude_error_handler	Exceptionrexception_asreraisesysexc_info)ryrr}rrrZctxresultrrrr
src
Cs|dkrdSt|||}|d}|}x|jdk	r8|j}q&W|d|i}td|j||dd|_|j|jd<|jd<t|jd	d}|dk	r|||}|r|St|jd
d}	|	dk	r|	||j|fS)zcalled by the _inherit method in template modules to set
    up the inheritance chain at the start of a template's
    execution.Nrr<zself:%sF)rr|r;local
_mako_inheritZ_mako_generate_namespaces)	rrrr:rrr
rIrqr)
ryrr}rrZihrrretZgen_nsrrr
_inherit_froms.


rcCsf|jj}|dkr"td|jj|||}y
||Stjk
r`ttt	
YnXdS)Nz.Template '%s' has no TemplateLookup associated)r
rrZTemplateLookupExceptionrZ
adjust_urirZTopLevelLookupExceptionstrrr)ryrZ
relativetorrrrr>s
rcCs^|dkrtd|j||dd}||jd<|jd<t|jdrT|j||}|rT|S|j|fS)Nzself:%sF)rr|rrr)rrr
rprqrr)ryrrrrrrrLsrFcCsx|rtjdd}n$|jr"t}ntj||j|jd}t|f|}||_|	|t
|||f|t|||
S)z^create a Context and return the string
    output of the given template and template callable.T)
as_unicode)rencodingerrors)rr)Zbytestring_passthroughrStringIOoutput_encodingencoding_errorsrrr_render_context_kwargs_for_callabler0r)rrrrrr+ryrrr_render\s$


rcCsnt|}|dr|S|ddd|ddD}i}x0|D](}|dkr>||kr>||kr>||||<q>W|S)NrircSsg|]}|dk	r|qS)Nr)rvrrrrrwsz(_kwargs_for_callable.<locals>.<listcomp>rary)rinspect_getargspec)rrargspec	namedargsrargrrrrxs

rcKs^t|}|ddd|ddD}x0|D](}|dkr.||kr.||kr.||||<q.W|S)NrcSsg|]}|dk	r|qS)Nr)rvrrrrrwsz'_kwargs_for_include.<locals>.<listcomp>rarry)rr)rrrrrrrrrrs

rcOs\ddlm}t||js8t||\}}t||||dn t||j\}}t||||ddS)Nr)rr)Z
mako.templater
isinstanceZDefTemplater_exec_templater;)ZtmplrryrrrZinheritrrrrrsrcCs|j}|dk	rx|js|jrxy||f||Wqtk
rRt||tYqtd}t|||YqXn||f||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)	r
Zformat_exceptions
error_handlerr
_render_errorrrrr)rryrrrerrrrsrcCs|jr&|||}|stjtn\t}|jrNtj	ddg|j
dd<nt	|j|jg|j
dd<|
||j||ddS)NT)r)error)rrrrrrZhtml_error_templaterrr)r	rrrZrender_context)rryrrZerror_templaterrrrs
r)N)F)NN)$rBrrZmakorrrZmako.compatrobjectrr$rrNZ	UNDEFINEDZSTOP_RENDERINGrRrZrnrurrrrrrrrrrrrrrrrrrrr<module>sB-(BD]: