o
    7 hr                     @  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   X/var/www/html/figdemos/bartoux_crm/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   zWorks 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)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)tuple[str, str | None, t.Callable | 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_loadersr2   r   appenddebughelpersr3   r   )	r#   r*   r+   ZattemptsZtrvsrcobjr   r   r3   r   r   r   r0   C   s"   z,DispatchingJinjaLoader._get_source_explainedc              	   C  s@   |  |D ]\}}z	|||W   S  ty   Y qw t|r)   )r4   r2   r   )r#   r*   r+   Z_srcobjr   r   r   r   r1   [   s   z'DispatchingJinjaLoader._get_source_fast4t.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   r4   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   r9   updatelist_templatesr:   addlist)r#   resultr   r;   r+   r   r   r   r?   q   s   z%DispatchingJinjaLoader.list_templatesN)r   r   r   r   )r*   r   r+   r,   r   r-   )r+   r,   r   r8   )r   r<   )
r$   r%   r&   r'   r"   r2   r0   r1   r4   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_async_wrapperr+   rC   )update_template_contextr   sendensure_syncZrenderr   )r   r+   rC   r   r   r   r   _render   s   



rJ   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_templaterJ   rK   rC   r   r+   r   r   r   render_template      
rR   sourcec                 K  rM   )zRender 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
   rN   rO   from_stringrJ   rT   rC   r   r+   r   r   r   render_template_string   s   rW   t.Iterator[str]c                   sF      tj  jd d fdd}| }tr!t|}|S )NrE   r   rX   c                   3  s*     E d H  tj  jd d S rD   )generater   rH   rI   r   r   rC   r+   r   r   rY      s
   

z_stream.<locals>.generate)r   rX   )rG   r   rH   rI   r   r   )r   r+   rC   rY   r   r   rZ   r   _stream   s   

r[   c                 K  rM   )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
   rN   rO   rP   r[   rQ   r   r   r   stream_template   s   r\   c                 K  rM   )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
   rN   rO   rU   r[   rV   r   r   r   stream_template_string   rS   r]   )r   r   )r   r   r+   r   rC   r   r   r,   )rK   rL   rC   r   r   r,   )rT   r,   rC   r   r   r,   )r   r   r+   r   rC   r   r   rX   )rK   rL   rC   r   r   rX   )rT   r,   rC   r   r   rX   )#
__future__r   typingtZjinja2r   r   r!   r   r   globalsr   r	   r
   r   helpersr   signalsr   r   TYPE_CHECKINGr   r   
sansio.appr   sansio.scaffoldr   r   r(   rJ   rR   rW   r[   r\   r]   r   r   r   r   <module>   s4    

L



