
     fq                    @   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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!d0d)Z"dS )1    )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                     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      S/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/flask/templating.py_default_template_ctx_processorr      sY     [F_T""FB(399I    c                      e Zd ZdZ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                n    d|vr|                                 |d<   t          j        | fi | || _        d S )Nloader)create_global_jinja_loaderBaseEnvironment__init__r    )selfr    r!   s      r   r(   zEnvironment.__init__-   sG    7"" # > > @ @GH 11111r   N)r    r   r!   r"   r   r#   )__name__
__module____qualname____doc__r(    r   r   r   r   '   s2         
     r   r   c                  B    e Zd ZdZddZddZddZddZddZ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                    || _         d S N)r    )r)   r    s     r   r(   zDispatchingJinjaLoader.__init__9   s    r   environmentr'   templatestr3tuple[str, str | None, t.Callable[[], bool] | None]c                ~    | j         j        d         r|                     ||          S |                     ||          S )NEXPLAIN_TEMPLATE_LOADING)r    config_get_source_explained_get_source_fast)r)   r3   r4   s      r   
get_sourcez!DispatchingJinjaLoader.get_source<   sC     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debughelpersr>   r    )	r)   r3   r4   attemptstrvsrcobjr%   r   r>   s	            r   r:   z,DispatchingJinjaLoader._get_source_explainedC   s     LP"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          |          r2   )r?   r<   r   )r)   r3   r4   _srcobjr%   s        r   r;   z'DispatchingJinjaLoader._get_source_fast[   st      $11(;; 	 	OGV((h?????#   x(((s   4
A A't.Iterator[tuple[Scaffold, BaseLoader]]c              #     K   | j         j        }|| j         |fV  | j                                         D ]}|j        }|||fV  d S r2   )r    jinja_loaderiter_blueprints)r)   r4   r%   	blueprints       r   r?   z$DispatchingJinjaLoader._iter_loaderse   sp      &(F""""1133 	( 	(I+F!''''	( 	(r   	list[str]c                H   t                      }| j        j        }|'|                    |                                           | j                                        D ]7}|j        }|,|                                D ]}|                    |           8t          |          S r2   )setr    rI   updatelist_templatesrJ   addlist)r)   resultr%   rK   r4   s        r   rP   z%DispatchingJinjaLoader.list_templateso   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#   )r3   r'   r4   r5   r   r6   )r4   r5   r   rG   )r   rL   )
r*   r+   r,   r-   r(   r<   r:   r;   r?   rP   r.   r   r   r0   r0   4   s            < < < <) ) ) )0) ) ) )( ( ( (     r   r0   r    r   r4   r   contextr5   c                    |                      |           t          j        | | j        ||           |                    |          }t          j        | | j        ||           |S N_async_wrapperr4   rT   )update_template_contextr   sendensure_syncrenderr   )r    r4   rT   r   s       r   _renderr]   ~   sz    (((COh    
	!	!BCOh    Ir   template_name_or_list%str | Template | list[str | Template]r"   c                ~    t          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_templater]   r^   rT   r    r4   s       r   render_templatere      s:     
)
+
+C}334IJJH3'***r   sourcec                ~    t          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   ra   rb   from_stringr]   rf   rT   r    r4   s       r   render_template_stringrj      s9     
)
+
+C}((00H3'***r   t.Iterator[str]c                                                      t          j          j                   d fd} |            }t          rt          |          }|S )NrW   r   rk   c               3  |   K                                  E d {V  t          j          j                   d S rV   )generater   rZ   r[   )r    rT   r4   s   r   rn   z_stream.<locals>.generate   s\      $$W---------(G	
 	
 	
 	
 	
 	
r   )r   rk   )rY   r   rZ   r[   r   r   )r    r4   rT   rn   r   s   ```  r   _streamro      s     (((COh   
 
 
 
 
 
 
 
 
B  % $$Ir   c                ~    t          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   ra   rb   rc   ro   rd   s       r   stream_templaterq      s:     
)
+
+C}334IJJH3'***r   c                ~    t          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   ra   rb   rh   ro   ri   s       r   stream_template_stringrs      s9     
)
+
+C}((00H3'***r   )r   r   )r    r   r4   r   rT   r   r   r5   )r^   r_   rT   r"   r   r5   )rf   r5   rT   r"   r   r5   )r    r   r4   r   rT   r   r   rk   )r^   r_   rT   r"   r   rk   )rf   r5   rT   r"   r   rk   )#
__future__r   typingtjinja2r   r   r'   r   r   globalsr	   r
   r   r   helpersr   signalsr   r   TYPE_CHECKINGr    r   
sansio.appr   sansio.scaffoldr   r   r0   r]   re   rj   ro   rq   rs   r.   r   r   <module>r~      s   " " " " " "           1 1 1 1 1 1       # # # # # #                                     ( ( ( ( ( ( + + + + + + & & & & & &? *))))))   
 
 
 
 
/ 
 
 
G G G G GZ G G GT	 	 	 	+ + + +	+ 	+ 	+ 	+   .+ + + +&+ + + + + +r   