HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/mako/__pycache__/runtime.cpython-310.pyc
o

%we�l�@sHdZddlZddlZddlZddlmZddlmZddlmZGdd�d�ZGdd	�d	e	�Z
Gd
d�d�Ze�ZdZ
Gd
d�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�de�ZGdd�de�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd6d'd(�Zd7d*d+�Zd,d-�Zd.d/�Zd0d1�Zd8d2d3�Z d4d5�Z!dS)9zdprovides runtime services for templates, including Context,
Namespace, and various helper functions.�N)�compat)�
exceptions)�utilc@s�eZdZdZdd�Zdd�Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd'dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�ZdS)(�Contextz�Provides 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|_t�t	|�|jd<t
�|_|jd<dS)N�capture�caller)�
_buffer_stack�_data�copy�_kwargs�_with_template�_outputting_as_unicode�
namespaces�	functools�partialr�CallerStack�caller_stack)�self�buffer�data�r�E/home/arjun/projects/env/lib/python3.10/site-packages/mako/runtime.py�__init__s
zContext.__init__cCs0||_|j�|j�}|rt�dd�|���dS)Nz%Reserved words passed to render(): %sz, )r�reserved_names�intersectionr	r�NameConflictError�join)r�t�
illegal_namesrrr�_set_with_template.s���zContext._set_with_templatecC�|jjS)z]Return the :class:`.TemplateLookup` associated
        with this :class:`.Context`.

        )r�lookup�rrrrr!7szContext.lookupcC�
|j��S)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"rrr�kwargs?s
zContext.kwargscCs|j�|�dS)zQPush a ``caller`` callable onto the callstack for
        this :class:`.Context`.N)r�append)rrrrr�push_callerUszContext.push_callercCs|jd=dS)zPPop a ``caller`` callable onto the callstack for this
        :class:`.Context`.���N)rr"rrr�
pop_caller[szContext.pop_callercCst|j���S)zAReturn a list of all names established in this :class:`.Context`.)�listr	�keysr"rrrr*aszContext.keyscCs||jvr
|j|Stj|S�N)r	�builtins�__dict__�r�keyrrr�__getitem__fs


zContext.__getitem__cCst��}|j�|�|jS)zUpush a capturing buffer onto this Context and return
        the new writer function.)r�FastEncodingBufferrr%�write�r�bufrrr�_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�popr2r3rrr�_pop_buffer_and_writerts
zContext._pop_buffer_and_writercCs|��dS)z*push a capturing buffer onto this Context.N)r5r"rrr�_push_buffer}�zContext._push_buffercCr#)z7pop the most recent capturing buffer from this Context.)rr6r"rrr�_pop_buffer�s
zContext._pop_bufferNcCs|j�|tj�||��S)z+Return a value from this :class:`.Context`.)r	�getr,r-)rr/�defaultrrrr;�szContext.getcCs|jd�|�dS)zSWrite a string to this :class:`.Context` object's
        underlying output buffer.r'N�rr2)r�stringrrrr2�sz
Context.writecCs|jdjS)z#Return the current writer function.r'r=r"rrr�writer�r9zContext.writercCsJt�t�}|j|_|j��|_|j|_|j|_|j|_|j|_|j	|_	|Sr+)
r�__new__rr	r
rrr
rr)r�crrr�_copy�s
z
Context._copycCs |s|S|��}|j�|�|S)z�Create 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.


        )rBr	�update)r�drArrr�_locals�s
zContext._localscCs6|��}|j}|�dd�|�dd�|�dd�|S)zfcreate a new copy of this :class:`.Context`. with
        tokens related to inheritance state removed.rN�parent�next)rBr	r6)rrA�xrrr�_clean_inheritance_tokens�sz!Context._clean_inheritance_tokensr+)�__name__�
__module__�__qualname__�__doc__rr�propertyr!r$r&r(r*r0r5r7r8r:r;r2r?rBrErIrrrrrs,	

	
rc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)rcCs
d|_dSr+)�
nextcallerr"rrrr��
zCallerStack.__init__cC�|��Sr+��__bool__r"rrr�__nonzero__��zCallerStack.__nonzero__cCst|�r
|��r
dpdS)NTF)�len�_get_callerr"rrrrS�szCallerStack.__bool__cCs|dS�Nr'rr"rrrrW�szCallerStack._get_callercCst|��|�Sr+)�getattrrWr.rrr�__getattr__��zCallerStack.__getattr__cCs|jpd}|�|�d|_|Sr+)rOr%)r�framerrr�_push_frame�s

zCallerStack._push_framecCs|��|_dSr+)r6rOr"rrr�
_pop_frame�r[zCallerStack._pop_frameN)
rJrKrLrrTrSrWrZr]r^rrrrr�src@s(eZdZdZdd�Zdd�Zdd�ZdS)	�	Undefinedz�Represents an undefined value in a template.

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

    cCstd��)Nr_)�	NameErrorr"rrr�__str__�rUzUndefined.__str__cCrQr+rRr"rrrrT�rUzUndefined.__nonzero__cCsdS)NFrr"rrrrS�szUndefined.__bool__N)rJrKrLrMrarTrSrrrrr_�s
r_�c@sTeZdZdZdd�Zdd�Zdd�Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�	LoopStackz�a stack for LoopContexts that implements the context manager protocol
    to automatically pop off the top of the stack on context exit
    cCs
g|_dSr+��stackr"rrrr�rPzLoopStack.__init__cCs|�|�|jSr+)�_push�_top�r�iterablerrr�_enter�s
zLoopStack._entercCs|��|jSr+)�_poprgr"rrr�_exitszLoopStack._exitcCs|jr|jdS|SrXrdr"rrrrgs
zLoopStack._topcCr#r+)rer6r"rrrrkrPzLoopStack._popcCs&t|�}|jr
|jd|_|j�|�SrX)�LoopContextrerFr%)rri�newrrrrfszLoopStack._pushcCs
t�d��)NzNo loop context is established)r�RuntimeExceptionr.rrrrZrPzLoopStack.__getattr__cC�
t|j�Sr+)�iterrgr"rrr�__iter__rPzLoopStack.__iter__N)
rJrKrLrMrrjrlrNrgrkrfrZrrrrrrrc�s
rcc@sreZdZdZdd�Zdd�Zejdd��Ze	dd	��Z
e	d
d��Ze	dd
��Ze	dd��Z
e	dd��Zdd�ZdS)rma�A 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)�	_iterable�indexrFrhrrrr3s
zLoopContext.__init__ccs&�|jD]}|V|jd7_qdS�N�)rtru)r�irrrrr8s
�
�zLoopContext.__iter__cCrpr+)rVrtr"rrr�__len__=�
zLoopContext.__len__cCst|�|jdSrv)rVrur"rrr�
reverse_indexA�zLoopContext.reverse_indexcCs
|jdkSrs)rur"rrr�firstErzzLoopContext.firstcCs|jt|�dkSrv)rurVr"rrr�lastIr|zLoopContext.lastcCs|jSr+)�oddr"rrr�evenMszLoopContext.evencCst|jd�S)N�)�boolrur"rrrrQszLoopContext.oddcGs|std��||jt|�S)z,Cycle through values as the loop progresses.z(You must provide values to cycle through)�
ValueErrorrurV)r�valuesrrr�cycleUszLoopContext.cycleN)rJrKrLrMrrrr�memoized_instancemethodryrNr{r}r~r�rr�rrrrrms"





rmc@seZdZdd�Zdd�ZdS)�_NSAttrcCs
||_dSr+)�_NSAttr__parent)rrFrrrr]rPz_NSAttr.__init__cCs4|j}|rt|j|�rt|j|�S|j}|st|��r+)r��hasattr�modulerY�inherits�AttributeError)rr/�nsrrrrZ`s�z_NSAttr.__getattr__N)rJrKrLrrZrrrrr�\sr�c@s�eZdZdZ				ddd�ZdZdZ	dZ	dZ	dZ		dZ
	dZej
dd��Zd	d
�Zdd�Zd
d�Zedd��Zdd�Zdd�Zdd�Zdd�ZdS)�	Namespacea�Provides 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||_||_||_|durdd�|D�|_dSdS)NcS�i|]}|j|�qSr�rJ��.0rArrr�
<dictcomp>��z&Namespace.__init__.<locals>.<dictcomp>)�name�contextr��	callables)rr�r�r�r��
populate_self�calling_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`

        )r�r"rrr�attr�szNamespace.attrcCsH||f}||jjvr|jj|St||j��||jd�}||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�)r�r�TemplateNamespacerB�_templateuri)r�urir/r�rrr�
get_namespace�s�zNamespace.get_namespacecCst|j||j�S)z�Return a :class:`.Template` from the given ``uri``.

        The ``uri`` resolution is relative to the ``uri`` of this
        :class:`.Namespace` object's :class:`.Template`.

        )�_lookup_templater�r�)rr�rrr�get_template�szNamespace.get_templatecKs|jj|fi|��S)a�Return 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>``.

        )�cacher;)rr/r$rrr�
get_cached�szNamespace.get_cachedcCr )zReturn the :class:`.Cache` object referenced
        by this :class:`.Namespace` object's
        :class:`.Template`.

        )�templater�r"rrrr�szNamespace.cachecKst|j||jfi|��dS)z$Include a file at the given ``uri``.N)�
_include_filer�r�)rr�r$rrr�include_file
szNamespace.include_filecCs@|D]}|dkr|��D]\}}|||<qqt||�||<qdS)N�*)�	_get_starrY)rrD�l�ident�k�vrrr�	_populates
��zNamespace._populateccs,�|jr|jD]}||j|fVqdSdSr+)r�r.rrrr�s�
�zNamespace._get_starcCsL||jvr|j|}n|jrt|j|�}n	td|j|f��t|||�|S�Nz!Namespace '%s' has no member '%s')r�r�rYr�r��setattr)rr/�valrrrrZs
�zNamespace.__getattr__�NNTN)rJrKrLrMrr�r�r�r��filenamer�r�r�memoized_propertyr�r�r�r�rNr�r�r�r�rZrrrrr�js<
�


 	
r�c@sZeZdZdZ						ddd�Zedd��Zedd	��Zed
d��Zdd
�Z	dd�Z
dS)r�z@A :class:`.Namespace` specific to a :class:`.Template` instance.NTc	Cs�||_||_||_|durdd�|D�|_|dur't|||�|_|jjj|_n|dur4||_|jj|_nt	d��|rFt
||j|d�\}	}
dSdS)NcSr�rr�r�rrrr�?r�z.TemplateNamespace.__init__.<locals>.<dictcomp>z 'template' argument is required.)�self_ns)r�r�r�r�r�r�r��
_template_urir��	TypeError�_populate_self_namespace)rr�r�r�r�r�r�r�r��lclcallable�
lclcontextrrrr0s"��zTemplateNamespace.__init__cCr )z�The 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.

        )r�r�r"rrrr�O�	zTemplateNamespace.modulecCr �zhThe path of the filesystem file used for this
        :class:`.Namespace`'s module or template.
        )r�r�r"rrrr�Z�zTemplateNamespace.filenamecCr )z�The 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`.

        )r�r�r"rrrr�ar�zTemplateNamespace.uric#sR��jr�jD]
}|�j|fVq�fdd�}�jjjD]	}|||�fVqdS)Ncs�j�|�}t�|�j�Sr+)r��_get_def_callablerrr�)r/�	callable_r"rrr;qsz(TemplateNamespace._get_star.<locals>.get)r�r�r��_exports)rr/r;r�rr"rr�ls�
�zTemplateNamespace._get_starcCst||jvr|j|}n'|j�|�r|j�|�}t�||j�}n|jr)t|j|�}n	t	d|j
|f��t|||�|Sr�)r�r��has_defr�rrr�r�rYr�r�r��rr/r�r�rrrrZxs
�zTemplateNamespace.__getattr__)NNNNTN)rJrKrLrMrrNr�r�r�r�rZrrrrr�,s"
�




r�c@s>eZdZdZ				ddd�Zedd��Zdd	�Zd
d�ZdS)
�ModuleNamespacez;A :class:`.Namespace` specific to a Python module instance.NTc
Cs^||_||_||_|durdd�|D�|_t|�}|�d�dd�D]}	t||	�}q"||_dS)NcSr�rr�r�rrrr��r�z,ModuleNamespace.__init__.<locals>.<dictcomp>�.rw)r�r�r�r��
__import__�splitrYr�)
rr�r�r�r�r�r�r��mod�tokenrrrr�s

zModuleNamespace.__init__cCr r�)r��__file__r"rrrr��r�zModuleNamespace.filenameccsl�|jr|jD]
}||j|fVqt|j�D]}|ddkr3t|j|�}t|�r3|t�||j�fVqdS)Nr�_)r��dirr�rY�callablerrr�)rr/r�rrrr��s�
��zModuleNamespace._get_starcCst||jvr|j|}n't|j|�rt|j|�}t�||j�}n|jr)t|j|�}n	td|j	|f��t
|||�|Sr�)r�r�r�rYrrr�r�r�r�r�r�rrrrZ�s
�zModuleNamespace.__getattr__r�)	rJrKrLrMrrNr�r�rZrrrrr��s
�

r�c��fdd�}|S)z�Apply a caller_stack compatibility decorator to a plain
    Python function.

    See the example in :ref:`namespaces_python_modules`.

    cs:|j��z�|g|�Ri|��W|j��S|j��wr+)rr]r^)r��argsr$��funcrr�wrap_stackframe�s
z(supports_caller.<locals>.wrap_stackframer)r�r�rr�r�supports_caller�sr�cOsFt|�s	t�d��|��z||i|��W|��}|��S|��}w)z�Execute 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)))r�rror8r:�getvalue)r�r�r�r$r4rrrr�s�
�rcr�)Ncs��fdd�}|S)NcsP��fdd�}z
�jdd�|_Wn	tyYnw�|��g|�Ri|��S)Nc���g|�Ri|��Sr+r�r��kw)r��	render_fnrr�y��zB_decorate_toplevel.<locals>.decorate_render.<locals>.go.<locals>.y�)rJr�)r�r�r�r�)�fnr�)r�r�go�s�z7_decorate_toplevel.<locals>.decorate_render.<locals>.gor�r�r��r�)r�r�decorate_render�sz+_decorate_toplevel.<locals>.decorate_renderr)r�r�rr�r�_decorate_toplevel�sr�cs��fdd�}|S)Ncs�|����fdd�}|S)Ncr�r+rr�)r��decrrr�r�z5_decorate_inline.<locals>.decorate_render.<locals>.gorr��r�r�)r�rr��sz)_decorate_inline.<locals>.decorate_renderr)r�r�r�rr�r�_decorate_inline�sr�cKs�t|||�}t|��|�\}}t||jfi|��}|jr=z||fi|��WdSty<|�|t���}|s9�YdSw||fi|��dS)zPlocate the template from the given uri and include it in
    the current output.N)	r�r�rI�_kwargs_for_includer	�include_error_handler�	Exceptionr�exception_as)r�r�r�r$r�r��ctx�resultrrrr�s���r�c
Cs�|durdSt|||�}|d}|}|jdur|j}|jdus|�d|i�}td|j||dd�|_|j|jd<|jd<t|jd	d�}|durQ|||�}|rQ|St|jd
d�}	|	dur`|	|�|j|fS)z�called by the _inherit method in template modules to set
    up the inheritance chain at the start of a template's
    execution.NrrG�self:%sF�r�r�rF�local�
_mako_inherit�_mako_generate_namespaces)	r�r�rEr�r�r	rYr�r�)
r�r�r�r�r��ihr�r��ret�gen_nsrrr�
_inherit_froms2

��

r�c
Csj|jj}|durt�d|jj��|�||�}z|�|�WStjy4}z
t�tt	�
���|�d}~ww)Nz.Template '%s' has no TemplateLookup associated)rr!r�TemplateLookupExceptionr��
adjust_urir��TopLevelLookupException�strrr�)r�r��
relativetor!�errrr�<s$��
����r�cCs^|durtd|j||dd�}||jd<|jd<t|jd�r*|j�||�}|r*|S|j|fS)Nr�Fr�rr�r�)r�r�r	r�r�r�r�)r�r�r�r�rrrr�Ls�
r�FcCsl|rt��}n	tj|j|jd�}t|fi|��}||_|�|�t|||g|�Rit||���|�	��
�S)z^create a Context and return the string
    output of the given template and template callable.)�encoding�errors)rr1�output_encoding�encoding_errorsrr
r�_render_context�_kwargs_for_callabler:r�)r�r�r�r�
as_unicoder4r�rrr�_render\s$
�
���r�cCsjt�|�}|dr|S|ddd�|dd�D�}i}|D]}|dkr2||vr2||vr2||||<q|S)Nr�rcS�g|]}|dur|�qSr+r�r�r�rrr�
<listcomp>{�z(_kwargs_for_callable.<locals>.<listcomp>rw�r��r�inspect_getargspec)r�r�argspec�	namedargsr$�argrrrr�ts
�r�cKsZt�|�}|ddd�|dd�D�}|D]}|dkr*||vr*||vr*||||<q|S)NrcSrr+rrrrrr�rz'_kwargs_for_include.<locals>.<listcomp>rwrr�r)r�rr$rrr	rrrr��s
�r�cOs^ddlm}t||j�st||�\}}t||||d�dSt||j�\}}t||||d�dS)Nr)r�r$)�
mako.templater��
isinstance�DefTemplater��_exec_templaterF)�tmplr�r�r�r$r��inheritr�rrrr��sr�cCs�|j}|dur?|js
|jr?z||g|�Ri|��WdSty-t||t���YdSt��d}t|||�YdS||g|�Ri|��dS)z�execute 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�format_exceptions�
error_handlerr��
_render_errorrr��sys�exc_info)r�r�r�r$r�r�rrrr
�s��r
cCs�|jr|�||�}|st��\}}}|r|r|�|��|�dSt��}|jr1t��g|j	dd�<nt�|j
|j�g|j	dd�<|�|�|j
||d�dS)N)�error)rrr�with_tracebackr�html_error_templater
rr1rr�r�r�render_context)r�r�rr��tp�value�tb�error_templaterrrr�s$
���
rr+)F)NN)"rMr,rr�makorrrrr)rr_�	UNDEFINED�STOP_RENDERINGrcrmr�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r
rrrrr�<module>sD-(AC]: