o
    ­1)hq  ã                   @  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  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   úOC:\Users\User\Downloads\Proyecto_IoT\venv\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!   9   s   
zDispatchingJinjaLoader.__init__Úenvironmentr    ÚtemplateÚstrú3tuple[str, str | None, t.Callable[[], bool] | 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_loadersr0   r   ÚappendZdebughelpersr1   r   )	r"   r)   r*   ZattemptsZtrvÚsrcobjr   r   r1   r   r   r   r.   C   s"   €ÿz,DispatchingJinjaLoader._get_source_explainedc              	   C  s@   |   |¡D ]\}}z	| ||¡W   S  ty   Y qw t|ƒ‚r(   )r2   r0   r   )r"   r)   r*   Z_srcobjr   r   r   r   r/   [   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   r2   e   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   r6   ÚupdateÚlist_templatesr7   ÚaddÚlist)r"   Úresultr   r8   r*   r   r   r   r<   o   s   €z%DispatchingJinjaLoader.list_templatesN)r   r   r   r   )r)   r    r*   r+   r   r,   )r*   r+   r   r5   )r   r9   )
r#   r$   r%   r&   r!   r0   r.   r/   r2   r<   r   r   r   r   r'   4   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   

ÿ

ÿrG   Ú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_templaterG   ©rH   r@   r   r*   r   r   r   Úrender_templateŠ   ó   
rO   Úsourcec                 K  rJ   )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
   rK   rL   Úfrom_stringrG   ©rQ   r@   r   r*   r   r   r   Úrender_template_string™   s   rT   út.Iterator[str]c                   sF   ˆ   ˆ¡ tjˆ ˆ jˆˆd d‡ ‡‡fdd„}|ƒ }tr!t|ƒ}|S )NrB   r   rU   c                   3  s*    ˆ  ˆ¡E d H  tjˆ ˆ jˆˆd d S rA   )Úgenerater   rD   rE   r   ©r   r@   r*   r   r   rV   ­   s
   €

ÿz_stream.<locals>.generate)r   rU   )rC   r   rD   rE   r   r   )r   r*   r@   rV   r   r   rW   r   Ú_stream¥   s   

ÿrX   c                 K  rJ   )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
   rK   rL   rM   rX   rN   r   r   r   Ústream_template¼   s   rY   c                 K  rJ   )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
   rK   rL   rR   rX   rS   r   r   r   Ústream_template_stringÏ   rP   rZ   )r   r   )r   r   r*   r   r@   r   r   r+   )rH   rI   r@   r   r   r+   )rQ   r+   r@   r   r   r+   )r   r   r*   r   r@   r   r   rU   )rH   rI   r@   r   r   rU   )rQ   r+   r@   r   r   rU   )#Ú
__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'   rG   rO   rT   rX   rY   rZ   r   r   r   r   Ú<module>   s4    

J



