a
    Ì~´gq  ã                   @  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rÂd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   úU/var/www/html/emsaiapi.evdpl.com/venv/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   zÌWorks 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)Ú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 )NÚ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_loadersr1   r   ÚappendÚdebughelpersr2   r   )	r#   r+   r,   ZattemptsZtrvÚsrcobjr   r   r2   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)   )r3   r1   r   )r#   r+   r,   Z_srcobjr   r   r   r   r0   [   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   r3   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   r7   ÚupdateÚlist_templatesr8   ÚaddÚlist)r#   Úresultr   r9   r,   r   r   r   r<   o   s    z%DispatchingJinjaLoader.list_templatesN)
r$   r%   r&   r'   r"   r1   r/   r0   r3   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©Ú_async_wrapperr,   r@   )Úupdate_template_contextr   ÚsendÚensure_syncZrenderr   )r   r,   r@   r   r   r   r   Ú_render~   s    

ÿ

ÿrG   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_templaterG   ©rH   r@   r   r,   r   r   r   Úrender_templateŠ   s    
rM   )Úsourcer@   r   c                 K  s    t  ¡ }|j | ¡}t|||ƒS )zÓRender 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
   rI   rJ   Úfrom_stringrG   ©rN   r@   r   r,   r   r   r   Úrender_template_string™   s    rQ   út.Iterator[str]c                   sJ   ˆ   ˆ¡ tjˆ ˆ jˆˆd ddœ‡ ‡‡fdd„}|ƒ }trFt|ƒ}|S )NrB   rR   r   c                   3  s(   ˆ  ˆ¡E d H  tjˆ ˆ jˆˆd d S rA   )Úgenerater   rE   rF   r   ©r   r@   r,   r   r   rS   ­   s    
ÿz_stream.<locals>.generate)rD   r   rE   rF   r   r   )r   r,   r@   rS   r   r   rT   r   Ú_stream¥   s    

ÿrU   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
   rI   rJ   rK   rU   rL   r   r   r   Ústream_template¼   s    rV   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
   rI   rJ   rO   rU   rP   r   r   r   Ústream_template_stringÏ   s    
rW   )#Ú
__future__r   ÚtypingÚtZjinja2r   r   r!   r   r   Úglobalsr   r	   r
   r   Úhelpersr   Úsignalsr   r   ÚTYPE_CHECKINGr   r   Ú
sansio.appr   Úsansio.scaffoldr   r   r(   rG   rM   rQ   rU   rV   rW   r   r   r   r   Ú<module>   s2   J