B
    dl                 @   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 )(ContextzProvides 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   Y/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/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   ZNameConflictErrorjoin)r   tZillegal_namesr   r   r   _set_with_template.   s    zContext._set_with_templatec             C   s   | 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   s
   | 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	   keys)r   r   r   r   r%   a   s    zContext.keysc             C   s"   || j kr| j | S tj| S d 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   popr+   )r   r,   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)r-   )r   r   r   r   _push_buffer}   s    zContext._push_bufferc             C   s
   | j  S )z7pop the most recent capturing buffer from this Context.)r   r.   )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   r2      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   r+   )r   stringr   r   r   r+      s    zContext.writec             C   s   | j d jS )z#Return the current writer function.r"   )r   r+   )r   r   r   r   writer   s    zContext.writerc             C   sJ   t t }| j|_| j |_| j|_| j|_| j|_| j|_| j	|_	|S )N)
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 )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.


        )r8   r	   update)r   dr7   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)r8   r	   r.   )r   r7   xr   r   r   _clean_inheritance_tokens   s    z!Context._clean_inheritance_tokens)N)__name__
__module____qualname____doc__r   r   propertyr   r   r!   r#   r%   r)   r-   r/   r0   r1   r2   r+   r5   r8   r;   r?   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 )N)
nextcaller)r   r   r   r   r      s    zCallerStack.__init__c             C   s   |   S )N)__bool__)r   r   r   r   __nonzero__   s    zCallerStack.__nonzero__c             C   s   t | r|  rdpdS )NTF)len_get_caller)r   r   r   r   rF      s    zCallerStack.__bool__c             C   s   | d S )Nr"   r   )r   r   r   r   rI      s    zCallerStack._get_callerc             C   s   t |  |S )N)getattrrI   )r   r(   r   r   r   __getattr__   s    zCallerStack.__getattr__c             C   s   | j pd }| | d | _ |S )N)rE   r    )r   framer   r   r   _push_frame   s    

zCallerStack._push_framec             C   s   |   | _d S )N)r.   rE   )r   r   r   r   
_pop_frame   s    zCallerStack._pop_frameN)
r@   rA   rB   r   rG   rF   rI   rK   rM   rN   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 )		UndefinedzRepresents 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d S )NrO   )	NameError)r   r   r   r   __str__   s    zUndefined.__str__c             C   s   |   S )N)rF   )r   r   r   r   rG      s    zUndefined.__nonzero__c             C   s   dS )NFr   )r   r   r   r   rF      s    zUndefined.__bool__N)r@   rA   rB   rC   rQ   rG   rF   r   r   r   r   rO      s   rO    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 )	LoopStackza 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 )N)stack)r   r   r   r   r      s    zLoopStack.__init__c             C   s   |  | | jS )N)_push_top)r   iterabler   r   r   _enter   s    
zLoopStack._enterc             C   s   |    | jS )N)_poprV   )r   r   r   r   _exit   s    zLoopStack._exitc             C   s   | j r| j d S | S d S )Nr"   )rT   )r   r   r   r   rV     s    
zLoopStack._topc             C   s
   | j  S )N)rT   r.   )r   r   r   r   rY     s    zLoopStack._popc             C   s&   t |}| jr| jd |_| j|S )Nr"   )LoopContextrT   r<   r    )r   rW   newr   r   r   rU     s    zLoopStack._pushc             C   s   t dd S )NzNo loop context is established)r   RuntimeException)r   r(   r   r   r   rK     s    zLoopStack.__getattr__c             C   s
   t | jS )N)iterrV   )r   r   r   r   __iter__  s    zLoopStack.__iter__N)r@   rA   rB   rC   r   rX   rZ   rD   rV   rY   rU   rK   r_   r   r   r   r   rS      s   rS   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 )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             C   s   || _ d| _d | _d S )Nr   )	_iterableindexr<   )r   rW   r   r   r   r   3  s    zLoopContext.__init__c             c   s(   x"| j D ]}|V  |  jd7  _qW d S )N   )r`   ra   )r   ir   r   r   r_   8  s    zLoopContext.__iter__c             C   s
   t | jS )N)rH   r`   )r   r   r   r   __len__=  s    zLoopContext.__len__c             C   s   t | | j d S )Nrb   )rH   ra   )r   r   r   r   reverse_indexA  s    zLoopContext.reverse_indexc             C   s
   | j dkS )Nr   )ra   )r   r   r   r   firstE  s    zLoopContext.firstc             C   s   | j t| d kS )Nrb   )ra   rH   )r   r   r   r   lastI  s    zLoopContext.lastc             C   s   | j  S )N)odd)r   r   r   r   evenM  s    zLoopContext.evenc             C   s   t | jd S )N   )boolra   )r   r   r   r   rh   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)
ValueErrorra   rH   )r   valuesr   r   r   cycleU  s    zLoopContext.cycleN)r@   rA   rB   rC   r   r_   r   Zmemoized_instancemethodrd   rD   re   rf   rg   ri   rh   rn   r   r   r   r   r[     s   r[   c               @   s   e Zd Zdd Zdd ZdS )_NSAttrc             C   s
   || _ d S )N)_NSAttr__parent)r   r<   r   r   r   r   ]  s    z_NSAttr.__init__c             C   s:   | j }x&|r,t|j|r$t|j|S |j}qW t|d S )N)rp   hasattrmodulerJ   inheritsAttributeError)r   r(   nsr   r   r   rK   `  s    
z_NSAttr.__getattr__N)r@   rA   rB   r   rK   r   r   r   r   ro   \  s   ro   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   s.   || _ || _|| _|d k	r*dd |D | _d S )Nc             S   s   i | ]}||j qS r   )r@   ).0r7   r   r   r   
<dictcomp>  s    z&Namespace.__init__.<locals>.<dictcomp>)namecontextrs   	callables)r   ry   rz   r{   rs   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`

        )ro   )r   r   r   r   attr  s    zNamespace.attrc             C   sH   | |f}|| j jk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}   )rz   r   TemplateNamespacer8   _templateuri)r   urir(   ru   r   r   r   get_namespace  s    
zNamespace.get_namespacec             C   s   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_templaterz   r   )r   r   r   r   r   get_template  s    zNamespace.get_templatec             K   s   | j j|f|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>``.

        )cacher2   )r   r(   r   r   r   r   
get_cached  s    zNamespace.get_cachedc             C   s   | j jS )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| dS )z$Include a file at the given ``uri``.N)_include_filerz   r   )r   r   r   r   r   r   include_file  s    zNamespace.include_filec             C   sH   xB|D ]:}|dkr2x,|   D ]\}}|||< qW qt| |||< qW d S )N*)	_get_starrJ   )r   r:   lidentkvr   r   r   	_populate  s
    
zNamespace._populatec             c   s*   | j r&x| j D ]}|| j | fV  qW d S )N)r{   )r   r(   r   r   r   r     s    zNamespace._get_starc             C   sL   || j kr| j | }n&| jr*t| j|}ntd| j|f t| || |S )Nz!Namespace '%s' has no member '%s')r{   rs   rJ   rt   ry   setattr)r   r(   valr   r   r   rK     s    
zNamespace.__getattr__)NNTN)r@   rA   rB   rC   r   r{   rr   r   rz   filenamer   r   r   Zmemoized_propertyr~   r   r   r   rD   r   r   r   r   rK   r   r   r   r   rv   j  s*      
		 		rv   c               @   sN   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 k	r*dd |D | _|d k	rNt|||| _| jjj| _n"|d k	rh|| _|jj| _nt	d|rt
|| j| d\}	}
d S )Nc             S   s   i | ]}||j qS r   )r@   )rw   r7   r   r   r   rx   ?  s    z.TemplateNamespace.__init__.<locals>.<dictcomp>z 'template' argument is required.)self_ns)ry   rz   rs   r{   r   r   rr   Z_template_urir   	TypeError_populate_self_namespace)r   ry   rz   r   r   r{   rs   r|   r}   Zlclcallable
lclcontextr   r   r   r   0  s    zTemplateNamespace.__init__c             C   s   | 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   rr   )r   r   r   r   rr   O  s    	zTemplateNamespace.modulec             C   s   | j jS )zhThe path of the filesystem file used for this
        :class:`.Namespace`'s module or template.
        )r   r   )r   r   r   r   r   Z  s    zTemplateNamespace.filenamec             C   s   | 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   r   r   r   r   a  s    	zTemplateNamespace.uric             #   sX    j r&x j D ]}| j | fV  qW  fdd}x  jjjD ]}|||fV  q>W d S )Nc                s    j | }t| jS )N)r   _get_def_callabler   r   rz   )r(   	callable_)r   r   r   r2   q  s    z(TemplateNamespace._get_star.<locals>.get)r{   r   rr   Z_exports)r   r(   r2   r   r   )r   r   r   l  s    zTemplateNamespace._get_starc             C   st   || j kr| j | }nN| j|r>| j|}t|| j}n&| jrRt| j|}nt	d| j
|f t| || |S )Nz!Namespace '%s' has no member '%s')r{   r   Zhas_defr   r   r   rz   rs   rJ   rt   ry   r   )r   r(   r   r   r   r   r   rK   x  s    
zTemplateNamespace.__getattr__)NNNNTN)r@   rA   rB   rC   r   rD   rr   r   r   r   rK   r   r   r   r   r   ,  s        
r   c               @   s6   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   sb   || _ || _|| _|d k	r*dd |D | _t|}x$|ddd  D ]}	t||	}qFW || _d S )Nc             S   s   i | ]}||j qS r   )r@   )rw   r7   r   r   r   rx     s    z,ModuleNamespace.__init__.<locals>.<dictcomp>.rb   )ry   rz   rs   r{   
__import__splitrJ   rr   )
r   ry   rz   rr   r{   rs   r|   r}   modtokenr   r   r   r     s    
zModuleNamespace.__init__c             C   s   | j jS )zhThe path of the filesystem file used for this
        :class:`.Namespace`'s module or template.
        )rr   __file__)r   r   r   r   r     s    zModuleNamespace.filenamec             c   sr   | j r&x| j D ]}|| j | fV  qW xFt| jD ]8}|d dkr2t| j|}t|r2|t|| jfV  q2W d S )Nr   _)r{   dirrr   rJ   callabler   r   rz   )r   r(   r   r   r   r   r     s    zModuleNamespace._get_starc             C   st   || j kr| j | }nNt| j|r>t| j|}t|| j}n&| jrRt| j|}ntd| j	|f t
| || |S )Nz!Namespace '%s' has no member '%s')r{   rq   rr   rJ   r   r   rz   rs   rt   ry   r   )r   r(   r   r   r   r   r   rK     s    
zModuleNamespace.__getattr__)NNTN)	r@   rA   rB   rC   r   rD   r   r   rK   r   r   r   r   r     s      

r   c                s    fdd}|S )zApply a caller_stack compatibility decorator to a plain
    Python function.

    See the example in :ref:`namespaces_python_modules`.

    c                s,   | j   z | f||S | j   X d S )N)r   rM   rN   )rz   argsr   )funcr   r   wrap_stackframe  s    
z(supports_caller.<locals>.wrap_stackframer   )r   r   r   )r   r   supports_caller  s    r   c             O   s<   t |std|   z||| W d|  }X | S )zExecute the given template def, capturing the output into
    a buffer.

    See the example in :ref:`namespaces_python_modules`.

    z[capture() function expects a callable as its argument (i.e. capture(func, *args, **kwargs))N)r   r   r]   r0   r1   getvalue)rz   r   r   r   r,   r   r   r   r     s    
r   c                s    fdd}|S )Nc                s    fdd}|S )Nc                sL    fdd}yj dd  |_ W n tk
r6   Y nX | f||S )Nc                 s    f| |S )Nr   )r   kw)rz   	render_fnr   r   y  s    zB_decorate_toplevel.<locals>.decorate_render.<locals>.go.<locals>.y   )r@   r   )rz   r   r   r   )fnr   )rz   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                 s    f| |S )Nr   )r   r   )rz   decr   r   r      s    z5_decorate_inline.<locals>.decorate_render.<locals>.gor   )r   r   )rz   r   )r   r   r     s    z)_decorate_inline.<locals>.decorate_renderr   )rz   r   r   r   )rz   r   r   _decorate_inline  s    r   c             K   s   t | ||}t|  |\}}t|| jf|}|jrry||f| W q~ tk
rn   ||t }|sj Y q~X n||f| dS )zPlocate the template from the given uri and include it in
    the current output.N)	r   r   r?   _kwargs_for_includer	   Zinclude_error_handler	Exceptionr   exception_as)rz   r   r}   r   r   r   ctxresultr   r   r   r     s    
r   c       
      C   s   |dkrdS t | ||}| d }|}x|jdk	r8|j}q&W | d|i}td|j ||dd|_|j | jd< |jd< t|jd	d}|dk	r|||}|r|S t|jd
d}	|	dk	r|	|  |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   r=   zself:%sF)r   r|   r<   local_mako_inheritZ_mako_generate_namespaces)	r   rs   r;   r   r   r	   rJ   rr   r   )
rz   r   r}   r   r   Zihr   r   retZgen_nsr   r   r   _inherit_from  s.    


r   c          
   C   sv   | j j}|d kr"td| j j |||}y
||S  tjk
rp } zttt	
 |W d d }~X Y nX d S )Nz.Template '%s' has no TemplateLookup associated)r   r   r   ZTemplateLookupExceptionr   Z
adjust_urir   ZTopLevelLookupExceptionstrr   r   )rz   r   Z
relativetor   er   r   r   r   <  s    
r   c             C   s^   |d krt d|j | |dd}| | jd< | jd< t|jdrT|j|| }|rT|S |j| fS )Nzself:%sF)r   r|   r   r   r   )r   r   r	   rq   rr   r   r   )rz   r   r   r   r   r   r   r   L  s    r   Fc             C   sb   |rt  }nt j| j| jd}t|f|}||_||  t| ||f|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_callabler1   r   )r   r   r   r   Z
as_unicoder,   rz   r   r   r   _render\  s    

r   c             C   sn   t | }|d r|S |d dd |dd D  }i }x0|D ](}|dkr>||kr>||kr>|| ||< q>W |S )Nrj   r   c             S   s   g | ]}|d k	r|qS )Nr   )rw   r   r   r   r   
<listcomp>{  s    z(_kwargs_for_callable.<locals>.<listcomp>rb      rz   )r   inspect_getargspec)r   r   argspec	namedargsr   argr   r   r   r   t  s    

r   c             K   s^   t | }|d dd |dd D  }x0|D ](}|dkr.||kr.||kr.|| ||< q.W |S )Nr   c             S   s   g | ]}|d k	r|qS )Nr   )rw   r   r   r   r   r     s    z'_kwargs_for_include.<locals>.<listcomp>rb   r   rz   )r   r   )r   r   r   r   r   r   r   r   r   r     s    

r   c             O   s\   dd l m} t| |js8t|| \}}t||||d n t|| j\}}t||||d d S )Nr   )r   r   )Zmako.templater   
isinstanceZDefTemplater   _exec_templater<   )tmplr   rz   r   r   r   inheritr   r   r   r   r     s    r   c             C   s   |j }|dk	rx|js|jrxy| |f|| W q tk
rR   t||t  Y q   t d }t||| Y qX n| |f|| 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   Zformat_exceptionserror_handlerr   _render_errorr   r   sysexc_info)r   rz   r   r   r   r   r   r   r   r     s    r   c             C   s   | j r>|  ||}|st \}}}|r8|r8||q|nXt }|jrbt g|j	d d < nt|j
|jg|j	d d < || |j||d d S )N)error)r   r   r   with_tracebackr   Zhtml_error_templater   r   r*   r   r   r   r   Zrender_context)r   rz   r   r   tpvaluetbZerror_templater   r   r   r     s    
r   )N)F)NN)"rC   r&   r   r   makor   r   r   r   r$   r   rO   	UNDEFINEDZSTOP_RENDERINGrS   r[   ro   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sB    -(A C]: 

	
