
    wdfK                         d 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
 Z G d de          Z G d de          Zd Zd Zd ZdS )z
    flask.templating
    ~~~~~~~~~~~~~~~~

    Implements the bridge to Jinja2.

    :copyright: 2010 Pallets
    :license: BSD-3-Clause
    )
BaseLoader)Environment)TemplateNotFound   )_app_ctx_stack)_request_ctx_stack)before_render_template)template_renderedc                  ~    t           j        } t          j        }i }|
|j        |d<   | | j        |d<   | j        |d<   |S )zSDefault template context processor.  Injects `request`,
    `session` and `g`.
    Ngrequestsession)r   topr   r   r   r   )reqctxappctxrvs      U/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/flask/templating.py_default_template_ctx_processorr      sK      #FF	B(399I    c                       e Zd ZdZ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.
    c                 n    d|vr|                                 |d<   t          j        | fi | || _        d S )Nloader)create_global_jinja_loaderBaseEnvironment__init__app)selfr   optionss      r   r   zEnvironment.__init__*   sG    7"" # > > @ @GH 11111r   N)__name__
__module____qualname____doc__r    r   r   r   r   $   s-         
    r   r   c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	DispatchingJinjaLoaderz\A loader that looks for templates in the application and all
    the blueprint folders.
    c                     || _         d S N)r   )r   r   s     r   r   zDispatchingJinjaLoader.__init__6   s    r   c                 ~    | j         j        d         r|                     ||          S |                     ||          S )NEXPLAIN_TEMPLATE_LOADING)r   config_get_source_explained_get_source_fast)r   environmenttemplates      r   
get_sourcez!DispatchingJinjaLoader.get_source9   sA    8?56 	E--k8DDD$$[(;;;r   c                 "   g }d }|                      |          D ]K\  }}	 |                    ||          }||}n# t          $ r d }Y nw xY w|                    |||f           Lddlm}  || j        ||           ||S t          |          )Nr   )!explain_template_loading_attempts)_iter_loadersr/   r   appenddebughelpersr1   r   )	r   r-   r.   attemptstrvsrcobjr   r   r1   s	            r   r+   z,DispatchingJinjaLoader._get_source_explained>   s    "00:: 	2 	2NFF&&{H==;C#   OOVVR01111CCCCCC))$(HhGGG?Jx(((s   ;A
	A
c                     |                      |          D ]-\  }}	 |                    ||          c S # t          $ r Y *w xY wt          |          r'   )r2   r/   r   )r   r-   r.   _srcobjr   s        r   r,   z'DispatchingJinjaLoader._get_source_fastS   sr    #11(;; 	 	OGV((h?????#   x(((s   4
A Ac              #      K   | j         j        }|| j         |fV  | j                                         D ]}|j        }|||fV  d S r'   )r   jinja_loaderiter_blueprints)r   r.   r   	blueprints       r   r2   z$DispatchingJinjaLoader._iter_loaders[   sp      &(F""""1133 	( 	(I+F!''''	( 	(r   c                 H   t                      }| j        j        }|'|                    |                                           | j                                        D ]7}|j        }|,|                                D ]}|                    |           8t          |          S r'   )setr   r;   updatelist_templatesr<   addlist)r   resultr   r=   r.   s        r   rA   z%DispatchingJinjaLoader.list_templatese   s    &MM&//112221133 	) 	)I+F! & 5 5 7 7 ) )HJJx((((F||r   N)
r   r    r!   r"   r   r/   r+   r,   r2   rA   r#   r   r   r%   r%   1   sx           < < <
) ) )*) ) )( ( (    r   r%   c                     t          j        || |           |                     |          }t          j        || |           |S )z)Renders the template and fires the signal)r.   context)r	   sendrenderr
   )r.   rF   r   r   s       r   _renderrI   t   sJ     hHHHH		!	!B37CCCCIr   c                     t           j        }|j                            |           t	          |j        j                            |           ||j                  S )a  Renders a template from the template folder with the given
    context.

    :param template_name_or_list: the name of the template to be
                                  rendered, or an iterable with template names
                                  the first one existing will be rendered
    :param context: the variables that should be available in the
                    context of the template.
    )r   r   r   update_template_contextrI   	jinja_envget_or_select_template)template_name_or_listrF   ctxs      r   render_templaterP   }   sS     
CG##G,,,001FGG  r   c                     t           j        }|j                            |           t	          |j        j                            |           ||j                  S )aF  Renders a template from the given template source string
    with the given context. Template variables will be autoescaped.

    :param source: the source code of the template to be
                   rendered
    :param context: the variables that should be available in the
                    context of the template.
    )r   r   r   rK   rI   rL   from_string)sourcerF   rO   s      r   render_template_stringrT      sI     
CG##G,,,37$0088'37KKKr   N)r"   jinja2r   r   r   r   globalsr   r   signalsr	   r
   r   r%   rI   rP   rT   r#   r   r   <module>rX      s7          1 1 1 1 1 1 # # # # # # # # # # # # ' ' ' ' ' ' + + + + + + & & & & & &  
 
 
 
 
/ 
 
 
@ @ @ @ @Z @ @ @F    &L L L L Lr   