ó
`¾Tc           @   sÎ   d  Z  d d l Z d d l m Z m Z m Z d d l m Z m	 Z	 d d l
 m Z d d l m Z d d l m Z 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: (c) 2011 by Armin Ronacher.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t
   BaseLoadert   Environmentt   TemplateNotFoundi   (   t   _request_ctx_stackt   _app_ctx_stack(   t   template_rendered(   t   blueprint_is_module(   t
   itervaluest	   iteritemsc          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(    (    sV   /var/www/send.findwatt.com/datamanager/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(    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyR   *   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyR   $   s   t   DispatchingJinjaLoaderc           B   s2   e  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   (    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyR   6   s    c         C   sX   xE |  j  | ƒ D]4 \ } } y | j | | ƒ SWq t k
 rC q Xq Wt | ƒ ‚ d  S(   N(   t   _iter_loaderst
   get_sourceR   (   R   t   environmentt   templateR   t
   local_name(    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyR   9   s    c         c   sý   |  j  j } | d  k	 r& | | f Vn  yg t j | ƒ j d d ƒ \ } } |  j  j | } t | ƒ rŒ | j } | d  k	 rŒ | | f VqŒ n  Wn t t	 f k
 r¦ n XxO t
 |  j  j ƒ D]; } t | ƒ rÒ qº n  | j } | d  k	 rº | | f Vqº qº Wd  S(   Nt   /i   (   R   t   jinja_loaderR   t	   posixpatht   normpatht   splitt
   blueprintsR   t
   ValueErrort   KeyErrorR   (   R   R    R   t   moduleR!   t	   blueprint(    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyR   B   s$    !		c         C   sÃ   t  ƒ  } |  j j } | d  k	 r7 | j | j ƒ  ƒ n  x t |  j j ƒ D]k \ } } | j } | d  k	 rJ xG | j ƒ  D]6 } d } t | ƒ r | d } n  | j	 | | ƒ qx WqJ qJ Wt
 | ƒ S(   Nt    R"   (   t   setR   R#   R   t   updatet   list_templatesR   R'   R   t   addt   list(   R   t   resultR   t   nameR+   R    t   prefix(    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyR/   Z   s    		(   R   R   R   R   R   R   R/   (    (    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyR   1   s
   				c         C   s,   |  j  | ƒ } t j | d |  d | ƒ| S(   s)   Renders the template and fires the signalR    t   context(   t   renderR   t   send(   R    R5   R   R   (    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyt   _renderl   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_contextR8   t	   jinja_envt   get_or_select_template(   t   template_name_or_listR5   t   ctx(    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyt   render_templates   s    
	c         K   s;   t  j } | j j | ƒ t | j j j |  ƒ | | j ƒ S(   s  Renders a template from the given template source string
    with the given context.

    :param source: the sourcecode of the template to be
                   rendered
    :param context: the variables that should be available in the
                    context of the template.
    (   R   R   R   R9   R8   R:   t   from_string(   t   sourceR5   R=   (    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyt   render_template_stringƒ   s    		(   R   R$   t   jinja2R    R   R   R   t   globalsR   R   t   signalsR   R*   R   t   _compatR   R   R   R   R8   R>   RA   (    (    (    sV   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/templating.pyt   <module>
   s   	;		