ó
¹×-]c           @   sÊ   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 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d S(   sŠ   
    flask.templating
    ~~~~~~~~~~~~~~~~

    Implements the bridge to Jinja2.

    :copyright: 2010 Pallets
    :license: BSD-3-Clause
iÿÿÿÿ(   t
   BaseLoader(   t   Environment(   t   TemplateNotFoundi   (   t   _app_ctx_stack(   t   _request_ctx_stack(   t   before_render_template(   t   template_renderedc          C   sa   t  j }  t j } i  } | d k	 r4 | j | d <n  |  d k	 r] |  j | d <|  j | d <n  | S(   sS   Default template context processor.  Injects `request`,
    `session` and `g`.
    t   gt   requestt   sessionN(   R   t   topR   t   NoneR   R   R	   (   t   reqctxt   appctxt   rv(    (    s/   lib/python2.7/site-packages/flask/templating.pyt   _default_template_ctx_processor   s    		R   c           B   s   e  Z d  Z d „  Z RS(   sÌ   Works 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 | j  ƒ  | d <n  t j |  |  | |  _ d  S(   Nt   loader(   t   create_global_jinja_loadert   BaseEnvironmentt   __init__t   app(   t   selfR   t   options(    (    s/   lib/python2.7/site-packages/flask/templating.pyR   *   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s/   lib/python2.7/site-packages/flask/templating.pyR   $   s   t   DispatchingJinjaLoaderc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s\   A loader that looks for templates in the application and all
    the blueprint folders.
    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s/   lib/python2.7/site-packages/flask/templating.pyR   6   s    c         C   s0   |  j  j d r  |  j | | ƒ S|  j | | ƒ S(   Nt   EXPLAIN_TEMPLATE_LOADING(   R   t   configt   _get_source_explainedt   _get_source_fast(   R   t   environmentt   template(    (    s/   lib/python2.7/site-packages/flask/templating.pyt
   get_source9   s    c   	      C   sÊ   g  } d  } xx |  j | ƒ D]g \ } } y+ | j | | ƒ } | d  k rR | } n  Wn t k
 rl d  } n X| j | | | f ƒ q Wd d l m } | |  j | | ƒ | d  k	 rº | St | ƒ ‚ d  S(   Ni   (   t!   explain_template_loading_attempts(   R   t   _iter_loadersR!   R   t   appendt   debughelpersR"   R   (	   R   R   R    t   attemptst   trvt   srcobjR   R   R"   (    (    s/   lib/python2.7/site-packages/flask/templating.pyR   >   s    
c         C   s[   xH |  j  | ƒ D]7 \ } } y | j | | ƒ SWq t k
 rF q q Xq Wt | ƒ ‚ d  S(   N(   R#   R!   R   (   R   R   R    t   _srcobjR   (    (    s/   lib/python2.7/site-packages/flask/templating.pyR   S   s    c         c   sj   |  j  j } | d  k	 r) |  j  | f Vn  x: |  j  j ƒ  D]) } | j } | d  k	 r9 | | f Vq9 q9 Wd  S(   N(   R   t   jinja_loaderR   t   iter_blueprints(   R   R    R   t	   blueprint(    (    s/   lib/python2.7/site-packages/flask/templating.pyR#   [   s    	c         C   s—   t  ƒ  } |  j j } | d  k	 r7 | j | j ƒ  ƒ n  xS |  j j ƒ  D]B } | j } | d  k	 rG x$ | j ƒ  D] } | j | ƒ qo WqG qG Wt | ƒ S(   N(	   t   setR   R*   R   t   updatet   list_templatesR+   t   addt   list(   R   t   resultR   R,   R    (    (    s/   lib/python2.7/site-packages/flask/templating.pyR/   e   s    		(	   R   R   R   R   R!   R   R   R#   R/   (    (    (    s/   lib/python2.7/site-packages/flask/templating.pyR   1   s   					
c         C   sE   t  j | d |  d | ƒ|  j | ƒ } t j | d |  d | ƒ| S(   s)   Renders the template and fires the signalR    t   context(   R   t   sendt   renderR   (   R    R3   R   R   (    (    s/   lib/python2.7/site-packages/flask/templating.pyt   _rendert   s    c         K   s;   t  j } | j j | ƒ t | j j j |  ƒ | | j ƒ S(   s–  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   t   update_template_contextR6   t	   jinja_envt   get_or_select_template(   t   template_name_or_listR3   t   ctx(    (    s/   lib/python2.7/site-packages/flask/templating.pyt   render_template}   s    
	c         K   s;   t  j } | j j | ƒ t | j j j |  ƒ | | j ƒ S(   sF  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   R7   R6   R8   t   from_string(   t   sourceR3   R;   (    (    s/   lib/python2.7/site-packages/flask/templating.pyt   render_template_string   s    		N(   R   t   jinja2R    R   R   R   t   globalsR   R   t   signalsR   R   R   R   R6   R<   R?   (    (    (    s/   lib/python2.7/site-packages/flask/templating.pyt   <module>
   s   	C			