o
    þ6÷dO  ã                   @  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r[ddlmZ ddlmZ d0dd„ZG dd„ deƒZG dd„ deƒZd1dd „Zd2d$d%„Zd3d'd(„Zd4d*d+„Zd5d,d-„Zd6d.d/„Z dS )7é    )ÚannotationsN)Ú
BaseLoader)ÚEnvironment)ÚTemplate)ÚTemplateNotFoundé   )Ú_cv_app)Ú_cv_request)Úcurrent_app)Úrequest)Ústream_with_context)Úbefore_render_template)Útemplate_rendered)ÚFlask)ÚScaffoldÚreturnúdict[str, t.Any]c                  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   úgC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\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 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   Úoptionsút.Anyr   ÚNonec                 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)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    8   s   
zDispatchingJinjaLoader.__init__Úenvironmentr   ÚtemplateÚstrú)tuple[str, str | None, t.Callable | None]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 ]&\}}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debughelpersr0   r   )	r!   r(   r)   ZattemptsZtrvÚsrcobjr   r   r0   r   r   r   r-   B   s"   €ÿz,DispatchingJinjaLoader._get_source_explainedc              	   C  s@   |   |¡D ]\}}z	| ||¡W   S  ty   Y qw t|ƒ‚r'   )r1   r/   r   )r!   r(   r)   Z_srcobjr   r   r   r   r.   Z   s   ÿz'DispatchingJinjaLoader._get_source_fastú4t.Generator[tuple[Scaffold, BaseLoader], None, None]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   r1   d   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   r5   ÚupdateÚlist_templatesr6   ÚaddÚlist)r!   Úresultr   r7   r)   r   r   r   r;   p   s   €z%DispatchingJinjaLoader.list_templatesN)r   r   r   r   )r(   r   r)   r*   r   r+   )r)   r*   r   r4   )r   r8   )
r"   r#   r$   r%   r    r/   r-   r.   r1   r;   r   r   r   r   r&   3   s    





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   

ÿ

ÿrF   Ú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_templaterF   ©rG   r?   r   r)   r   r   r   Úrender_template‹   ó   
rN   Úsourcec                 K  rI   )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
   rJ   rK   Úfrom_stringrF   ©rP   r?   r   r)   r   r   r   Úrender_template_stringš   s   rS   út.Iterator[str]c                   sF   ˆ   ˆ¡ tjˆ ˆ jˆˆd d‡ ‡‡fdd„}|ƒ }tr!t|ƒ}|S )NrA   r   rT   c                   3  s*    ˆ  ˆ¡E d H  tjˆ ˆ jˆˆd d S r@   )Úgenerater   rC   rD   r   ©r   r?   r)   r   r   rU   ®   s
   €

ÿz_stream.<locals>.generate)r   rT   )rB   r   rC   rD   r   r   )r   r)   r?   rU   r   r   rV   r   Ú_stream¦   s   

ÿrW   c                 K  rI   )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
   rJ   rK   rL   rW   rM   r   r   r   Ústream_template½   s   rX   c                 K  rI   )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
   rJ   rK   rQ   rW   rR   r   r   r   Ústream_template_stringÐ   rO   rY   )r   r   )r   r   r)   r   r?   r   r   r*   )rG   rH   r?   r   r   r*   )rP   r*   r?   r   r   r*   )r   r   r)   r   r?   r   r   rT   )rG   rH   r?   r   r   rT   )rP   r*   r?   r   r   rT   )!Ú
__future__r   ÚtypingÚtZjinja2r   r   r   r   r   Úglobalsr   r	   r
   r   Úhelpersr   Zsignalsr   r   ÚTYPE_CHECKINGr   r   Zscaffoldr   r   r&   rF   rN   rS   rW   rX   rY   r   r   r   r   Ú<module>   s2    

L



