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   ú^/var/www/html/cobodadashboardai.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)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+   Z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   r4   ÚupdateÚlist_templatesr5   ÚaddÚlist)r"   Úresultr   r6   r+   r   r   r   r9   o   s    z%DispatchingJinjaLoader.list_templatesN)
r#   r$   r%   r&   r!   r/   r-   r.   r1   r9   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    

ÿ

ÿrD   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_templaterD   ©rE   r=   r   r+   r   r   r   Úrender_templateŠ   s    
rJ   )Ú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
   rF   rG   Úfrom_stringrD   ©rK   r=   r   r+   r   r   r   Úrender_template_string™   s    rN   út.Iterator[str]c                   sJ   ˆ   ˆ¡ tjˆ ˆ jˆˆd ddœ‡ ‡‡fdd„}|ƒ }trFt|ƒ}|S )Nr?   rO   r   c                   3  s(   ˆ  ˆ¡E d H  tjˆ ˆ jˆˆd d S r>   )Úgenerater   rA   rB   r   ©r   r=   r+   r   r   rP   ­   s    
ÿz_stream.<locals>.generate)r@   r   rA   rB   r   r   )r   r+   r=   rP   r   r   rQ   r   Ú_stream¥   s    

ÿrR   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
   rF   rG   rH   rR   rI   r   r   r   Ústream_template¼   s    rS   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
   rF   rG   rL   rR   rM   r   r   r   Ústream_template_stringÏ   s    
rT   )#Ú
__future__r   ÚtypingÚtZjinja2r   r   r    r   r   Úglobalsr   r	   r
   r   Úhelpersr   Zsignalsr   r   ÚTYPE_CHECKINGr   r   Z
sansio.appr   Zsansio.scaffoldr   r   r'   rD   rJ   rN   rR   rS   rT   r   r   r   r   Ú<module>   s2   J