o
    ]ÈOcû  ã                	   @   sÞ  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rUddlmZ ddlmZ dejeejf fdd„ZG dd„ deƒZG dd„ deƒZdddedejeejf defdd„Zdejeeejejeef  f dejdefdd„Zd edejdefd!d"„Z dddedejeejf dej!e fd#d$„Z"dejeeejejeef  f dejdej!e fd%d&„Z#d edejdej!e fd'd(„Z$dS ))é    N)Ú
BaseLoader)ÚEnvironment)ÚTemplate)ÚTemplateNotFoundé   )Ú_cv_app)Ú_cv_request)Úcurrent_app)Úrequest)Ústream_with_context)Úbefore_render_template)Útemplate_rendered)ÚFlask)ÚScaffoldÚreturnc                  C   sJ   t  d¡} t d¡}i }| dur| j|d< |dur#|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   ú2D:\Flask\env\Lib\site-packages\flask/templating.pyÚ_default_template_ctx_processor   s   




r   c                   @   s(   e Zd ZdZdddejddf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.
    Úappr   Úoptionsr   Nc                 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__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚtÚAnyr   r   r   r   r   r   $   s    r   c                
   @   sæ   e Zd ZdZddd„Zded	edejeej	e ej	ej
 f fd
d„Zded	edejeej	e ej	ej
 f fdd„Zded	edejeej	e ej	ej
 f fdd„Zd	edejejdef ddf fdd„Zdeje fdd„ZdS )ÚDispatchingJinjaLoaderz\A loader that looks for templates in the application and all
    the blueprint folders.
    r   r   r   Nc                 C   s
   || _ d S ©N)r   )r   r   r   r   r   r   6   s   
zDispatchingJinjaLoader.__init__ÚenvironmentÚtemplatec                 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_source9   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_loadersr+   r   ÚappendZdebughelpersr,   r   )	r   r&   r'   ZattemptsZtrvÚsrcobjr   r   r,   r   r   r   r)   @   s$   þ€ÿz,DispatchingJinjaLoader._get_source_explainedc              	   C   s@   |   |¡D ]\}}z	| ||¡W   S  ty   Y qw t|ƒ‚r%   )r-   r+   r   )r   r&   r'   Z_srcobjr   r   r   r   r*   Z   s   ÿz'DispatchingJinjaLoader._get_source_fastr   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   r-   d   s   €
€ýz$DispatchingJinjaLoader._iter_loadersc                 C   sb   t ƒ }| jj}|d ur| | ¡ ¡ | j ¡ D ]}|j}|d ur,| ¡ D ]}| |¡ q$qt|ƒS r%   )Úsetr   r0   ÚupdateÚlist_templatesr1   ÚaddÚlist)r   Úresultr   r2   r'   r   r   r   r5   p   s   €z%DispatchingJinjaLoader.list_templates)r   r   r   N)r   r   r    r!   r   r   Ústrr"   ÚTupleÚOptionalÚCallabler+   r)   r*   Ú	Generatorr   r-   ÚListr5   r   r   r   r   r$   1   s<    
ÿÿ
þÿÿ
þÿÿ
þ
ÿ
þr$   r   r   r'   Úcontextc                 C   s8   |   |¡ tj| ||d | |¡}tj| ||d |S ©N©r'   r?   )Úupdate_template_contextr   ÚsendÚrenderr   )r   r'   r?   r   r   r   r   Ú_render   s
   

rE   Útemplate_name_or_listc                 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_templaterE   ©rF   r?   r   r'   r   r   r   Úrender_template‡   ó   
rL   Úsourcec                 K   rG   )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	   rH   rI   Úfrom_stringrE   ©rN   r?   r   r'   r   r   r   Úrender_template_string–   s   rQ   c                    sL   ˆ   ˆ¡ tjˆ ˆˆd dtjt f‡ ‡‡fdd„}|ƒ }tr$t|ƒ}|S )NrA   r   c                   3   s&    ˆ  ˆ¡E d H  tjˆ ˆˆd d S r@   )Úgenerater   rC   r   ©r   r?   r'   r   r   rR   ¨   s   €z_stream.<locals>.generate)rB   r   rC   r"   ÚIteratorr9   r
   r   )r   r'   r?   rR   r   r   rS   r   Ú_stream¢   s   
rU   c                 K   rG   )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	   rH   rI   rJ   rU   rK   r   r   r   Ústream_templateµ   s   rV   c                 K   rG   )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	   rH   rI   rO   rU   rP   r   r   r   Ústream_template_stringÈ   rM   rW   )%Útypingr"   Zjinja2r   r   r   r   r   Úglobalsr   r   r	   r
   Úhelpersr   Zsignalsr   r   ÚTYPE_CHECKINGr   r   Zscaffoldr   ÚDictr9   r#   r   r$   rE   ÚUnionr>   rL   rQ   rT   rU   rV   rW   r   r   r   r   Ú<module>   sX    &Nÿþ
ýÿÿÿ
þÿþ
ý"