o
    ‹ågœl  ã                   @   sH  d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ G dd„ dƒZG dd	„ d	e	ƒZ
G d
d„ dƒZeƒ ZdZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ dƒZG dd„ deƒZG dd„ deƒZdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd6d'd(„Zd7d*d+„Zd,d-„ Zd.d/„ Zd0d1„ Zd8d2d3„Z d4d5„ Z!dS )9zdprovides runtime services for templates, including Context,
Namespace, and various helper functions.é    N)Úcompat)Ú
exceptions)Úutilc                   @   sª   e Zd ZdZdd„ Zdd„ Zedd„ ƒZedd	„ ƒZd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd'dd„Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ ZdS )(ÚContextz­Provides runtime namespace, output buffer, and various
    callstacks for templates.

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

    c                 K   sR   |g| _ || _| ¡ | _d | _d | _i | _t t	| ¡| jd< t
ƒ  | _| jd< d S )NÚcaptureÚcaller)Ú_buffer_stackÚ_dataÚcopyÚ_kwargsÚ_with_templateÚ_outputting_as_unicodeÚ
namespacesÚ	functoolsÚpartialr   ÚCallerStackÚcaller_stack)ÚselfÚbufferÚdata© r   úH/var/www/html/flaskapp/venv/lib/python3.10/site-packages/mako/runtime.pyÚ__init__   s   
zContext.__init__c                 C   s0   || _ |j | j¡}|rt dd |¡ ¡‚d S )Nz%Reserved words passed to render(): %sz, )r   Úreserved_namesÚintersectionr	   r   ÚNameConflictErrorÚjoin)r   ÚtÚillegal_namesr   r   r   Ú_set_with_template.   s   ÿÿÿzContext._set_with_templatec                 C   ó   | j jS )z]Return the :class:`.TemplateLookup` associated
        with this :class:`.Context`.

        )r   Úlookup©r   r   r   r   r!   7   s   zContext.lookupc                 C   ó
   | 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)}

        )r   r
   r"   r   r   r   Úkwargs?   s   
zContext.kwargsc                 C   s   | j  |¡ dS )zQPush a ``caller`` callable onto the callstack for
        this :class:`.Context`.N)r   Úappend)r   r   r   r   r   Úpush_callerU   s   zContext.push_callerc                 C   s   | j d= dS )zPPop a ``caller`` callable onto the callstack for this
        :class:`.Context`.éÿÿÿÿN)r   r"   r   r   r   Ú
pop_caller[   s   zContext.pop_callerc                 C   s   t | j ¡ ƒS )zAReturn a list of all names established in this :class:`.Context`.)Úlistr	   Úkeysr"   r   r   r   r*   a   s   zContext.keysc                 C   s   || j v r
| j | S tj| S ©N)r	   ÚbuiltinsÚ__dict__©r   Úkeyr   r   r   Ú__getitem__f   s   


zContext.__getitem__c                 C   s   t  ¡ }| j |¡ |jS )zUpush a capturing buffer onto this Context and return
        the new writer function.)r   ÚFastEncodingBufferr   r%   Úwrite©r   Úbufr   r   r   Ú_push_writerl   s   zContext._push_writerc                 C   s   | j  ¡ }|| j d jfS )zupop the most recent capturing buffer from this Context
        and return the current writer after the pop.

        r'   )r   Úpopr2   r3   r   r   r   Ú_pop_buffer_and_writert   s   
zContext._pop_buffer_and_writerc                 C   s   |   ¡  dS )z*push a capturing buffer onto this Context.N)r5   r"   r   r   r   Ú_push_buffer}   ó   zContext._push_bufferc                 C   r#   )z7pop the most recent capturing buffer from this Context.)r   r6   r"   r   r   r   Ú_pop_buffer‚   s   
zContext._pop_bufferNc                 C   s   | j  |tj ||¡¡S )z+Return a value from this :class:`.Context`.)r	   Úgetr,   r-   )r   r/   Údefaultr   r   r   r;   ‡   s   zContext.getc                 C   s   | j d  |¡ dS )zSWrite a string to this :class:`.Context` object's
        underlying output buffer.r'   N©r   r2   )r   Ústringr   r   r   r2   Œ   s   zContext.writec                 C   s   | j d jS )z#Return the current writer function.r'   r=   r"   r   r   r   Úwriter’   r9   zContext.writerc                 C   sJ   t  t ¡}| j|_| j ¡ |_| j|_| j|_| j|_| j|_| j	|_	|S r+   )
r   Ú__new__r   r	   r
   r   r   r   r   r   )r   Úcr   r   r   Ú_copy—   s   
zContext._copyc                 C   s    |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.


        )rB   r	   Úupdate)r   ÚdrA   r   r   r   Ú_locals¢   s
   zContext._localsc                 C   s6   |   ¡ }|j}| dd¡ | dd¡ | dd¡ |S )zfcreate a new copy of this :class:`.Context`. with
        tokens related to inheritance state removed.r   NÚparentÚnext)rB   r	   r6   )r   rA   Úxr   r   r   Ú_clean_inheritance_tokens³   s   z!Context._clean_inheritance_tokensr+   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úpropertyr!   r$   r&   r(   r*   r0   r5   r7   r8   r:   r;   r2   r?   rB   rE   rI   r   r   r   r   r      s,    	

	
r   c                   @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )r   c                 C   s
   d | _ d S r+   )Ú
nextcallerr"   r   r   r   r   À   ó   
zCallerStack.__init__c                 C   ó   |   ¡ S r+   ©Ú__bool__r"   r   r   r   Ú__nonzero__Ã   ó   zCallerStack.__nonzero__c                 C   s   t | ƒr
|  ¡ r
dpdS )NTF)ÚlenÚ_get_callerr"   r   r   r   rS   Æ   s   zCallerStack.__bool__c                 C   s   | d S ©Nr'   r   r"   r   r   r   rW   É   s   zCallerStack._get_callerc                 C   s   t |  ¡ |ƒS r+   )ÚgetattrrW   r.   r   r   r   Ú__getattr__Î   ó   zCallerStack.__getattr__c                 C   s   | j pd }|  |¡ d | _ |S r+   )rO   r%   )r   Úframer   r   r   Ú_push_frameÑ   s   

zCallerStack._push_framec                 C   s   |   ¡ | _d S r+   )r6   rO   r"   r   r   r   Ú
_pop_frame×   r[   zCallerStack._pop_frameN)
rJ   rK   rL   r   rT   rS   rW   rZ   r]   r^   r   r   r   r   r   ¿   s    r   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú	Undefinedz¥Represents an undefined value in a template.

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

    c                 C   s   t dƒ‚)Nr_   )Ú	NameErrorr"   r   r   r   Ú__str__å   rU   zUndefined.__str__c                 C   rQ   r+   rR   r"   r   r   r   rT   è   rU   zUndefined.__nonzero__c                 C   s   dS )NFr   r"   r   r   r   rS   ë   s   zUndefined.__bool__N)rJ   rK   rL   rM   ra   rT   rS   r   r   r   r   r_   Û   s
    r_   Ú c                   @   sT   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZd
d„ Z	dd„ Z
dd„ Zdd„ ZdS )Ú	LoopStackzŒa stack for LoopContexts that implements the context manager protocol
    to automatically pop off the top of the stack on context exit
    c                 C   s
   g | _ d S r+   ©Ústackr"   r   r   r   r   ù   rP   zLoopStack.__init__c                 C   s   |   |¡ | jS r+   )Ú_pushÚ_top©r   Úiterabler   r   r   Ú_enterü   s   
zLoopStack._enterc                 C   s   |   ¡  | jS r+   )Ú_poprg   r"   r   r   r   Ú_exit   s   zLoopStack._exitc                 C   s   | j r| j d S | S rX   rd   r"   r   r   r   rg     s   
zLoopStack._topc                 C   r#   r+   )re   r6   r"   r   r   r   rk     rP   zLoopStack._popc                 C   s&   t |ƒ}| jr| jd |_| j |¡S rX   )ÚLoopContextre   rF   r%   )r   ri   Únewr   r   r   rf     s   zLoopStack._pushc                 C   s
   t  d¡‚)NzNo loop context is established)r   ÚRuntimeExceptionr.   r   r   r   rZ     rP   zLoopStack.__getattr__c                 C   ó
   t | jƒS r+   )Úiterrg   r"   r   r   r   Ú__iter__  rP   zLoopStack.__iter__N)rJ   rK   rL   rM   r   rj   rl   rN   rg   rk   rf   rZ   rr   r   r   r   r   rc   ó   s    
rc   c                   @   sr   e Zd ZdZdd„ Zdd„ Zejdd„ ƒZe	dd	„ ƒZ
e	d
d„ ƒZe	dd„ ƒZe	dd„ ƒZe	dd„ ƒZdd„ ZdS )rm   a¶  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.
    c                 C   s   || _ d| _d | _d S ©Nr   )Ú	_iterableÚindexrF   rh   r   r   r   r   3  s   
zLoopContext.__init__c                 c   s&   � | j D ]}|V  |  jd7  _qd S ©Né   )rt   ru   )r   Úir   r   r   rr   8  s
   €
þzLoopContext.__iter__c                 C   rp   r+   )rV   rt   r"   r   r   r   Ú__len__=  ó   
zLoopContext.__len__c                 C   s   t | ƒ| j d S rv   )rV   ru   r"   r   r   r   Úreverse_indexA  ó   zLoopContext.reverse_indexc                 C   s
   | j dkS rs   )ru   r"   r   r   r   ÚfirstE  rz   zLoopContext.firstc                 C   s   | j t| ƒd kS rv   )ru   rV   r"   r   r   r   ÚlastI  r|   zLoopContext.lastc                 C   s   | j  S r+   )Úoddr"   r   r   r   ÚevenM  s   zLoopContext.evenc                 C   s   t | jd ƒS )Né   )Úboolru   r"   r   r   r   r   Q  s   zLoopContext.oddc                 G   s   |st dƒ‚|| jt|ƒ  S )z,Cycle through values as the loop progresses.z(You must provide values to cycle through)Ú
ValueErrorru   rV   )r   Úvaluesr   r   r   ÚcycleU  s   zLoopContext.cycleN)rJ   rK   rL   rM   r   rr   r   Úmemoized_instancemethodry   rN   r{   r}   r~   r€   r   r…   r   r   r   r   rm     s"    





rm   c                   @   s   e Zd Zdd„ Zdd„ ZdS )Ú_NSAttrc                 C   s
   || _ d S r+   )Ú_NSAttr__parent)r   rF   r   r   r   r   ]  rP   z_NSAttr.__init__c                 C   s4   | j }|rt|j|ƒrt|j|ƒS |j}|st|ƒ‚r+   )rˆ   ÚhasattrÚmodulerY   ÚinheritsÚAttributeError)r   r/   Únsr   r   r   rZ   `  s   üz_NSAttr.__getattr__N)rJ   rK   rL   r   rZ   r   r   r   r   r‡   \  s    r‡   c                   @   sš   e Zd ZdZ				ddd„ZdZdZ	 dZ	 dZ	 dZ		 dZ
	 dZejdd„ ƒZd	d
„ Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú	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.

    NTc                 C   s2   || _ || _|| _|d urdd„ |D ƒ| _d S d S )Nc                 S   ó   i | ]}|j |“qS r   ©rJ   ©Ú.0rA   r   r   r   Ú
<dictcomp>ˆ  ó    z&Namespace.__init__.<locals>.<dictcomp>)ÚnameÚcontextr‹   Ú	callables)r   r•   r–   r—   r‹   Úpopulate_selfÚcalling_urir   r   r   r   {  s   	ÿzNamespace.__init__r   c                 C   s   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`

        )r‡   r"   r   r   r   Úattr¼  s   zNamespace.attrc                 C   sH   | |f}|| j jv r| j j| S t|| j  ¡ || jd�}|| j j|< |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�   r   r   r   Úget_namespaceÍ  s   üzNamespace.get_namespacec                 C   s   t | 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�   )r   rž   r   r   r   Úget_templateí  s   zNamespace.get_templatec                 K   s   | j j|fi |¤Ž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;   )r   r/   r$   r   r   r   Ú
get_cachedö  s   zNamespace.get_cachedc                 C   r    )zReturn the :class:`.Cache` object referenced
        by this :class:`.Namespace` object's
        :class:`.Template`.

        )Útemplater¢   r"   r   r   r   r¢     s   zNamespace.cachec                 K   s   t | j|| jfi |¤Ž dS )z$Include a file at the given ``uri``.N)Ú_include_filer–   r�   )r   rž   r$   r   r   r   Úinclude_file  s   zNamespace.include_filec                 C   s@   |D ]}|dkr|   ¡ D ]\}}|||< qqt| |ƒ||< qd S )NÚ*)Ú	_get_starrY   )r   rD   ÚlÚidentÚkÚvr   r   r   Ú	_populate  s   
ÿûzNamespace._populatec                 c   s,   � | j r| j D ]}|| j | fV  qd S d S r+   )r—   r.   r   r   r   r¨     s   €
þzNamespace._get_starc                 C   sL   || j v r| j | }n| jrt| j|ƒ}n	td| j|f ƒ‚t| ||ƒ |S ©Nz!Namespace '%s' has no member '%s')r—   r‹   rY   rŒ   r•   Úsetattr)r   r/   Úvalr   r   r   rZ     s   
ÿzNamespace.__getattr__©NNTN)rJ   rK   rL   rM   r   r—   rŠ   r¤   r–   Úfilenamerž   r�   r   Úmemoized_propertyrš   rŸ   r¡   r£   rN   r¢   r¦   r­   r¨   rZ   r   r   r   r   rŽ   j  s<    
ù


 	
rŽ   c                   @   sZ   e Zd ZdZ						ddd„Zedd„ ƒZedd	„ ƒZed
d„ ƒZdd„ Z	dd„ Z
dS )rœ   z@A :class:`.Namespace` specific to a :class:`.Template` instance.NTc	                 C   s�   || _ || _|| _|d urdd„ |D ƒ| _|d ur't|||ƒ| _| jjj| _n|d ur4|| _|jj| _nt	dƒ‚|rFt
|| j| d�\}	}
d S d S )Nc                 S   r�   r   r�   r‘   r   r   r   r“   ?  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)r   r•   r–   r¤   r›   r—   r‹   r˜   r™   ÚlclcallableÚ
lclcontextr   r   r   r   0  s"   ÿÿzTemplateNamespace.__init__c                 C   r    )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"   r   r   r   rŠ   O  ó   	zTemplateNamespace.modulec                 C   r    ©zhThe path of the filesystem file used for this
        :class:`.Namespace`'s module or template.
        )r¤   r²   r"   r   r   r   r²   Z  ó   zTemplateNamespace.filenamec                 C   r    )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"   r   r   r   rž   a  rº   zTemplateNamespace.uric                 #   sR   � ˆ j rˆ j D ]
}|ˆ j | fV  q‡ fdd„}ˆ jjjD ]	}|||ƒfV  qd S )Nc                    s   ˆ j  | ¡}t |ˆ j¡S r+   )r¤   Ú_get_def_callabler   r   r–   )r/   Ú	callable_r"   r   r   r;   q  s   z(TemplateNamespace._get_star.<locals>.get)r—   r¤   rŠ   Ú_exports)r   r/   r;   r«   r   r"   r   r¨   l  s   €
ÿzTemplateNamespace._get_starc                 C   st   || j v r| j | }n'| j |¡r| j |¡}t || j¡}n| jr)t| j|ƒ}n	t	d| j
|f ƒ‚t| ||ƒ |S r®   )r—   r¤   Úhas_defr½   r   r   r–   r‹   rY   rŒ   r•   r¯   ©r   r/   r°   r¾   r   r   r   rZ   x  s   
ÿzTemplateNamespace.__getattr__)NNNNTN)rJ   rK   rL   rM   r   rN   rŠ   r²   rž   r¨   rZ   r   r   r   r   rœ   ,  s"    
÷




rœ   c                   @   s>   e Zd ZdZ				ddd„Zedd„ ƒZdd	„ Zd
d„ ZdS )ÚModuleNamespacez;A :class:`.Namespace` specific to a Python module instance.NTc           
      C   s^   || _ || _|| _|d urdd„ |D ƒ| _t|ƒ}| d¡dd … D ]}	t||	ƒ}q"|| _d S )Nc                 S   r�   r   r�   r‘   r   r   r   r“   ›  r”   z,ModuleNamespace.__init__.<locals>.<dictcomp>Ú.rw   )r•   r–   r‹   r—   Ú
__import__ÚsplitrY   rŠ   )
r   r•   r–   rŠ   r—   r‹   r˜   r™   ÚmodÚtokenr   r   r   r   �  s   

zModuleNamespace.__init__c                 C   r    r»   )rŠ   Ú__file__r"   r   r   r   r²   ¢  r¼   zModuleNamespace.filenamec                 c   sl   � | j r| j D ]
}|| j | fV  qt| jƒD ]}|d dkr3t| j|ƒ}t|ƒr3|t || j¡fV  qd S )Nr   Ú_)r—   ÚdirrŠ   rY   Úcallabler   r   r–   )r   r/   r¾   r   r   r   r¨   ©  s   €
€üzModuleNamespace._get_starc                 C   st   || j v r| j | }n't| j|ƒrt| j|ƒ}t || j¡}n| jr)t| j|ƒ}n	td| j	|f ƒ‚t
| ||ƒ |S r®   )r—   r‰   rŠ   rY   r   r   r–   r‹   rŒ   r•   r¯   rÁ   r   r   r   rZ   ³  s   
ÿzModuleNamespace.__getattr__r±   )	rJ   rK   rL   rM   r   rN   r²   r¨   rZ   r   r   r   r   rÂ   ‰  s    
ø

rÂ   c                    ó   ‡ fdd„}|S )zŒApply a caller_stack compatibility decorator to a plain
    Python function.

    See the example in :ref:`namespaces_python_modules`.

    c                    s:   | j  ¡  zˆ | g|¢R i |¤ŽW | j  ¡  S | j  ¡  w r+   )r   r]   r^   )r–   Úargsr$   ©Úfuncr   r   Úwrap_stackframeË  s   
z(supports_caller.<locals>.wrap_stackframer   )rÏ   rÐ   r   rÎ   r   Úsupports_callerÃ  s   rÑ   c                 O   sF   t |ƒ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Ë   r   ro   r8   r:   Úgetvalue)r–   r¾   rÍ   r$   r4   r   r   r   r   Õ  s   ÿ
ÿr   c                    rÌ   )Nc                    s   ‡‡ fdd„}|S )Nc                    sP   ‡ ‡fdd„}z
ˆj dd … |_ W n	 ty   Y nw ˆ|ƒˆ g|¢R i |¤ŽS )Nc                     ó   ˆˆ g| ¢R i |¤ŽS r+   r   ©rÍ   Úkw)r–   Ú	render_fnr   r   Úyí  ó   zB_decorate_toplevel.<locals>.decorate_render.<locals>.go.<locals>.yé   )rJ   r¶   )r–   rÍ   rÕ   r×   )ÚfnrÖ   )r–   r   Úgoì  s   þz7_decorate_toplevel.<locals>.decorate_render.<locals>.gor   ©rÖ   rÛ   ©rÚ   )rÖ   r   Údecorate_renderë  s   z+_decorate_toplevel.<locals>.decorate_renderr   )rÚ   rÞ   r   rÝ   r   Ú_decorate_toplevelê  s   rß   c                    s   ‡ ‡fdd„}|S )Nc                    s   ˆ| ƒ‰ ‡‡ fdd„}|S )Nc                     rÓ   r+   r   rÔ   )r–   Údecr   r   rÛ      rØ   z5_decorate_inline.<locals>.decorate_render.<locals>.gor   rÜ   ©r–   rÚ   )rà   r   rÞ   ý  s   z)_decorate_inline.<locals>.decorate_renderr   )r–   rÚ   rÞ   r   rá   r   Ú_decorate_inlineü  s   râ   c                 K   sŽ   t | ||ƒ}t|  ¡ |ƒ\}}t|| jfi |¤Ž}|jr=z||fi |¤Ž W dS  ty<   | |t ¡ ¡}|s9‚ Y dS w ||fi |¤Ž dS )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Úresultr   r   r   r¥     s   ÿÿþr¥   c           
      C   sÊ   |du rdS t | ||ƒ}| d }|}|jdur|j}|jdus|  d|i¡}td|j ||dd�|_|j | jd< |jd< t|jd	dƒ}|durQ|||ƒ}|rQ|S t|jd
dƒ}	|	dur`|	| ƒ |j|fS )z�called by the _inherit method in template modules to set
    up the inheritance chain at the start of a template's
    execution.Nr   rG   úself:%sF©r¤   r˜   rF   ÚlocalÚ_mako_inheritÚ_mako_generate_namespaces)	r    r‹   rE   rœ   rž   r	   rY   rŠ   r¾   )
r–   rž   r™   r¤   r´   Úihr¹   r¾   ÚretÚgen_nsr   r   r   Ú_inherit_from  s2   

ÿü

rñ   c              
   C   sj   | j j}|d u rt d| j j ¡‚| ||¡}z| |¡W S  tjy4 } z
t tt	 
¡ ƒ¡|‚d }~ww )Nz.Template '%s' has no TemplateLookup associated)r   r!   r   ÚTemplateLookupExceptionrž   Ú
adjust_urir¡   ÚTopLevelLookupExceptionÚstrr   ræ   )r–   rž   Ú
relativetor!   Úer   r   r   r    <  s$   ÿÿ
ÿþ€ÿr    c                 C   s^   |d u rt d|j | |dd�}| | jd< | jd< t|jdƒr*|j || ¡}|r*|S |j| fS )Nré   Frê   r   rë   rì   )rœ   rž   r	   r‰   rŠ   rì   r¾   )r–   r¤   r´   rï   r   r   r   r·   L  s   ü
r·   Fc                 C   sl   |rt  ¡ }n	t j| j| jd�}t|fi |¤Ž}||_| | ¡ t| ||g|¢R i t||ƒ¤Ž | 	¡  
¡ S )z^create a Context and return the string
    output of the given template and template callable.)ÚencodingÚerrors)r   r1   Úoutput_encodingÚencoding_errorsr   r   r   Ú_render_contextÚ_kwargs_for_callabler:   rÒ   )r¤   r¾   rÍ   r   Ú
as_unicoder4   r–   r   r   r   Ú_render\  s$   
ÿ
ýüûrÿ   c                 C   sj   t  | ¡}|d r|S |d dd„ |dd… D ƒ }i }|D ]}|dkr2||v r2||vr2|| ||< q|S )Nr�   r   c                 S   ó   g | ]}|d ur|‘qS r+   r   ©r’   r¬   r   r   r   Ú
<listcomp>{  ó    z(_kwargs_for_callable.<locals>.<listcomp>rw   é   r–   ©r   Úinspect_getargspec)r¾   r   ÚargspecÚ	namedargsr$   Úargr   r   r   rý   t  s   
€rý   c                 K   sZ   t  | ¡}|d dd„ |dd… D ƒ }|D ]}|dkr*||v r*||vr*|| ||< q|S )Nr   c                 S   r   r+   r   r  r   r   r   r  …  r  z'_kwargs_for_include.<locals>.<listcomp>rw   r  r–   r  )r¾   r   r$   r  r  r	  r   r   r   rã   ƒ  s   
€rã   c                 O   s^   dd l m} t| |jƒst|| ƒ\}}t||||d� d S t|| jƒ\}}t||||d� d S )Nr   )rÍ   r$   )Úmako.templater¤   Ú
isinstanceÚDefTemplater·   Ú_exec_templaterF   )Útmplr¾   r–   rÍ   r$   r¤   Úinheritr¹   r   r   r   rü   Œ  s   rü   c                 C   s˜   |j }|dur?|js|jr?z| |g|¢R i |¤Ž W dS  ty-   t||t ¡ ƒ Y dS    t ¡ d }t|||ƒ Y dS | |g|¢R i |¤Ž dS )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_errorr   ræ   ÚsysÚexc_info)r¾   r–   rÍ   r$   r¤   r÷   r   r   r   r  ›  s   ÿÿr  c                 C   sš   | j r|   ||¡}|st ¡ \}}}|r|r| |¡‚|‚d S t ¡ }|jr1t ¡ g|j	d d …< nt |j
|j¡g|j	d d …< | |¡ |j||d� d S )N)Úerror)r  r  r  Úwith_tracebackr   Úhtml_error_templater   r   r1   r   rú   rû   r   Úrender_context)r¤   r–   r  rè   ÚtpÚvalueÚtbÚerror_templater   r   r   r  ²  s$   
ûþÿ
r  r+   )F)NN)"rM   r,   r   r  Úmakor   r   r   r   r)   r   r_   Ú	UNDEFINEDÚSTOP_RENDERINGrc   rm   r‡   rŽ   rœ   rÂ   rÑ   r   rß   râ   r¥   rñ   r    r·   rÿ   rý   rã   rü   r  r  r   r   r   r   Ú<module>   sD    -(A C]: 

	
