
    +hl                     j   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      Z G d d	e	      Z
 G d
 d      Z e       ZdZ G d d      Z G d d      Z G d d      Z G d d      Z G d de      Z G d de      Zd Zd Zd Zd Zd Zd Zd Zd'd Zd(d!Zd" Zd# Zd$ Zd)d%Z d& Z!y)*zdprovides runtime services for templates, including Context,
Namespace, and various helper functions.    N)compat)
exceptions)utilc                       e Zd ZdZd Zd Zed        Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd ZddZd Zd Zd Zd Zd Zy)ContextzProvides runtime namespace, output buffer, and various
    callstacks for templates.

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

    c                     |g| _         || _        |j                         | _        d | _        d | _        i | _        t        j                  t        |       | j                  d<   t               x| _        | j                  d<   y )Ncapturecaller)_buffer_stack_datacopy_kwargs_with_template_outputting_as_unicode
namespaces	functoolspartialr	   CallerStackcaller_stack)selfbufferdatas      ?/var/www/html/venv/lib/python3.12/site-packages/mako/runtime.py__init__zContext.__init__   sn    $X
yy{"&*# !* 1 1'4 @

9 4?=@DJJx0    c                     || _         |j                  j                  | j                        }|r't	        j
                  ddj                  |      z        y )Nz%Reserved words passed to render(): %sz, )r   reserved_namesintersectionr   r   NameConflictErrorjoin)r   tillegal_namess      r   _set_with_templatezContext._set_with_template.   sS    ((55djjA..7))M*+  r   c                 .    | j                   j                  S )z]Return the :class:`.TemplateLookup` associated
        with this :class:`.Context`.

        )r   lookupr   s    r   r%   zContext.lookup7   s     "")))r   c                 6    | j                   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&   s    r   kwargszContext.kwargs?   s    ( ||  ""r   c                 :    | j                   j                  |       y)zQPush a ``caller`` callable onto the callstack for
        this :class:`.Context`.N)r   append)r   r
   s     r   push_callerzContext.push_callerU   s     	  (r   c                     | j                   d= y)zPPop a ``caller`` callable onto the callstack for this
        :class:`.Context`.N)r   r&   s    r   
pop_callerzContext.pop_caller[   s     b!r   c                 H    t        | j                  j                               S )zAReturn a list of all names established in this :class:`.Context`.)listr   keysr&   s    r   r1   zContext.keysa   s     DJJOO%&&r   c                 b    || j                   v r| j                   |   S t        j                  |   S N)r   builtins__dict__r   keys     r   __getitem__zContext.__getitem__f   s-    $**::c?"$$S))r   c                 x    t        j                         }| j                  j                  |       |j                  S )zUpush a capturing buffer onto this Context and return
        the new writer function.)r   FastEncodingBufferr   r*   writer   bufs     r   _push_writerzContext._push_writerl   s0     %%'!!#&yyr   c                 l    | j                   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   popr;   r<   s     r   _pop_buffer_and_writerzContext._pop_buffer_and_writert   s4       $$&D&&r*0000r   c                 $    | j                          y)z*push a capturing buffer onto this Context.N)r>   r&   s    r   _push_bufferzContext._push_buffer}   s     	r   c                 6    | j                   j                         S )z7pop the most recent capturing buffer from this Context.)r   r@   r&   s    r   _pop_bufferzContext._pop_buffer   s     !!%%''r   Nc                 v    | j                   j                  |t        j                  j                  ||            S )z+Return a value from this :class:`.Context`.)r   getr4   r5   )r   r7   defaults      r   rG   zContext.get   s,     zz~~c8#4#4#8#8g#FGGr   c                 @    | j                   d   j                  |       y)zSWrite a string to this :class:`.Context` object's
        underlying output buffer.r-   Nr   r;   )r   strings     r   r;   zContext.write   s     	2$$V,r   c                 4    | j                   d   j                  S )z#Return the current writer function.r-   rJ   r&   s    r   writerzContext.writer   s     !!"%+++r   c                 B   t         j                  t               }| j                  |_        | j                  j	                         |_        | j
                  |_        | j                  |_        | j                  |_        | j                  |_        | j                  |_	        |S r3   )
r   __new__r   r   r   r   r   r   r   r   )r   cs     r   _copyzContext._copy   ss    OOG$,,**//#LL	..#'#>#> **r   c                 d    |s| S | j                         }|j                  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.


        )rQ   r   update)r   drP   s      r   _localszContext._locals   s,     KJJL	qr   c                     | j                         }|j                  }|j                  dd       |j                  dd       |j                  dd       |S )zfcreate a new copy of this :class:`.Context`. with
        tokens related to inheritance state removed.r   Nparentnext)rQ   r   r@   )r   rP   xs      r   _clean_inheritance_tokensz!Context._clean_inheritance_tokens   sG     JJLGG	fd	h	fdr   r3   )__name__
__module____qualname____doc__r   r#   propertyr%   r(   r+   r.   r1   r8   r>   rA   rC   rE   rG   r;   rM   rQ   rU   rZ    r   r   r   r      s    A" * * # #*)"'
*1
(
H
-,
	"	r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	r   c                     d | _         y r3   )
nextcallerr&   s    r   r   zCallerStack.__init__   s	    r   c                 "    | j                         S r3   __bool__r&   s    r   __nonzero__zCallerStack.__nonzero__       }}r   c                 L    t        |       xr | j                         xr dxs dS )NTF)len_get_callerr&   s    r   rf   zCallerStack.__bool__   s$    4y8T--/8DAEAr   c                     | d   S Nr-   r`   r&   s    r   rk   zCallerStack._get_caller   s     Bxr   c                 6    t        | j                         |      S r3   )getattrrk   r6   s     r   __getattr__zCallerStack.__getattr__   s    t'')3//r   c                 V    | j                   xs d }| j                  |       d | _         |S r3   )rc   r*   )r   frames     r   _push_framezCallerStack._push_frame   s(    '4Er   c                 .    | j                         | _        y r3   )r@   rc   r&   s    r   
_pop_framezCallerStack._pop_frame   s    ((*r   N)
r[   r\   r]   r   rg   rf   rk   rp   rs   ru   r`   r   r   r   r      s&    B
0%r   r   c                   "    e Zd ZdZd Zd Zd Zy)	UndefinedzRepresents an undefined value in a template.

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

    c                     t        d      )Nrw   )	NameErrorr&   s    r   __str__zUndefined.__str__   s    $$r   c                 "    | j                         S r3   re   r&   s    r   rg   zUndefined.__nonzero__   rh   r   c                      y)NFr`   r&   s    r   rf   zUndefined.__bool__   s    r   N)r[   r\   r]   r^   rz   rg   rf   r`   r   r   rw   rw      s    %r   rw    c                   J    e Zd ZdZd Zd Zd Zed        Zd Z	d Z
d Zd	 Zy
)	LoopStackza stack for LoopContexts that implements the context manager protocol
    to automatically pop off the top of the stack on context exit
    c                     g | _         y r3   stackr&   s    r   r   zLoopStack.__init__   s	    
r   c                 <    | j                  |       | j                  S r3   )_push_topr   iterables     r   _enterzLoopStack._enter   s    

8yyr   c                 :    | j                          | j                  S r3   )_popr   r&   s    r   _exitzLoopStack._exit   s    		yyr   c                 <    | j                   r| j                   d   S | S rm   r   r&   s    r   r   zLoopStack._top  s    ::::b>!Kr   c                 6    | j                   j                         S r3   )r   r@   r&   s    r   r   zLoopStack._pop  s    zz~~r   c                     t        |      }| j                  r| j                  d   |_        | j                  j                  |      S rm   )LoopContextr   rW   r*   )r   r   news      r   r   zLoopStack._push  s7    (#::BCJzz  %%r   c                 ,    t        j                  d      )NzNo loop context is established)r   RuntimeExceptionr6   s     r   rp   zLoopStack.__getattr__  s    ))*JKKr   c                 ,    t        | j                        S r3   )iterr   r&   s    r   __iter__zLoopStack.__iter__  s    DIIr   N)r[   r\   r]   r^   r   r   r   r_   r   r   r   rp   r   r`   r   r   r   r      s?       &Lr   r   c                       e Zd ZdZd Zd Zej                  d        Ze	d        Z
e	d        Ze	d        Ze	d        Ze	d	        Zd
 Zy)r   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                 .    || _         d| _        d | _        y Nr   )	_iterableindexrW   r   s     r   r   zLoopContext.__init__3  s    !
r   c              #   `   K   | j                   D ]  }| | xj                  dz  c_         y wN   )r   r   )r   is     r   r   zLoopContext.__iter__8  s+      	AGJJ!OJ	s   ,.c                 ,    t        | j                        S r3   )rj   r   r&   s    r   __len__zLoopContext.__len__=  s    4>>""r   c                 8    t        |       | j                  z
  dz
  S r   )rj   r   r&   s    r   reverse_indexzLoopContext.reverse_indexA  s    4y4::%))r   c                      | j                   dk(  S r   )r   r&   s    r   firstzLoopContext.firstE  s    zzQr   c                 8    | j                   t        |       dz
  k(  S r   )r   rj   r&   s    r   lastzLoopContext.lastI  s    zzSY]**r   c                     | j                    S r3   )oddr&   s    r   evenzLoopContext.evenM  s    88|r   c                 2    t        | j                  dz        S )N   )boolr   r&   s    r   r   zLoopContext.oddQ  s    DJJN##r   c                 R    |st        d      || j                  t        |      z     S )z,Cycle through values as the loop progresses.z(You must provide values to cycle through)
ValueErrorr   rj   )r   valuess     r   cyclezLoopContext.cycleU  s)    GHHdjj3v;.//r   N)r[   r\   r]   r^   r   r   r   memoized_instancemethodr   r_   r   r   r   r   r   r   r`   r   r   r   r     s    ,

 
!!# "# * *   + +   $ $0r   r   c                       e Zd Zd Zd Zy)_NSAttrc                     || _         y r3   )_NSAttr__parent)r   rW   s     r   r   z_NSAttr.__init__]  s	    r   c                     | j                   }|r;t        |j                  |      rt        |j                  |      S |j                  }|r;t        |      r3   )r   hasattrmodulero   inheritsAttributeError)r   r7   nss      r   rp   z_NSAttr.__getattr__`  sH    ]]ryy#&ryy#..[[	 
 S!!r   N)r[   r\   r]   r   rp   r`   r   r   r   r   \  s    "r   r   c                       e Zd ZdZ	 	 	 	 ddZdZdZ	 dZ	 dZ	 dZ		 dZ
	 dZej                  d        Zd Zd Zd Zed	        Zd
 Zd Zd Zd Zy)	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.

    Nc                 ~    || _         || _        || _        |!|D ci c]  }|j                  | c}| _        y y c c}w r3   )namecontextr   r[   	callables)r   r   r   r   r   populate_selfcalling_urirP   s           r   r   zNamespace.__init__{  sA     	  5>?ajj!m?DN !?s   :r`   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`

        )r   r&   s    r   attrzNamespace.attr  s     t}r   c                    | |f}|| j                   j                  v r| j                   j                  |   S t        || j                   j                         || j                        }|| 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   TemplateNamespacerQ   _templateuri)r   urir7   r   s       r   get_namespacezNamespace.get_namespace  sx    ( Sk$,,)))<<**3//LL ))	
 (*$	r   c                 D    t        | j                  || j                        S )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_templater   r   )r   r   s     r   get_templatezNamespace.get_template  s      c43D3DEEr   c                 <     | 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>``.

        )cacherG   )r   r7   r(   s      r   
get_cachedzNamespace.get_cached  s     tzz~~c,V,,r   c                 .    | j                   j                  S )zReturn the :class:`.Cache` object referenced
        by this :class:`.Namespace` object's
        :class:`.Template`.

        )templater   r&   s    r   r   zNamespace.cache  s     }}"""r   c                 H    t        | j                  || j                  fi | y)z$Include a file at the given ``uri``.N)_include_filer   r   )r   r   r(   s      r   include_filezNamespace.include_file  s     	dllC):):EfEr   c                 v    |D ]4  }|dk(  r| j                         D ]
  \  }}|||<    &t        | |      ||<   6 y )N*)	_get_starro   )r   rT   lidentkvs         r   	_populatezNamespace._populate  sM     	0E| NN, DAqAaD #4/%	0r   c              #   n   K   | j                   r%| j                   D ]  }|| j                   |   f  y y wr3   )r   r6   s     r   r   zNamespace._get_star  s9     >>~~ 1DNN3/001 s   35c                     || j                   v r| j                   |   }n?| j                  rt        | j                  |      }nt        d| j                  d|d      t        | ||       |S NzNamespace 'z' has no member '')r   r   ro   r   r   setattr)r   r7   vals      r   rp   zNamespace.__getattr__  s_    $.. ..%C]]$---C 7;yy#F  	c3
r   NNTN)r[   r\   r]   r^   r   r   r   r   r   filenamer   r   r   memoized_propertyr   r   r   r   r_   r   r   r   r   rp   r`   r   r   r   r   j  s    & @ IF H
 G H C L	  @F- # #F
01

r   r   c                   `    e Zd ZdZ	 	 	 	 	 	 d	dZed        Zed        Zed        Zd Z	d Z
y)
r   z@A :class:`.Namespace` specific to a :class:`.Template` instance.Nc	                    || _         || _        || _        | |D 	ci c]  }	|	j                  |	 c}	| _        |8t        |||      | _        | j                  j                  j                  | _	        n0|#|| _        |j                  j                  | _	        nt        d      |rt        || j                  |       \  }
}y y c c}	w )Nz 'template' argument is required.)self_ns)r   r   r   r[   r   r   r   r   _template_urir   	TypeError_populate_self_namespace)r   r   r   r   r   r   r   r   r   rP   lclcallable
lclcontexts               r   r   zTemplateNamespace.__init__0  s     	  5>?ajj!m?DN",Wk;ODM $ 4 4 B BD!$DM ( = =D>??&>'#K  @s   Cc                 .    | j                   j                  S )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.

        )r   r   r&   s    r   r   zTemplateNamespace.moduleO  s     }}###r   c                 .    | j                   j                  S zhThe path of the filesystem file used for this
        :class:`.Namespace`'s module or template.
        )r   r   r&   s    r   r   zTemplateNamespace.filenameZ  s    
 }}%%%r   c                 .    | j                   j                  S )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`.

        )r   r   r&   s    r   r   zTemplateNamespace.uria  s     }}   r   c              #       K    j                   r$ j                   D ]  }| j                   |   f   fd} j                  j                  j                  D ]  }| ||      f  y w)Nc                 z    j                   j                  |       }t        j                  |j                        S r3   )r   _get_def_callabler   r   r   )r7   	callable_r   s     r   rG   z(TemplateNamespace._get_star.<locals>.getq  s.    77<I$$Y==r   )r   r   r   _exports)r   r7   rG   r   s   `   r   r   zTemplateNamespace._get_starl  si     >>~~ 1DNN3/001	> %%.. 	Ac!f+	s   A(A+c                    || j                   v r| j                   |   }n| j                  j                  |      r<| j                  j                  |      }t	        j
                  || j                        }n?| j                  rt        | j                  |      }nt        d| j                  d|d      t        | ||       |S r   )r   r   has_defr   r   r   r   r   ro   r   r   r   r   r7   r   r   s       r   rp   zTemplateNamespace.__getattr__x  s    $.. ..%C]]""3'77<I##It||<C]]$---C !7;yy#F  	c3
r   )NNNNTN)r[   r\   r]   r^   r   r_   r   r   r   r   rp   r`   r   r   r   r   ,  sd    J > $ $ & & ! !
r   r   c                   <    e Zd ZdZ	 	 	 	 ddZed        Zd Zd Zy)ModuleNamespacez;A :class:`.Namespace` specific to a Python module instance.Nc                     || _         || _        || _        | |D ci c]  }|j                  | c}| _        t        |      }	|j                  d      dd  D ]  }
t        |	|
      }	 |	| _        y c c}w )N.r   )	r   r   r   r[   r   
__import__splitro   r   )r   r   r   r   r   r   r   r   rP   modtokens              r   r   zModuleNamespace.__init__  s{     	  5>?ajj!m?DN \\#&qr* 	&E#u%C	& @s   A0c                 .    | j                   j                  S r   )r   __file__r&   s    r   r   zModuleNamespace.filename  s    
 {{###r   c              #   >  K   | j                   r$| j                   D ]  }|| j                   |   f  t        | j                        D ]Q  }|d   dk7  st        | j                  |      }t	        |      s.|t        j                  || j                        f S y w)Nr   _)r   dirr   ro   callabler   r   r   )r   r7   r   s      r   r   zModuleNamespace._get_star  s     >>~~ 1DNN3/001t{{# 	JC1v}#DKK5	I&y00DLLIII		Js   AB!B6'Bc                 t   || j                   v r| j                   |   }nt        | j                  |      r7t        | j                  |      }t	        j
                  || j                        }n?| j                  rt        | j                  |      }nt        d| j                  d|d      t        | ||       |S r   )r   r   r   ro   r   r   r   r   r   r   r   r   s       r   rp   zModuleNamespace.__getattr__  s    $.. ..%CT[[#&S1I##It||<C]]$---C 7;yy#F  	c3
r   r   )	r[   r\   r]   r^   r   r_   r   r   rp   r`   r   r   r   r     s7    E * $ $Jr   r   c                       fd}|S )zApply a caller_stack compatibility decorator to a plain
    Python function.

    See the example in :ref:`namespaces_python_modules`.

    c                     | j                   j                          	  | g|i || j                   j                          S # | j                   j                          w xY wr3   )r   rs   ru   )r   argsr(   funcs      r   wrap_stackframez(supports_caller.<locals>.wrap_stackframe  sQ    ((*	.1$1&1  ++-G  ++-s   A Ar`   )r  r  s   ` r   supports_callerr    s    . r   c                     t        |      st        j                  d      | j                          	  ||i | | j	                         }|j                         S # | j	                         }w xY w)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)))r	  r   r   rC   rE   getvalue)r   r   r  r(   r=   s        r   r	   r	     sq     I))A
 	
 $4"6"!!#<<> !!#s   A A,c                       fd}|S )Nc                       fd}|S )Nc                 ~      fd}	 j                   dd  |_           |       g|i |S # t        $ r Y w xY w)Nc                       g| i |S r3   r`   )r  kwr   	render_fns     r   yzB_decorate_toplevel.<locals>.decorate_render.<locals>.go.<locals>.y  s     646266r      )r[   r   )r   r  r  r  fnr  s   `   r   goz7_decorate_toplevel.<locals>.decorate_render.<locals>.go  sR    7&//3
 2a5.4.2..  s   0 	<<r`   )r  r  r  s   ` r   decorate_renderz+_decorate_toplevel.<locals>.decorate_render  s    		/ 	r   r`   )r  r  s   ` r   _decorate_toplevelr    s     r   c                       fd}|S )Nc                 &     |       fd}|S )Nc                       g| i |S r3   r`   )r  r  r   decs     r   r  z5_decorate_inline.<locals>.decorate_render.<locals>.go   s    w,,,,r   r`   )r  r  r"  r   r  s     @r   r  z)_decorate_inline.<locals>.decorate_render  s    m	- 	r   r`   )r   r  r  s   `` r   _decorate_inliner#    s     r   c                 2   t        | ||      }t        | j                         |      \  }}t        || j                  fi |}|j
                  r	  ||fi | y ||fi | y# t        $ r* |j                  |t        j                               }|s Y yw xY w)zPlocate the template from the given uri and include it in
    the current output.N)	r   r   rZ   _kwargs_for_includer   include_error_handler	Exceptionr   exception_as)r   r   r   r(   r   r   ctxresults           r   r   r     s      k:H/))+XY !GMMDVDF%%	c$V$ 	#    	33C9L9L9NOF 	s   	A# #0BBc                    |yt        | ||      }| d   }|}|j                  |j                  }|j                  | j                  d|i      }t        d|j                  z  ||d      |_        |j                  x| j
                  d<   |j
                  d<   t        |j                  d	d      }| |||      }|r|S t        |j                  d
d      }	|	 |	|        |j                  |fS )zcalled by the _inherit method in template modules to set
    up the inheritance chain at the start of a template's
    execution.Nr   rX   self:%sFr   r   rW   local_mako_inherit_mako_generate_namespaces)	r   r   rU   r   r   r   ro   r   r   )
r   r   r   r   r   ihr   r   retgen_nss
             r   _inherit_fromr4    s    
 {k:HfoG	B
++
![[ ++
!&".J#HLL 	BK ;=++EGMM(j..w7$?I*-JX__&A4HFw
++r   c                 j   | j                   j                  }|,t        j                  d| j                   j                  z        |j                  ||      }	 |j                  |      S # t        j                  $ r6}t        j                  t        t        j                                     |d }~ww xY w)Nz.Template '%s' has no TemplateLookup associated)r   r%   r   TemplateLookupExceptionr   
adjust_urir   TopLevelLookupExceptionstrr   r(  )r   r   
relativetor%   es        r   r   r   <  s    ##**F~00<$$(()
 	
 

C
,C""3''-- 00##%&
	s   A) )B2<1B--B2c                    |t        d|j                  z  | |d      }|x| j                  d<   | j                  d<   t        |j                  d      r |j                  j                  ||       }|r|S |j                  | fS )Nr,  Fr-  r   r.  r/  )r   r   r   r   r   r/  r   )r   r   r   r2  s       r   r   r   L  s    #$	
 6=<GMM&GMM'2x0oo++Hg>J((r   c                 @   |rt        j                         }n+t        j                  | j                  | j                        }t	        |fi |}||_        |j                  |        t        | ||g|i t        ||       |j                         j                         S )z^create a Context and return the string
    output of the given template and template callable.)encodingerrors)r   r:   output_encodingencoding_errorsr   r   r#   _render_context_kwargs_for_callablerE   r  )r   r   r  r   
as_unicoder=   r   s          r   _renderrE  \  s     %%'%%--h6N6N
 c"T"G%/G"x( 
	
 y$
/  ))++r   c                     t        j                  |       }|d   r|S |d   |dd D cg c]  }||	 c}z   }i }|D ]  }|dk7  s	||v s||vs||   ||<    |S c c}w )Nr   r   r      r   r   inspect_getargspec)r   r   argspecr   	namedargsr(   args          r   rC  rC  t  s    ''	2Gqz 
1GAaGGIF $)t60As)F3K$ M Hs
   AAc                     t        j                  |       }|d   |dd D cg c]  }||	 c}z   }|D ]  }|dk7  s	||v s||vs||   ||<    |S c c}w )Nr   r   rG  r   rH  )r   r   r(   rJ  r   rK  rL  s          r   r%  r%    ss    ''	2G
1GAaGGI $)t60As)F3K$ M	 Hs
   AAc                     dd l m} t        | |j                        st	        ||       \  }}t        ||||       y t	        || j                        \  }}t        ||||       y )Nr   )r  r(   )mako.templater   
isinstanceDefTemplater   _exec_templaterW   )tmplr   r   r  r(   r   inheritr   s           r   rB  rB    s[    $ dH001 8$ G*w
fE !9$++ N*y'VDr   c                 ,   |j                   }|&|j                  s|j                  r	  | |g|i | y | |g|i | y# t        $ r" t	        ||t        j                                Y y t        j                         d   }t	        |||       Y yxY w)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   format_exceptionserror_handlerr'  _render_errorr   r(  sysexc_info)r   r   r  r(   r   r;  s         r   rR  rR    s     %%H""h&<&<	0g/// 	'+D+F+  	D(GV-@-@-BC	0q!A(GQ/s   A (B,%Bc                    | j                   rD| j                  ||      }|s/t        j                         \  }}}|r|r|j                  |      |y t	        j
                         }|j                  r#t        j                         g|j                  d d  n8t        j                  |j                  |j                        g|j                  d d  |j                  |       |j                  ||       y )N)error)rW  rY  rZ  with_tracebackr   html_error_templater   r   r:   r   r@  rA  r#   render_context)r   r   r\  r*  tpvaluetberror_templates           r   rX  rX    s    ''7LLNMBr**2..  $779))(,(?(?(A'BG!!!$ ''"22"22(G!!!$ 	"">2%%gU%;r   r3   )F)NN)"r^   r4   r   rY  makor   r   r   r   r0   r   rw   	UNDEFINEDSTOP_RENDERINGr   r   r   r   r   r   r  r	   r  r#  r   r4  r   r   rE  rC  r%  rB  rR  rX  r`   r   r   <module>rg     s   ,   
   i iX%$ %8 ( K	% %P>0 >0B" " DZ	 Zz7i 7t$*$	!(,@ ) ,0E,.<r   