o
    àý°jþ  ã                   @  s,  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raddlmZ ddlmZ ddlmZ d1dd„ZG dd„ deƒZG dd„ deƒZd2d d!„Zd3d%d&„Zd4d(d)„Zd5d+d,„Z d6d-d.„Z!d7d/d0„Z"dS )8é    )ÚannotationsN)Ú
BaseLoader)ÚEnvironment)ÚTemplate)ÚTemplateNotFoundé   )Ú_cv_app)Ú_cv_request)Úcurrent_app)Úrequest)Ústream_with_context)Úbefore_render_template)Útemplate_rendered)ÚFlask)ÚApp)ÚScaffoldÚreturnúdict[str, t.Any]c                  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   )ÚappctxÚreqctxÚrv© r   úƒ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/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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.
    Úappr   Úoptionsút.Anyr   ÚNonec                 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)r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r   r   r   r   r   (   s    r   c                   @  sL   e Zd ZdZddd„Zddd„Zddd„Zddd„Zddd„Z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__Úenvironmentr"   ÚtemplateÚstrú3tuple[str, str | None, t.Callable[[], bool] | None]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 ]&\}}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_loadersr3   r   ÚappendÚdebughelpersr4   r   )	r$   r+   r,   ÚattemptsÚtrvÚsrcobjr    r   r4   r   r   r   r1   D   s"   €ÿz,DispatchingJinjaLoader._get_source_explainedc              	   C  s@   |   |¡D ]\}}z	| ||¡W   S  ty   Y qw t|ƒ‚r*   )r5   r3   r   )r$   r+   r,   Ú_srcobjr    r   r   r   r2   \   s   ÿz'DispatchingJinjaLoader._get_source_fastú't.Iterator[tuple[Scaffold, BaseLoader]]c                 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   r5   f   s   €
€ýz$DispatchingJinjaLoader._iter_loadersú	list[str]c                 C  sb   t ƒ }| jj}|d ur| | ¡ ¡ | j ¡ D ]}|j}|d ur,| ¡ D ]}| |¡ q$qt|ƒS r*   )Úsetr   r=   ÚupdateÚlist_templatesr>   ÚaddÚlist)r$   Úresultr    r?   r,   r   r   r   rC   p   s   €z%DispatchingJinjaLoader.list_templatesN)r   r   r   r   )r+   r"   r,   r-   r   r.   )r,   r-   r   r<   )r   r@   )
r%   r&   r'   r(   r#   r3   r1   r2   r5   rC   r   r   r   r   r)   5   s    






r)   r   r   r,   r   Úcontextr-   c                 C  s@   |   |¡ tj| | j||d� | |¡}tj| | j||d� |S ©N©Ú_async_wrapperr,   rG   )Úupdate_template_contextr   ÚsendÚensure_syncÚrenderr   )r   r,   rG   r   r   r   r   Ú_render   s   

ÿ

ÿrO   Útemplate_name_or_listú%str | Template | list[str | Template]r   c                 K  ó    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_templaterO   ©rP   rG   r   r,   r   r   r   Úrender_template‹   ó   
rW   Úsourcec                 K  rR   )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
   rS   rT   Úfrom_stringrO   ©rY   rG   r   r,   r   r   r   Úrender_template_stringš   s   r\   út.Iterator[str]c                   sF   ˆ   ˆ¡ tjˆ ˆ jˆˆd� d‡ ‡‡fdd„}|ƒ }tr!t|ƒ}|S )NrI   r   r]   c                   3  s*   � ˆ  ˆ¡E d H  tjˆ ˆ jˆˆd� d S rH   )Úgenerater   rL   rM   r   ©r   rG   r,   r   r   r^   ®   s
   €

ÿz_stream.<locals>.generate)r   r]   )rK   r   rL   rM   r   r   )r   r,   rG   r^   r   r   r_   r   Ú_stream¦   s   

ÿr`   c                 K  rR   )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
   rS   rT   rU   r`   rV   r   r   r   Ústream_template½   s   ra   c                 K  rR   )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
   rS   rT   rZ   r`   r[   r   r   r   Ústream_template_stringÐ   rX   rb   )r   r   )r   r   r,   r   rG   r   r   r-   )rP   rQ   rG   r   r   r-   )rY   r-   rG   r   r   r-   )r   r   r,   r   rG   r   r   r]   )rP   rQ   rG   r   r   r]   )rY   r-   rG   r   r   r]   )#Ú
__future__r   ÚtypingÚtÚjinja2r   r   r"   r   r   Úglobalsr   r	   r
   r   Úhelpersr   Úsignalsr   r   ÚTYPE_CHECKINGr   r   Ú
sansio.appr   Úsansio.scaffoldr   r   r)   rO   rW   r\   r`   ra   rb   r   r   r   r   Ú<module>   s4    

J



