ó
ZËTc           @   s  y d  d l  m Z Wn! e k
 r7 d  d l m Z n Xd  d l m Z d  d l m Z d  d l Z d  d l m	 Z	 d  d l
 m Z d e f d „  ƒ  YZ d	 „  Z y( d  d l Z d  d l Z e e j _ Wn e k
 rÞ n Xd d d
 „ Z d d d d d „ Z d S(   iÿÿÿÿ(   t
   quote_plus(   t   asbool(   t   MarkupN(   t
   predicates(   t   Buncht   MissingRendererErrorc           B   s   e  Z d  „  Z RS(   c         C   s*   t  j |  d t d | ƒ ƒ | |  _ d  S(   Ns£   The renderer for '%(template_engine)s' templates is missing. Try adding the following line in you app_cfg.py:
"base_config.renderers.append('%(template_engine)s')"t   template_engine(   t	   Exceptiont   __init__t   dictR   (   t   selfR   (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/render.pyR      s
    	(   t   __name__t
   __module__R   (    (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/render.pyR      s   c       !   C   sµ  t  j j j ƒ  }  |  j } |  j } |  j } |  j } |  j } |  j	 } |  j
 } y | d j j } Wn  t t f k
 r‡ t ƒ  } n Xt d t  j d t  j d t d t  j d | j j d ƒ d | d	 | j d
 | j d
 d | j d d | d d | j k d t ƒ }	 t d | d | d | d | d | d | d | d | d t  j d | d | d |	 d | d t  j j d t  j j d t  j j ƒ }
 | j d d ƒ } | r±|
 j | ƒ  ƒ n  |
 S(   sÅ  Create a Bunch of variables that should be available in all templates.

    These variables are:

    WARNING: This function should not be called from outside of the render()
    code.  Please consider this function as private.

    quote_plus
        the urllib quote_plus function
    url
        the turbogears.url function for creating flexible URLs
    identity
        the current visitor's identity information
    session
        the current beaker.session if the session_filter.on it set
        in the app.cfg configuration file. If it is not set then session
        will be None.
    locale
        the default locale
    inputs
        input values from a form
    errors
        validation errors
    request
        the WebOb Request Object
    config
        the app's config object
    auth_stack_enabled
        A boolean that determines if the auth stack is present in the environment
    predicates
        The :mod:`tg.predicates` module.

    t   packaget   configt	   flash_objR    t   urlt   identitys   repoze.who.identityt   sessiont   localet   errorst   inputst   valuest   requestt   auth_stack_enableds   repoze.who.pluginsR   t   ct   tmpl_contextt   responset   app_globalst   gt   helperst   ht   tgt
   translatort	   ungettextt   _t   N_t   variable_providerN(   R    t   request_localt   contextt   _current_objR   R   R   R   R!   R   R   t   libR   t   AttributeErrort   ImportErrorR   t   flashR    R   t   environt   gett   plain_languagest
   validationR   t   i18nR"   t   ugettextt   gettext_noopt   Nonet   update(   t   tglt   reqt   confR   R   R!   R   R   R   t   tg_varst	   root_varsR%   (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/render.pyt   _get_tg_vars   s\    #													c   
      K   s˜  t  j j ƒ  } d } | d k	 rR | d j | ƒ } | d k rR t | ƒ ‚ qR n  | ss | d } | d | } n  |  s‚ i  }  n  |  j d i  ƒ } | j d ƒ | d <| j d ƒ | d <| j d ƒ | d	 <x9 | j d
 i  ƒ j d g  ƒ D] } | | | |  | ƒ qì W|  } | d }	 | |	 k r>t ƒ  } | j |  ƒ n  | | | |  | d <x9 | j d
 i  ƒ j d g  ƒ D] } | | | |  | ƒ qsW| d S(   s¾	  Renders a specific template in current TurboGears context.

    Permits to manually render any template like TurboGears would for
    expositions. It also guarantees that the ``before_render_call`` and
    ``after_render_call`` hooks are called in the process.

    :param dict template_vars: This is the dictonary of variables that should
                               become available to the template. Template
                               vars can also include the ``tg_cache`` dictionary
                               which enables template caching.
    :param str template_engine: This is the template engine name, same as
                                specified inside AppConfig.renderers.
    :param str template_name: This is the template to render, can be specified
                              both as a path or using dotted notation if available.

    TurboGears injects some additional variables in the template context,
    those include:

        - tg.config -> like tg.config in controllers
        - tg.flash_obj -> the flash object, call ``render`` on it to display it.
        - tg.quote_plus -> function to perform percentage escaping (%xx)
        - tg.url -> like tg.url in controllers
        - tg.identity -> like tg.request.identity in controllers
        - tg.session -> like tg.session in controllers
        - tg.locale -> Languages of the current request
        - tg.errors -> Validation errors
        - tg.inputs -> Values submitted for validation
        - tg.request -> like tg.request in controllers
        - tg.auth_stack_enabled -> if authentication is enabled or not
        - tg.predicates -> like tg.predicates in controllers

        - tmpl_context -> like tg.tmpl_context in controllers
        - response -> like tg.response in controllers
        - request -> like tg.request in controllers
        - config -> like tg.config in controllers
        - app_globals -> like tg.app_globals in controllers
        - session -> like tg.session in controllers
        - url -> like tg.url in controllers
        - h -> Your application helpers
        - translator -> The current gettext translator
        - _ -> like tg.i18n.ugettext

    Additional variables can be added to every template by a
    ``variable_provider`` function inside the application
    configuration. This function is expected to return
    a ``dict`` with any variable that should be added
    the default template variables. It can even replace
    existing variables.

    t   render_functionst   default_renderert   tg_cachet   keyt	   cache_keyt   expiret   cache_expiret   typet
   cache_typet   hookst   before_render_callt   rendering_engines_without_varst   resultt   after_render_callN(   R    R   R(   R4   R.   R   R;   R5   (
   t   template_varsR   t   template_namet   kwargsR   t   render_functiont   caching_optionst   funcR9   t   engines_without_vars(    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/render.pyt   render}   s4    3
	%
	%c         K   sÖ   | d k	 s$ | d k	 s$ | d k	 rË i  } | d k	 rC | | d <n  | sR d } n  | d k rg d } n  |  } x' | D] }	 | t | j |	 ƒ ƒ 7} qt Wt j j | |  }
 |
 j | d | d | ƒ} | S| ƒ  Sd S(   sV  Cache and render a template, took from Pylons

    Cache a template to the namespace ``template_name``, along with a
    specific key if provided.

    Basic Options

    ``template_name``
        Name of the template, which is used as the template namespace.
    ``render_func``
        Function used to generate the template should it no longer be
        valid or doesn't exist in the cache.
    ``ns_options``
        Tuple of strings, that should correspond to keys likely to be
        in the ``kwargs`` that should be used to construct the
        namespace used for the cache. For example, if the template
        language supports the 'fragment' option, the namespace should
        include it so that the cached copy for a template is not the
        same as the fragment version of it.

    Caching options (uses Beaker caching middleware)

    ``cache_key``
        Key to cache this copy of the template under.
    ``cache_type``
        Valid options are ``dbm``, ``file``, ``memory``, ``database``,
        or ``memcached``.
    ``cache_expire``
        Time in seconds to cache this template with this ``cache_key``
        for. Or use 'never' to designate that the cache should never
        expire.

    The minimum key required to trigger caching is
    ``cache_expire='never'`` which will cache the template forever
    seconds with no key.

    RC   t   defaultt   nevert
   createfunct
   expiretimeN(   R4   t   strR.   R    t   cachet	   get_cachet	   get_value(   RK   t   render_funct
   ns_optionsR@   RD   RB   RL   t   get_cache_kwt	   namespacet   nameRW   t   content(    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/render.pyt   cached_templateÜ   s     )$			(    (   t   urllibR    R+   t   urllib.parset   tg.support.convertersR   t
   markupsafeR   R    R   t   tg.utilR   R   R   R;   t   pylonst   pylons.templatingt
   templatingt   pylons_globalsR4   RQ   R`   (    (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/render.pyt   <module>   s&   
	\_