a
    0hq                     @  sd  d dl mZ 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rddlmZ ddlmZ ddlmZ ddddZG dd deZG dd deZdddddddZd d!dd"d#d$Zdd!dd%d&d'Zdddd(dd)d*Z d d!d(d"d+d,Z!dd!d(d%d-d.Z"dS )/    )annotationsN)
BaseLoader)Environment)Template)TemplateNotFound   )_cv_app)_cv_request)current_app)request)stream_with_context)before_render_template)template_rendered)Flask)App)Scaffoldzdict[str, t.Any]returnc                  C  sJ   t d} td}i }| dur*| j|d< |durF|j|d< |j|d< |S )zSDefault template context processor.  Injects `request`,
    `session` and `g`.
    Ngr   session)r   getr	   r   r   r   )ZappctxZreqctxrv r   >/var/www/auris/lib/python3.9/site-packages/flask/templating.py_default_template_ctx_processor   s    




r   c                   @  s"   e Zd ZdZdddd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.
    r   t.AnyNone)appoptionsr   c                 K  s0   d|vr|  |d< tj| fi | || _d S )Nloader)Zcreate_global_jinja_loaderBaseEnvironment__init__r   )selfr   r   r   r   r   r!   -   s    zEnvironment.__init__N)__name__
__module____qualname____doc__r!   r   r   r   r   r   '   s   r   c                   @  st   e Zd ZdZdddddZddd	d
ddZddd	d
ddZddd	d
ddZdddddZddddZ	dS )DispatchingJinjaLoaderz\A loader that looks for templates in the application and all
    the blueprint folders.
    r   r   )r   r   c                 C  s
   || _ d S N)r   )r"   r   r   r   r   r!   9   s    zDispatchingJinjaLoader.__init__r    strz3tuple[str, str | None, t.Callable[[], bool] | None])environmenttemplater   c                 C  s$   | j jd r| ||S | ||S )NZEXPLAIN_TEMPLATE_LOADING)r   config_get_source_explained_get_source_fast)r"   r*   r+   r   r   r   
get_source<   s    z!DispatchingJinjaLoader.get_sourcec           	   	   C  s   g }d }|  |D ]L\}}z|||}|d u r4|}W n tyL   d }Y n0 ||||f qddlm} || j|| |d ur|S t|d S )Nr   )!explain_template_loading_attempts)_iter_loadersr/   r   appendZdebughelpersr0   r   )	r"   r*   r+   attemptsZtrvsrcobjr   r   r0   r   r   r   r-   C   s    
z,DispatchingJinjaLoader._get_source_explainedc              	   C  sJ   |  |D ]2\}}z|||W   S  ty:   Y q
Y q
0 q
t|d S r(   )r1   r/   r   )r"   r*   r+   Z_srcobjr   r   r   r   r.   [   s    z'DispatchingJinjaLoader._get_source_fastz't.Iterator[tuple[Scaffold, BaseLoader]])r+   r   c                 c  sH   | 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   e   s    z$DispatchingJinjaLoader._iter_loadersz	list[str]r   c                 C  sb   t  }| jj}|d ur$||  | j D ]*}|j}|d ur.| D ]}|| qHq.t|S r(   )setr   r5   updatelist_templatesr6   addlist)r"   resultr   r7   r+   r   r   r   r:   o   s    z%DispatchingJinjaLoader.list_templatesN)
r#   r$   r%   r&   r!   r/   r-   r.   r1   r:   r   r   r   r   r'   4   s   

r'   r   r   r)   )r   r+   contextr   c                 C  s@   |  | tj| | j||d ||}tj| | j||d |S NZ_async_wrapperr+   r>   )update_template_contextr   sendensure_syncrenderr   )r   r+   r>   r   r   r   r   _render~   s    



rE   z%str | Template | list[str | Template]r   )template_name_or_listr>   r   c                 K  s    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_templaterE   rF   r>   r   r+   r   r   r   render_template   s    
rK   )sourcer>   r   c                 K  s    t  }|j| }t|||S )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
   rG   rH   from_stringrE   rL   r>   r   r+   r   r   r   render_template_string   s    rO   t.Iterator[str]c                   sJ      tj  jd dd fdd}| }trFt|}|S )Nr@   rP   r   c                   3  s(    E d H  tj  jd d S r?   )generater   rB   rC   r   r   r>   r+   r   r   rQ      s    
z_stream.<locals>.generate)rA   r   rB   rC   r   r   )r   r+   r>   rQ   r   r   rR   r   _stream   s    

rS   c                 K  s    t  }|j| }t|||S )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
   rG   rH   rI   rS   rJ   r   r   r   stream_template   s    rT   c                 K  s    t  }|j| }t|||S )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
   rG   rH   rM   rS   rN   r   r   r   stream_template_string   s    
rU   )#
__future__r   typingtZjinja2r   r   r    r   r   globalsr   r	   r
   r   Zhelpersr   Zsignalsr   r   TYPE_CHECKINGr   r   Z
sansio.appr   Zsansio.scaffoldr   r   r'   rE   rK   rO   rS   rT   rU   r   r   r   r   <module>   s2   J