
    +hO                    X   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 ddZ G d de      Z G d de      ZddZ	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 d dZ	 	 	 	 	 	 d!dZd"dZ y)#    )annotationsN)
BaseLoader)Environment)Template)TemplateNotFound   )_cv_app)_cv_request)current_app)request)stream_with_context)before_render_template)template_rendered)Flask)Scaffoldc                     t        j                  d      } t        j                  d      }i }| | j                  |d<   ||j                  |d<   |j
                  |d<   |S )zSDefault template context processor.  Injects `request`,
    `session` and `g`.
    Ngr   session)r	   getr
   r   r   r   )appctxreqctxrvs      C/var/www/html/venv/lib/python3.12/site-packages/flask/templating.py_default_template_ctx_processorr      s]     [[F__T"FB((399I    c                      e Zd ZdZddZy)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.
    c                l    d|vr|j                         |d<   t        j                  | fi | || _        y )Nloader)create_global_jinja_loaderBaseEnvironment__init__app)selfr"   optionss      r   r!   zEnvironment.__init__,   s7    7" # > > @GH  11r   N)r"   r   r$   t.AnyreturnNone)__name__
__module____qualname____doc__r!    r   r   r   r   &   s    
r   r   c                  l    e Zd ZdZd	dZ	 	 	 	 	 	 d
dZ	 	 	 	 	 	 d
dZ	 	 	 	 	 	 d
dZ	 	 	 	 ddZddZ	y)DispatchingJinjaLoaderz\A loader that looks for templates in the application and all
    the blueprint folders.
    c                    || _         y N)r"   )r#   r"   s     r   r!   zDispatchingJinjaLoader.__init__8   s	    r   c                |    | j                   j                  d   r| j                  ||      S | j                  ||      S )NEXPLAIN_TEMPLATE_LOADING)r"   config_get_source_explained_get_source_fast)r#   environmenttemplates      r   
get_sourcez!DispatchingJinjaLoader.get_source;   s;     88??56--k8DD$$[(;;r   c                   g }d }| j                  |      D ]0  \  }}	 |j                  ||      }||}|j                  |||f       2 ddlm}  || j                  ||       ||S t        |      # t        $ r d }Y Lw xY w)Nr   )!explain_template_loading_attempts)_iter_loadersr8   r   appenddebughelpersr:   r"   )	r#   r6   r7   attemptstrvsrcobjr   r   r:   s	            r   r4   z,DispatchingJinjaLoader._get_source_explainedB   s     LP"00: 	2NFF&&{H=;C OOVVR01	2 	D)$((HhG?Jx(( $ s   A22B ?B c                    | j                  |      D ]  \  }}	 |j                  ||      c S  t        |      # t        $ r Y 2w xY wr0   )r;   r8   r   )r#   r6   r7   _srcobjr   s        r   r5   z'DispatchingJinjaLoader._get_source_fastZ   s[      $11(; 	OGV((h??	
 x(( $ s   9	AAc              #     K   | j                   j                  }|| j                   |f | j                   j                         D ]  }|j                  }|||f  y wr0   )r"   jinja_loaderiter_blueprints)r#   r7   r   	blueprints       r   r;   z$DispatchingJinjaLoader._iter_loadersd   sd      &&((F""113 	(I++F!''	(s   AA 	A c                B   t               }| j                  j                  }||j                  |j	                                | j                  j                         D ]7  }|j                  }||j	                         D ]  }|j                  |        9 t        |      S r0   )setr"   rD   updatelist_templatesrE   addlist)r#   resultr   rF   r7   s        r   rJ   z%DispatchingJinjaLoader.list_templatesp   s    &&MM&//12113 	)I++F! & 5 5 7 )HJJx()	) F|r   N)r"   r   r&   r'   )r6   r   r7   strr&   z)tuple[str, str | None, t.Callable | None])r7   rN   r&   z4t.Generator[tuple[Scaffold, BaseLoader], None, None])r&   z	list[str])
r(   r)   r*   r+   r!   r8   r4   r5   r;   rJ   r,   r   r   r.   r.   3   s}    <&<25<	2<)&)25)	2)0)&)25)	2)
(
(	=
(r   r.   c                    | j                  |       t        j                  | | j                  ||       |j	                  |      }t        j                  | | j                  ||       |S N_async_wrapperr7   context)update_template_contextr   sendensure_syncrenderr   )r"   r7   rS   r   s       r   _renderrX      s]    (COOh 
	!BCOOh Ir   c                z    t        j                         }|j                  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_templaterX   template_name_or_listrS   r"   r7   s       r   render_templater_      s6     
)
)
+C}}334IJH3'**r   c                z    t        j                         }|j                  j                  |       }t	        |||      S )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   rZ   r[   from_stringrX   sourcerS   r"   r7   s       r   render_template_stringrd      s5     
)
)
+C}}((0H3'**r   c                      j                         t        j                    j                         d fd} |       }t        rt        |      }|S )NrQ   c               3     K   j                        E d {    t        j                    j                         y 7 (wrP   )generater   rU   rV   )r"   rS   r7   s   r   rg   z_stream.<locals>.generate   s;     $$W---(G	
 	.s   AA)A)r&   t.Iterator[str])rT   r   rU   rV   r   r   )r"   r7   rS   rg   r   s   ```  r   _streamri      sP     (COOh
 
B  $Ir   c                z    t        j                         }|j                  j                  |       }t	        |||      S )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   rZ   r[   r\   ri   r]   s       r   stream_templaterk      s6     
)
)
+C}}334IJH3'**r   c                z    t        j                         }|j                  j                  |       }t	        |||      S )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   rZ   r[   ra   ri   rb   s       r   stream_template_stringrm      s5     
)
)
+C}}((0H3'**r   )r&   dict[str, t.Any])r"   r   r7   r   rS   rn   r&   rN   )r^   %str | Template | list[str | Template]rS   r%   r&   rN   )rc   rN   rS   r%   r&   rN   )r"   r   r7   r   rS   rn   r&   rh   )r^   ro   rS   r%   r&   rh   )rc   rN   rS   r%   r&   rh   )!
__future__r   typingtjinja2r   r   r    r   r   globalsr	   r
   r   r   helpersr   signalsr   r   TYPE_CHECKINGr"   r   scaffoldr   r   r.   rX   r_   rd   ri   rk   rm   r,   r   r   <module>ry      s    "   1  #       ( + &??"
/ 
IZ IX	+@++ 	+	+	"-=.+@++ +&+r   