
    YeIil                        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!dS )+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dS )ContextzProvides runtime namespace, output buffer, and various
    callstacks for templates.

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

    c                     |g| _         || _        |                                | _        d | _        d | _        i | _        t          j        t          |           | j        d<   t                      x| _        | 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datas      Q/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/mako/runtime.py__init__zContext.__init__   st    $X
yy{{"&*# !* 1'4 @ @
9 4?==@DJx000    c                     || _         |j                            | j                  }|r*t	          j        dd                    |          z            d S )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.   s`    (55djA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                 4    | 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                             |           dS )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= dS )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                 N    t          | j                                                  S )zAReturn a list of all names established in this :class:`.Context`.)listr   keysr&   s    r   r1   zContext.keysa   s     DJOO%%&&&r   c                 R    || 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                 j    t          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   s1     %''!!#&&&yr   c                 \    | 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   s.      $$&&D&r*000r   c                 .    |                                   dS )z*push a capturing buffer onto this Context.N)r>   r&   s    r   _push_bufferzContext._push_buffer}   s     	r   c                 4    | j                                         S )z7pop the most recent capturing buffer from this Context.)r   r@   r&   s    r   _pop_bufferzContext._pop_buffer   s     !%%'''r   Nc                 t    | j                             |t          j                            ||                    S )z+Return a value from this :class:`.Context`.)r   getr4   r5   )r   r7   defaults      r   rG   zContext.get   s-     z~~c8#4#8#8g#F#FGGGr   c                 F    | j         d                             |           dS )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                 &    | j         d         j        S )z#Return the current writer function.r-   rJ   r&   s    r   writerzContext.writer   s     !"%++r   c                    t                               t                     }| 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   sg    OOG$$,*//##L	.#'#> *r   c                 j    |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.


        )rQ   r   update)r   drP   s      r   _localszContext._locals   s7      	KJJLL	qr   c                     |                                  }|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)rQ   r   r@   )r   rP   xs      r   _clean_inheritance_tokensz!Context._clean_inheritance_tokens   sY     JJLLG	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      sP        A A A"   * * X* # # X#*) ) )" " "' ' '
* * *  1 1 1  
( ( (
H H H H
- - -, , ,
	 	 	  "	 	 	 	 	r   r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	r   c                     d | _         d S r3   )
nextcallerr&   s    r   r   zCallerStack.__init__   s    r   c                 *    |                                  S r3   __bool__r&   s    r   __nonzero__zCallerStack.__nonzero__       }}r   c                 P    t          |           r|                                 rdpdS )NTF)len_get_callerr&   s    r   rf   zCallerStack.__bool__   s)    4yy8T--//8DAEAr   c                     | d         S Nr-   r`   r&   s    r   rk   zCallerStack._get_caller   s     Bxr   c                 F    t          |                                 |          S r3   )getattrrk   r6   s     r   __getattr__zCallerStack.__getattr__   s    t''))3///r   c                 P    | j         pd }|                     |           d | _         |S r3   )rc   r*   )r   frames     r   _push_framezCallerStack._push_frame   s,    '4Er   c                 8    |                                  | _        d S 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 B B  
0 0 0  % % % % %r   r   c                   $    e Zd ZdZd Zd Zd ZdS )	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                 *    |                                  S r3   re   r&   s    r   rg   zUndefined.__nonzero__   rh   r   c                     dS )NFr`   r&   s    r   rf   zUndefined.__bool__   s    ur   N)r[   r\   r]   r^   rz   rg   rf   r`   r   r   rw   rw      sK         % % %      r   rw    c                   R    e Zd ZdZd Zd Zd Zed             Zd Z	d Z
d Zd	 Zd
S )	LoopStackza stack for LoopContexts that implements the context manager protocol
    to automatically pop off the top of the stack on context exit
    c                     g | _         d S r3   stackr&   s    r   r   zLoopStack.__init__   s    


r   c                 :    |                      |           | j        S r3   )_push_topr   iterables     r   _enterzLoopStack._enter   s    

8yr   c                 8    |                                   | j        S r3   )_popr   r&   s    r   _exitzLoopStack._exit   s    		yr   c                 .    | j         r| j         d         S | S rm   r   r&   s    r   r   zLoopStack._top  s    : 	:b>!Kr   c                 4    | j                                         S r3   )r   r@   r&   s    r   r   zLoopStack._pop  s    z~~r   c                     t          |          }| j        r| j        d         |_        | j                            |          S rm   )LoopContextr   rW   r*   )r   r   news      r   r   zLoopStack._push  s<    (##: 	(BCJz  %%%r   c                 *    t          j        d          )NzNo loop context is established)r   RuntimeExceptionr6   s     r   rp   zLoopStack.__getattr__  s    )*JKKKr   c                 *    t          | j                  S r3   )iterr   r&   s    r   __iter__zLoopStack.__iter__  s    DIr   N)r[   r\   r]   r^   r   r   r   r_   r   r   r   rp   r   r`   r   r   r   r      s                  X     & & &L L 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dS )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                 0    || _         d| _        d | _        d S Nr   )	_iterableindexrW   r   s     r   r   zLoopContext.__init__3  s    !
r   c              #   F   K   | j         D ]}|V  | xj        dz  c_        d S N   )r   r   )r   is     r   r   zLoopContext.__iter__8  s;       	 	AGGGJJ!OJJJ	 	r   c                 *    t          | j                  S r3   )rj   r   r&   s    r   __len__zLoopContext.__len__=  s    4>"""r   c                 6    t          |           | j        z
  dz
  S r   )rj   r   r&   s    r   reverse_indexzLoopContext.reverse_indexA  s    4yy4:%))r   c                     | j         dk    S r   )r   r&   s    r   firstzLoopContext.firstE  s    zQr   c                 8    | j         t          |           dz
  k    S r   )r   rj   r&   s    r   lastzLoopContext.lastI  s    zSYY]**r   c                     | j          S r3   )oddr&   s    r   evenzLoopContext.evenM  s    8|r   c                 0    t          | j        dz            S )N   )boolr   r&   s    r   r   zLoopContext.oddQ  s    DJN###r   c                 ^    |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  s2     	IGHHHdj3v;;.//r   N)r[   r\   r]   r^   r   r   r   memoized_instancemethodr   r_   r   r   r   r   r   r   r`   r   r   r   r     s         ,  
  
 
!# # "!# * * X*   X + + X+   X $ $ X$0 0 0 0 0r   r   c                       e Zd Zd Zd ZdS )_NSAttrc                     || _         d S r3   )_NSAttr__parent)r   rW   s     r   r   z_NSAttr.__init__]  s    r   c                     | j         }|r3t          |j        |          rt          |j        |          S |j        }|3t          |          r3   )r   hasattrmodulero   inheritsAttributeError)r   r7   nss      r   rp   z_NSAttr.__getattr__`  sX    ] 	!ry#&& !ry#...[	  	!
 S!!!r   N)r[   r\   r]   r   rp   r`   r   r   r   r   \  s2          " " " " "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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                 Z    || _         || _        || _        |d |D             | _        d S d S )Nc                     i | ]
}|j         |S r`   r[   .0rP   s     r   
<dictcomp>z&Namespace.__init__.<locals>.<dictcomp>      ???aj!???r   )namecontextr   	callables)r   r   r   r   r   populate_selfcalling_uris          r   r   zNamespace.__init__{  s@     	  ??Y???DNNN ! r   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        |<   |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  st    ( Sk$,)))<*3//L  )	
 
 
 (*$	r   c                 8    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      c43DE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      tz~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                 8    t          | j        || j        fi | dS )z$Include a file at the given ``uri``.N)_include_filer   r   )r   r   r(   s      r   include_filezNamespace.include_file  s)     	dlC):EEfEEEEEr   c                     |D ];}|dk    r |                                  D ]
\  }}|||<   (t          | |          ||<   <d S )N*)	_get_starro   )r   rT   lidentkvs         r   	_populatezNamespace._populate  sh     	0 	0E|| NN,,  DAqAaDD #4//%	0 	0r   c              #   R   K   | j         r| j         D ]}|| j         |         fV  d S d S r3   )r   r6   s     r   r   zNamespace._get_star  sP      > 	1~ 1 1DN3/00000	1 	11 1r   c                     || j         v r| j         |         }n8| 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__  sy    $.  .%CC] 	$---CC .7;yyy###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  s4        & @ @ @ @ IF H
 G H C L	     @F F F- - - # # X#F F F
0 0 01 1 1

 
 
 
 
r   r   c                   t    e Zd ZdZ	 	 	 	 	 	 d
dZed             Zed             Zed             Zd Z	d	 Z
dS )r   z@A :class:`.Namespace` specific to a :class:`.Template` instance.NTc	                 D   || _         || _        || _        |d |D             | _        |-t	          |||          | _        | j        j        j        | _        n*||| _        |j        j        | _        nt          d          |rt          || j        |           \  }	}
d S d S )Nc                     i | ]
}|j         |S r`   r   r   s     r   r   z.TemplateNamespace.__init__.<locals>.<dictcomp>?  r   r   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
lclcontexts              r   r   zTemplateNamespace.__init__0  s     	  ??Y???DN",Wk;OODM $ 4 BD!$DM ( =D>??? 	&>' ' '#K	 	r   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V   fd} j        j        j        D ]}| ||          fV  d S )Nc                 l    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  s      > 	1~ 1 1DN3/00000	> 	> 	> 	> 	> %. 	 	Acc!ff+	 	r   c                 d   || j         v r| j         |         }n| j                            |          r5| j                            |          }t	          j        || j                  }n8| 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    $.  .%CC]""3'' 		77<<I#It|<<CC] 	$---CC !.7;yyy###F   	c3
r   )NNNNTN)r[   r\   r]   r^   r   r_   r   r   r   r   rp   r`   r   r   r   r   ,  s        JJ    > $ $ X$ & & X& ! ! X!
 
 
    r   r   c                   D    e Zd ZdZ	 	 	 	 ddZed             Zd Zd ZdS )	ModuleNamespacez;A :class:`.Namespace` specific to a Python module instance.NTc                     || _         || _        || _        |d |D             | _        t	          |          }|                    d          dd          D ]}	t          ||	          }|| _        d S )Nc                     i | ]
}|j         |S r`   r   r   s     r   r   z,ModuleNamespace.__init__.<locals>.<dictcomp>  r   r   .r   )r   r   r   r   
__import__splitro   r   )
r   r   r   r   r   r   r   r   modtokens
             r   r   zModuleNamespace.__init__  s     	  ??Y???DN  \\#&&qrr* 	& 	&E#u%%CCr   c                     | j         j        S r   )r   __file__r&   s    r   r   zModuleNamespace.filename  s    
 {##r   c              #     K   | j         r| j         D ]}|| j         |         fV  t          | j                  D ]P}|d         dk    rBt          | j        |          }t	          |          r|t          j        || j                  fV  Qd S )Nr   _)r   dirr   ro   callabler   r   r   )r   r7   r   s      r   r   zModuleNamespace._get_star  s      > 	1~ 1 1DN3/00000t{## 	J 	JC1v}}#DK55	I&& Jy0DLIIIIII		J 	Jr   c                 P   || j         v r| j         |         }n}t          | j        |          r0t          | j        |          }t	          j        || j                  }n8| 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    $.  .%CCT[#&& 	S11I#It|<<CC] 	$---CC .7;yyy###F   	c3
r   r   )	r[   r\   r]   r^   r   r_   r   r   rp   r`   r   r   r  r    sx        EE    * $ $ X$J J 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                                          	  | g|R i || j                                          S # | j                                          w xY wr3   )r   rs   ru   )r   argsr(   funcs      r   wrap_stackframez(supports_caller.<locals>.wrap_stackframe  sm    ((***	.41$111&11 ++----G ++----s   A Ar`   )r  r  s   ` r   supports_callerr    s$    . . . . . r   c                    t          |          st          j        d          |                                  	  ||i | |                                 }n# |                                 }w xY w|                                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)))r  r   r   rC   rE   getvalue)r   r   r  r(   r=   s        r   r	   r	     s     I 
)A
 
 	
 $	4"6"""!!##g!!######<<>>s   A A,c                       fd}|S )Nc                       fd}|S )Nc                       fd}	 j         dd          |_         n# t          $ r Y nw xY w  |           g|R i |S )Nc                       g| R i |S r3   r`   )r  kwr   	render_fns     r   yzB_decorate_toplevel.<locals>.decorate_render.<locals>.go.<locals>.y  s#     y646662666r      )r[   r   )r   r  r  r!  fnr   s   `   r   goz7_decorate_toplevel.<locals>.decorate_render.<locals>.go  s    7 7 7 7 7 7&/3

    22a55.4...2...s    
,,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| R i |S r3   r`   )r  r  r   decs     r   r$  z5_decorate_inline.<locals>.decorate_render.<locals>.go   s#    3w,,,,,,,r   r`   )r   r$  r*  r   r#  s     @r   r%  z)_decorate_inline.<locals>.decorate_render  s6    bmm	- 	- 	- 	- 	- 	- 	r   r`   )r   r#  r%  s   `` r   _decorate_inliner+    s*          r   c                 F   t          | ||          }t          |                                 |          \  }}t          || j        fi |}|j        rG	  ||fi | dS # t          $ r. |                    |t          j                              }|s Y dS w xY w ||fi | dS )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 !GMDDVDDF% !	Ic$$V$$$$$ 	 	 	33C9L9N9NOOF   	
 		#       s   	A 4BBc                    |dS t          | ||          }| d         }|}|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_fromr<    s   
 {tk::HfoG	B
+
![ +
!&"..J#HL 	  BK ;=+EGM(j.w7$??Ii*-- 	JX_&A4HHFw
++r   c                 L   | j         j        }|!t          j        d| j         j        z            |                    ||          }	 |                    |          S # t          j        $ r8}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   r0  )r   r   
relativetor%   es        r   r   r   <  s    #*F~0<$()
 
 	
 

C
,
,C""3'''-   0#%%&&
 
	s   A B#+3BB#c                     |t          d|j        z  | |d          }|x| j        d<   | j        d<   t          |j        d          r|j                            ||           }|r|S |j        | fS )Nr4  Fr5  r   r6  r7  )r   r   r   r   r   r7  r   )r   r   r   r:  s       r   r   r   L  s    #$	
 
 
 6=<GM&GM'2x00 o++Hg>> 	J((r   Fc                 L   |rt          j                    }n t          j        | j        | j                  }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   r:   output_encodingencoding_errorsr   r   r#   _render_context_kwargs_for_callablerE   r  )r   r   r  r   
as_unicoder=   r   s          r   _renderrM  \  s      
%''%-h6N
 
 
 c""T""G%/G"x((( 
	  
 y$
/
/     ))+++r   c                     t          j        |           }|d         r|S |d         d |dd         D             z   }i }|D ]}|dk    r||v r||vr||         ||<   |S )Nr   r   c                     g | ]}||S r3   r`   r   r   s     r   
<listcomp>z(_kwargs_for_callable.<locals>.<listcomp>{      GGGAar   r      r   r   inspect_getargspec)r   r   argspec	namedargsr(   args         r   rK  rK  t  s    '	22Gqz  
GG1GGGGIF $ $)t60A0As)F3KMr   c                     t          j        |           }|d         d |dd         D             z   }|D ]}|dk    r||v r||vr||         ||<   |S )Nr   c                     g | ]}||S r3   r`   rP  s     r   rQ  z'_kwargs_for_include.<locals>.<listcomp>  rR  r   r   rS  r   rT  )r   r   r(   rV  rW  rX  s         r   r-  r-    sv    '	22G
GG1GGGGI $ $)t60A0As)F3KMr   c                     dd l m} t          | |j                  s(t	          ||           \  }}t          ||||           d S t	          || j                  \  }}t          ||||           d S )Nr   )r  r(   )mako.templater   
isinstanceDefTemplater   _exec_templaterW   )tmplr   r   r  r(   r   inheritr   s           r   rJ  rJ    s    $$$$$$ dH011 E 8$ G G*w
fEEEEEE !9$+ N N*y'VDDDDDDr   c                 *   |j         }|}|j        s|j        ro	  | |g|R i | dS # t          $ r& t	          ||t          j                               Y dS  t          j                    d         }t	          |||           Y dS xY w | |g|R i | dS )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   r0  sysexc_info)r   r   r  r(   r   rC  s         r   r_  r_    s     %H" &.&< 	0Ig///////// 	D 	D 	D(GV-@-B-BCCCCCC	0q!A(GQ//////	'+D+++F+++++s   ' ,B+Bc                    | j         rL|                      ||          }|s2t          j                    \  }}}|r|r|                    |          |d S t	          j                    }|j        rt          j                    g|j	        d d <   n*t          j        |j
        |j                  g|j	        d d <   |                    |           |                    ||           d S )N)error)rd  rf  rg  with_tracebackr   html_error_templater   r   r:   r   rH  rI  r#   render_context)r   r   ri  r2  tpvaluetberror_templates           r   re  re    s    <''77 	LNNMBr  **2...	 	 $799) 	(,(?(A(A'BG!!!!$$ '"2"2 (G!!!!$ 	"">222%%gU%;;;;;r   r3   )F)NN)"r^   r4   r   rf  makor   r   r   r   r0   r   rw   	UNDEFINEDSTOP_RENDERINGr   r   r   r   r   r  r  r	   r&  r+  r   r<  r   r   rM  rK  r-  rJ  r_  re  r`   r   r   <module>rt     s  , ,      



                  i i i i i i i iX% % % % %$ % % %8       ( IKK	% % % % % % % %P>0 >0 >0 >0 >0 >0 >0 >0B" " " " " " " "       DZ Z Z Z Z	 Z Z Zz7 7 7 7 7i 7 7 7t  $  *  $	 	 	! ! !(, , ,@   ) ) ) ) , , , ,0    E E E, , , ,.< < < < <r   