o
    iK                     @   s   d 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 ZG dd deZG dd deZdd Zdd Zdd ZdS )z
    flask.templating
    ~~~~~~~~~~~~~~~~

    Implements the bridge to Jinja2.

    :copyright: 2010 Pallets
    :license: BSD-3-Clause
    )
BaseLoader)Environment)TemplateNotFound   )_app_ctx_stack)_request_ctx_stack)before_render_template)template_renderedc                  C   sB   t j} tj}i }|dur|j|d< | dur| j|d< | j|d< |S )zSDefault template context processor.  Injects `request`,
    `session` and `g`.
    Ngrequestsession)r   topr   r
   r   r   )reqctxappctxrv r   K/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/flask/templating.py_default_template_ctx_processor   s   


r   c                   @   s   e Zd ZdZ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.
    c                 K   s0   d|vr
|  |d< tj| fi | || _d S )Nloader)create_global_jinja_loaderBaseEnvironment__init__app)selfr   optionsr   r   r   r   *   s   
zEnvironment.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r   $   s    r   c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )DispatchingJinjaLoaderz\A loader that looks for templates in the application and all
    the blueprint folders.
    c                 C   s
   || _ d S N)r   )r   r   r   r   r   r   6   s   
zDispatchingJinjaLoader.__init__c                 C   s$   | j jd r| ||S | ||S )NEXPLAIN_TEMPLATE_LOADING)r   config_get_source_explained_get_source_fast)r   environmenttemplater   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debughelpersr(   r   )	r   r%   r&   attemptstrvsrcobjr   r   r(   r   r   r   r#   >   s"   z,DispatchingJinjaLoader._get_source_explainedc              	   C   s@   |  |D ]\}}z	|||W   S  ty   Y qw t|r    )r)   r'   r   )r   r%   r&   _srcobjr   r   r   r   r$   S   s   z'DispatchingJinjaLoader._get_source_fastc                 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   r)   [   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   r0   updatelist_templatesr1   addlist)r   resultr   r2   r&   r   r   r   r5   e   s   z%DispatchingJinjaLoader.list_templatesN)
r   r   r   r   r   r'   r#   r$   r)   r5   r   r   r   r   r   1   s    
r   c                 C   s.   t j|| |d | |}tj|| |d |S )z)Renders the template and fires the signal)r&   context)r   sendrenderr	   )r&   r9   r   r   r   r   r   _rendert   s   
r<   c                 K   *   t j}|j| t|jj| ||jS )a  Renders a template from the template folder with the given
    context.

    :param template_name_or_list: the name of the template to be
                                  rendered, or an iterable with template names
                                  the first one existing will be rendered
    :param context: the variables that should be available in the
                    context of the template.
    )r   r   r   update_template_contextr<   	jinja_envget_or_select_template)template_name_or_listr9   ctxr   r   r   render_template}   s   
rC   c                 K   r=   )aF  Renders a template from the given template source string
    with the given context. Template variables will be autoescaped.

    :param source: the source code of the template to be
                   rendered
    :param context: the variables that should be available in the
                    context of the template.
    )r   r   r   r>   r<   r?   from_string)sourcer9   rB   r   r   r   render_template_string   s   	rF   N)r   jinja2r   r   r   r   globalsr   r   signalsr   r	   r   r   r<   rC   rF   r   r   r   r   <module>   s   	C	