o
    d                  	   @   s  d dl Zd dlmZ d dlmZ d dlmZ d dlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ejrUddlmZ ddlmZ dejeejf fddZG dd deZG dd deZdddedejeejf defddZdejeeejejeef  f dejdefddZd edejdefd!d"Z dddedejeejf dej!e fd#d$Z"dejeeejejeef  f dejdej!e fd%d&Z#d edejdej!e fd'd(Z$dS ))    N)
BaseLoader)Environment)Template)TemplateNotFound   )_cv_app)_cv_request)current_app)request)stream_with_context)before_render_template)template_rendered)Flask)Scaffoldreturnc                  C   sJ   t d} td}i }| dur| j|d< |dur#|j|d< |j|d< |S )zSDefault template context processor.  Injects `request`,
    `session` and `g`.
    Ngr
   session)r   getr   r   r
   r   )appctxreqctxrv r   U/var/www/html/visualizacion-main/env/lib/python3.10/site-packages/flask/templating.py_default_template_ctx_processor   s   




r   c                   @   s(   e Zd ZdZdddejddfddZdS )	r   zWorks like a regular Jinja2 environment but has some additional
    knowledge of how Flask's blueprint works so that it can prepend the
    name of the blueprint to referenced templates if necessary.
    appr   optionsr   Nc                 K   s0   d|vr
|  |d< tj| fi | || _d S )Nloader)create_global_jinja_loaderBaseEnvironment__init__r   )selfr   r   r   r   r   r   *   s   
zEnvironment.__init__)__name__
__module____qualname____doc__tAnyr   r   r   r   r   r   $   s    r   c                
   @   s   e Zd ZdZdddZded	edejeej	e ej	ej
 f fd
dZded	edejeej	e ej	ej
 f fddZded	edejeej	e ej	ej
 f fddZd	edejejdef ddf fddZdeje fddZdS )DispatchingJinjaLoaderz\A loader that looks for templates in the application and all
    the blueprint folders.
    r   r   r   Nc                 C   s
   || _ d S N)r   )r    r   r   r   r   r   6   s   
zDispatchingJinjaLoader.__init__environmenttemplatec                 C   s$   | j jd r| ||S | ||S )NEXPLAIN_TEMPLATE_LOADING)r   config_get_source_explained_get_source_fast)r    r)   r*   r   r   r   
get_source9   s   z!DispatchingJinjaLoader.get_sourcec           	   	   C   s   g }d }|  |D ]&\}}z|||}|d u r|}W n ty&   d }Y nw ||||f q	ddlm} || j|| |d urC|S t|)Nr   )!explain_template_loading_attempts)_iter_loadersr/   r   appenddebughelpersr0   r   )	r    r)   r*   attemptstrvsrcobjr   r   r0   r   r   r   r-   @   s$   z,DispatchingJinjaLoader._get_source_explainedc              	   C   s@   |  |D ]\}}z	|||W   S  ty   Y qw t|r(   )r1   r/   r   )r    r)   r*   _srcobjr   r   r   r   r.   Z   s   z'DispatchingJinjaLoader._get_source_fastr   c                 c   sJ    | j j}|d ur| j |fV  | j  D ]}|j}|d ur"||fV  qd S r(   )r   jinja_loaderiter_blueprints)r    r*   r   	blueprintr   r   r   r1   d   s   
z$DispatchingJinjaLoader._iter_loadersc                 C   sb   t  }| jj}|d ur||  | j D ]}|j}|d ur,| D ]}|| q$qt|S r(   )setr   r8   updatelist_templatesr9   addlist)r    resultr   r:   r*   r   r   r   r=   p   s   z%DispatchingJinjaLoader.list_templates)r   r   r   N)r!   r"   r#   r$   r   r   strr%   TupleOptionalCallabler/   r-   r.   	Generatorr   r1   Listr=   r   r   r   r   r'   1   s<    





r'   r   r   r*   contextc                 C   s8   |  | tj| ||d ||}tj| ||d |S Nr*   rG   )update_template_contextr   sendrenderr   )r   r*   rG   r   r   r   r   _render   s
   

rM   template_name_or_listc                 K       t  }|j| }t|||S )a  Render a template by name with the given context.

    :param template_name_or_list: The name of the template to render. If
        a list is given, the first name to exist will be rendered.
    :param context: The variables to make available in the template.
    )r	   _get_current_object	jinja_envget_or_select_templaterM   rN   rG   r   r*   r   r   r   render_template      
rT   sourcec                 K   rO   )zRender a template from the given source string with the given
    context.

    :param source: The source code of the template to render.
    :param context: The variables to make available in the template.
    )r	   rP   rQ   from_stringrM   rV   rG   r   r*   r   r   r   render_template_string   s   rY   c                    sL      tj d dtjt f fdd}| }tr$t|}|S )NrI   r   c                   3   s&     E d H  tj d d S rH   )generater   rK   r   r   rG   r*   r   r   rZ      s   z_stream.<locals>.generate)rJ   r   rK   r%   IteratorrA   r
   r   )r   r*   rG   rZ   r   r   r[   r   _stream   s   
r]   c                 K   rO   )a  Render a template by name with the given context as a stream.
    This returns an iterator of strings, which can be used as a
    streaming response from a view.

    :param template_name_or_list: The name of the template to render. If
        a list is given, the first name to exist will be rendered.
    :param context: The variables to make available in the template.

    .. versionadded:: 2.2
    )r	   rP   rQ   rR   r]   rS   r   r   r   stream_template   s   r^   c                 K   rO   )aZ  Render a template from the given source string with the given
    context as a stream. This returns an iterator of strings, which can
    be used as a streaming response from a view.

    :param source: The source code of the template to render.
    :param context: The variables to make available in the template.

    .. versionadded:: 2.2
    )r	   rP   rQ   rW   r]   rX   r   r   r   stream_template_string   rU   r_   )%typingr%   jinja2r   r   r   r   r   globalsr   r   r	   r
   helpersr   signalsr   r   TYPE_CHECKINGr   r   scaffoldr   DictrA   r&   r   r'   rM   UnionrF   rT   rY   r\   r]   r^   r_   r   r   r   r   <module>   sX    &N


"