
    H[gq                    d   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!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)App)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      K/var/www/html/bid-api/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                  d    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__9   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_loadersr9   r   appenddebughelpersr;   r#   )	r$   r7   r8   attemptstrvsrcobjr   r   r;   s	            r   r5   z,DispatchingJinjaLoader._get_source_explainedC   s     LP"00:NFF&&{H=;C OOVVR01 ; 	D)$((HhG?Jx(( $ s   A22B ?B c                    | j                  |      D ]  \  }}	 |j                  ||      c S  t        |      # t        $ r Y 2w xY wr1   )r<   r9   r   )r$   r7   r8   _srcobjr   s        r   r6   z'DispatchingJinjaLoader._get_source_fast[   sV      $11(;OGV((h??  <
 x(( $ s   9	AAc              #     K   | j                   j                  }|| j                   |f | j                   j                         D ]  }|j                  }|||f  y wr1   )r#   jinja_loaderiter_blueprints)r$   r8   r   	blueprints       r   r<   z$DispatchingJinjaLoader._iter_loaderse   s]     &&((F""113I++F!'' 4s   AA 	A c                B   t               }| j                  j                  }||j                  |j	                                | j                  j                         D ]7  }|j                  }||j	                         D ]  }|j                  |        9 t        |      S r1   )setr#   rE   updatelist_templatesrF   addlist)r$   resultr   rG   r8   s        r   rK   z%DispatchingJinjaLoader.list_templateso   s    &&MM&//12113I++F! & 5 5 7HJJx( !8 4 F|r   N)r#   r   r'   r(   )r7   r!   r8   strr'   z3tuple[str, str | None, t.Callable[[], bool] | None])r8   rO   r'   z't.Iterator[tuple[Scaffold, BaseLoader]])r'   z	list[str])
r)   r*   r+   r,   r"   r9   r5   r6   r<   rK   r-   r   r   r/   r/   4   sm    <*<69<	<<)*)69)	<)0)*)69)	<)(r   r/   c                    | j                  |       t        j                  | | j                  ||       |j	                  |      }t        j                  | | j                  ||       |S N_async_wrapperr8   context)update_template_contextr   sendensure_syncrenderr   )r#   r8   rT   r   s       r   _renderrY   ~   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_templaterY   template_name_or_listrT   r#   r8   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   r[   r\   from_stringrY   sourcerT   r#   r8   s       r   render_template_stringre      s5     
)
)
+C}}((0H3'**r   c                      j                         t        j                    j                         d fd} |       }t        rt        |      }|S )NrR   c               3     K   j                        E d {    t        j                    j                         y 7 (wrQ   )generater   rV   rW   )r#   rT   r8   s   r   rh   z_stream.<locals>.generate   s;     $$W---(G	
 	.s   AA)A)r'   t.Iterator[str])rU   r   rV   rW   r   r   )r#   r8   rT   rh   r   s   ```  r   _streamrj      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   r[   r\   r]   rj   r^   s       r   stream_templaterl      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   r[   r\   rb   rj   rc   s       r   stream_template_stringrn      s5     
)
)
+C}}((0H3'**r   )r'   dict[str, t.Any])r#   r   r8   r   rT   ro   r'   rO   )r_   %str | Template | list[str | Template]rT   r&   r'   rO   )rd   rO   rT   r&   r'   rO   )r#   r   r8   r   rT   ro   r'   ri   )r_   rp   rT   r&   r'   ri   )rd   rO   rT   r&   r'   ri   )#
__future__r   typingtjinja2r   r   r!   r   r   globalsr	   r
   r   r   helpersr   signalsr   r   TYPE_CHECKINGr#   r   
sansio.appr   sansio.scaffoldr   r   r/   rY   r`   re   rj   rl   rn   r-   r   r   <module>r{      s    "   1  #       ( + &??)
/ 
GZ GT	+@++ 	+	+	"-=.+@++ +&+r   