a
    ì´«jþ  ã                   @  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  s@   t  d¡} t d¡}i }| dur*| j|d< |dur<|j|d< |S )z‡Default template context processor.  Replaces the ``request`` and ``g``
    proxies with their concrete objects for faster access.
    NÚgr   )r   Úgetr	   r   r   )ZappctxZreqctxÚrv© r   úO/var/www/html/laksyashrimp/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 Jinja 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    :   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debughelpersr/   r   )	r!   r)   r*   ZattemptsZtrvÚsrcobjr   r   r/   r   r   r   r,   D   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'   )r0   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   r0   f   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   r3   ÚupdateÚlist_templatesr4   ÚaddÚlist)r!   Úresultr   r5   r*   r   r   r   r8   p   s    z%DispatchingJinjaLoader.list_templatesN)
r"   r#   r$   r%   r    r.   r,   r-   r0   r8   r   r   r   r   r&   5   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    

ÿ

ÿrC   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_templaterC   ©rD   r<   r   r*   r   r   r   Úrender_template‹   s    
rI   )Ú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
   rE   rF   Úfrom_stringrC   ©rJ   r<   r   r*   r   r   r   Úrender_template_stringš   s    rM   út.Iterator[str]c                   sJ   ˆ   ˆ¡ tjˆ ˆ jˆˆd� ddœ‡ ‡‡fdd„}|ƒ }trFt|ƒ}|S )Nr>   rN   r   c                   3  s(   ˆ  ˆ¡E d H  tjˆ ˆ jˆˆd� d S r=   )Úgenerater   r@   rA   r   ©r   r<   r*   r   r   rO   ®   s    
ÿz_stream.<locals>.generate)r?   r   r@   rA   r   r   )r   r*   r<   rO   r   r   rP   r   Ú_stream¦   s    

ÿrQ   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
   rE   rF   rG   rQ   rH   r   r   r   Ústream_template½   s    rR   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
   rE   rF   rK   rQ   rL   r   r   r   Ústream_template_stringÐ   s    
rS   )#Ú
__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&   rC   rI   rM   rQ   rR   rS   r   r   r   r   Ú<module>   s2   J