B
    ;=[2                 @   s|   d Z ddlmZmZmZ ddlmZmZ ddl	m
Z
mZ dd ZG dd	 d	eZG d
d deZdd Zdd Zdd ZdS )u   
    flask.templating
    ~~~~~~~~~~~~~~~~

    Implements the bridge to Jinja2.

    :copyright: © 2010 by the Pallets team.
    :license: BSD, see LICENSE for more details.
    )
BaseLoaderEnvironmentTemplateNotFound   )_request_ctx_stack_app_ctx_stack)template_renderedbefore_render_templatec              C   sB   t j} tj}i }|dk	r"|j|d< | dk	r>| j|d< | j|d< |S )zSDefault template context processor.  Injects `request`,
    `session` and `g`.
    Ngrequestsession)r   topr   r
   r   r   )ZreqctxZappctxrv r   /lib/python3.7/site-packages/flask/templating.py_default_template_ctx_processor   s    


r   c               @   s   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.
    c             K   s,   d|kr|  |d< tj| f| || _d S )Nloader)Zcreate_global_jinja_loaderBaseEnvironment__init__app)selfr   Zoptionsr   r   r   r   (   s    zEnvironment.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r   "   s   r   c               @   s@   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.
    c             C   s
   || _ d S )N)r   )r   r   r   r   r   r   4   s    zDispatchingJinjaLoader.__init__c             C   s$   | j jd r| ||S | ||S )NZEXPLAIN_TEMPLATE_LOADING)r   Zconfig_get_source_explained_get_source_fast)r   environmenttemplater   r   r   
get_source7   s    z!DispatchingJinjaLoader.get_sourcec       	   	   C   s   g }d }x\|  |D ]N\}}y|||}|d kr6|}W n tk
rP   d }Y nX ||||f qW ddlm} || j|| |d k	r|S t|d S )Nr   )!explain_template_loading_attempts)_iter_loadersr    r   appendZdebughelpersr!   r   )	r   r   r   ZattemptsZtrvsrcobjr   r   r!   r   r   r   r   <   s    
z,DispatchingJinjaLoader._get_source_explainedc          	   C   sH   x:|  |D ],\}}y|||S  tk
r6   wY qX qW t|d S )N)r"   r    r   )r   r   r   r$   r   r   r   r   r   P   s    z'DispatchingJinjaLoader._get_source_fastc             c   sL   | j j}|d k	r| j |fV  x*| j  D ]}|j}|d k	r(||fV  q(W d S )N)r   jinja_loaderiter_blueprints)r   r   r   	blueprintr   r   r   r"   X   s    z$DispatchingJinjaLoader._iter_loadersc             C   sj   t  }| jj}|d k	r$||  x<| j D ].}|j}|d k	r0x| D ]}|| qLW q0W t|S )N)setr   r%   updatelist_templatesr&   addlist)r   resultr   r'   r   r   r   r   r*   b   s    z%DispatchingJinjaLoader.list_templatesN)
r   r   r   r   r   r    r   r   r"   r*   r   r   r   r   r   /   s   
r   c             C   s.   t j|| |d | |}tj|| |d |S )z)Renders the template and fires the signal)r   context)r	   sendZrenderr   )r   r.   r   r   r   r   r   _renderq   s    
r0   c             K   s*   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_contextr0   	jinja_envZget_or_select_template)Ztemplate_name_or_listr.   ctxr   r   r   render_templatez   s    
r4   c             K   s*   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   r1   r0   r2   Zfrom_string)sourcer.   r3   r   r   r   render_template_string   s    	r6   N)r   Zjinja2r   r   r   r   globalsr   r   Zsignalsr   r	   r   r   r0   r4   r6   r   r   r   r   <module>
   s   B	