Ñò
Õ¥WJc           @   sî   d  Z  d d k Z d d k Z d d k Z d d k l Z d d k l Z l	 Z	 d d k
 Z
 d d k Z
 d d k Z
 d d k l Z l Z d d k l Z d d k l Z l Z l Z l Z d g Z e i e ƒ Z d e f d	 „  ƒ  YZ d S(
   så   WSGI App Creator

This module is responsible for creating the basic Pylons WSGI
application (PylonsApp). It's generally assumed that it will be called
by Paste, though any WSGI server could create and call the WSGI app as
well.

iÿÿÿÿN(   t   request_config(   t	   HTTPFoundt   HTTPNotFound(   t   Requestt   Response(   t   _get_translator(   t   AttribSafeContextObjt
   ContextObjt   PylonsContextt   class_name_from_module_namet	   PylonsAppc           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sã  Pylons WSGI Application

    This basic WSGI app is provided should a web developer want to
    get access to the most basic Pylons web application environment
    available. By itself, this Pylons web application does little more
    than dispatch to a controller and setup the context object, the
    request object, and the globals object.
    
    Additional functionality like sessions, and caching can be setup by
    altering the ``environ['pylons.environ_config']`` setting to
    indicate what key the ``session`` and ``cache`` functionality
    should come from.
    
    Resolving the URL and dispatching can be customized by sub-classing
    or "monkey-patching" this class. Subclassing is the preferred
    approach.
    
    c      
   K   s–  t  i i ƒ  |  _ } | d } | d |  _ | i d ƒ p | d |  _ | d |  _ | |  _ | d |  _ | d |  _	 h  |  _
 t |  _ |  i i d d ƒ d	 „  } | |  _ | i d
 ƒ o˜ | d
 d } t  i i | d d | d | d |  _ xf | d
 d D]I } t i d | d ƒ |  i i | d d | d d | d | d qWn
 d |  _ |  i i d d ƒ |  _ |  i i d d ƒ |  _ d S(   sø   Initialize a base Pylons WSGI application
        
        The base Pylons WSGI application requires several keywords, the
        package name, and the globals object. If no helpers object is
        provided then h will be None.
        
        s   pylons.packages   pylons.hs   pylons.app_globalss   pylons.gs   pylons.environ_configs   pylons.request_optionss   pylons.response_optionst   langc         S   s#   t  i d |  ƒ t d |  ƒ ‚ d  S(   Ns   Raising redirect to %st   location(   t   logt   debugR   (   t   url(    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyt   redirect_toD   s    s   buffet.template_enginesi    t   enginet   template_roott   template_optionsi   s+   Initializing additional template engine: %st   aliast   sessions   beaker.sessiont   caches   beaker.cacheN(   t   pylonst   configt   _current_objt   helperst   gett   globalst   environ_configt   package_namet   request_optionst   response_optionst   controller_classest   Falset	   log_debugt
   setdefaultt   NoneR   t
   templatingt   Buffett   buffetR   R   t   preparet   _session_keyt
   _cache_key(   t   selft   kwargsR   R   R   t   def_engt   e(    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyt   __init__/   s:    
						
 	
	c         C   sn  t  i t i ƒ  j } |  _ |  i | | ƒ d | j o` |  i | ƒ | d d j o> t i i	 i
 | ƒ | d d g ƒ d t i i	 i | ƒ g Sn |  i | | ƒ } |  i | | | ƒ } d | j o" t | d ƒ o | | d d	 <n z_ t | d ƒ o& | o t i d
 ƒ n | | | ƒ S| d j	 o | St d | i ƒ ‚ Wd d | j o | d =n Xd S(   s–  Setup and handle a web request
        
        PylonsApp splits its functionality into several methods to
        make it easier to subclass and customize core functionality.
        
        The methods are called in the following order:
        
        1. :meth:`~PylonsApp.setup_app_env`
        2. :meth:`~PylonsApp.load_test_env` (Only if operating in
           testing mode)
        3. :meth:`~PylonsApp.resolve`
        4. :meth:`~PylonsApp.dispatch`
        
        The response from :meth:`~PylonsApp.dispatch` is expected to be
        an iterable (valid :pep:`333` WSGI response), which is then
        sent back as the response.
        
        s   paste.testing_variablest	   PATH_INFOs   /_test_varss   200 OKs   Content-types
   text/plains   %st   wsgi_responset   responses6   Transforming legacy Response object into WSGI responsesK   No content returned by controller (Did you remember to 'return' it?) in: %rNs   pylons.pylons(   s   Content-types
   text/plain(   t   loggingt   DEBUGR   t   getEffectiveLevelR#   t   setup_app_envt   load_test_envt   pastet   registryt   restorert   save_registry_statet   get_request_idt   resolvet   dispatcht   hasattrR   R%   t	   Exceptiont   __name__(   R,   t   environt   start_responseR#   t
   controllerR3   (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyt   __call__^   s0    
c         C   sh  | d } | d } | i  t i | i ƒ | i  t i | i ƒ | i  t i |  i ƒ | i  t i |  i ƒ | i  t i |  i p t i	 i
 |  i ƒ ƒ | i  t i | i ƒ | i  t i | i ƒ |  i o | i  t i |  i ƒ n d | i j o | i  t i | i ƒ n d | i j o | i  t i | i ƒ n d | j o | i  t i | d ƒ n d S(   s3  Registers globals in the environment, called from
        :meth:`~PylonsApp.setup_app_env`
        
        Override this to control how the Pylons API is setup. Note that
        a custom render function will need to be used if the 
        ``pylons.app_globals`` global is not available.
        
        s   pylons.pylonss   paste.registryR   R   s
   routes.urlN(   t   registerR   R3   t   requestt   app_globalsR   R   t   hR   t   legacyt   load_hR   t   ct
   translatorR(   t   __dict__R   R   R   (   R,   RC   t
   pylons_objR:   (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyt   register_globals–   s$    	


c   
   	   C   sÕ  |  i  o t i d ƒ n |  i } t | d | d d | d d | d ƒ} | d | _ t d |  i d d |  i d ƒ } | i i	 |  i d ƒ t
 ƒ  } |  i | _ | | _ | | _ |  i | _ | _ |  i | _ |  i o |  i | _ n | | d	 <|  i | d
 <|  i d } t | d |  i ƒ| _ |  i d o t ƒ  } n
 t ƒ  } | | _ |  i d
 }	 |  i | j o | |  i | _ n |  i | j o | |  i | _ n d | j o |  i | ƒ n d S(   sÿ   Setup and register all the Pylons objects with the registry
        
        After creating all the global objects for use in the request,
        :meth:`~PylonsApp.register_globals` is called to register them
        in the environment.
        
        s(   Setting up Pylons stacked object globalst   charsett   unicode_errorst   errorst   decode_param_namest   languaget   content_typet   headerss   pylons.pylonss   pylons.environ_configR   t   pylons_configs   pylons.strict_cs   paste.registryN(   R#   R   R   R   R   RV   R   R    RX   t   updateR   R   RH   R3   R   t   gRI   R   RJ   R(   R   R   RN   R   R   RM   R*   R   R+   R   RQ   (
   R,   RC   RD   t   req_optionst   reqR3   RP   R   RM   t   econf(    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyR7   ¶   sD    
	
			

		c         C   ss   t  ƒ  } |  i | _ | d d } | | d <| i d ƒ } | p d S|  i o t i d | ƒ n |  i | ƒ S(   s=  Uses dispatching information found in 
        ``environ['wsgiorg.routing_args']`` to retrieve a controller
        name and return the controller instance from the appropriate
        controller module.
        
        Override this to change how the controller name is found and
        returned.
        
        s   wsgiorg.routing_argsi   s   pylons.routes_dictRE   Ns   Resolved URL to controller: %r(   R    R   t   redirectR   R#   R   R   t   find_controller(   R,   RC   RD   R   t   matchRE   (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyR>   ñ   s    	

c         C   sï   | |  i  j o |  i  | S|  i d | i d d ƒ } d } t | ƒ t t i | d ƒ o$ t t i | t i | i ƒ } n[ | i	 d ƒ d } t
 | ƒ d } |  i o t i d | | ƒ n t t i | | ƒ } | |  i  | <| S(	   sý   Locates a controller by attempting to import it then grab
        the SomeController instance from the imported module.
        
        Override this to change how the controller object is found once
        the URL has been resolved.
        
        s   .controllers.t   /t   .t   before_and_thist   __controller__iÿÿÿÿt
   Controllers+   Found controller, module: '%s', class: '%s'(   R!   R   t   replacet
   __import__R@   t   syst   modulest   getattrRe   t   splitR	   R#   R   R   (   R,   RE   t   full_module_namet   __traceback_hide__t   mycontrollert   module_namet
   class_name(    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyR`   	  s     	

	c         C   s¦   |  i  } | p) | o t i d ƒ n t ƒ  | | ƒ St | d ƒ o. | o t i d ƒ n | ƒ  } | | _ n | | d <| o t i d ƒ n | | | ƒ S(   s´   Dispatches to a controller, will instantiate the controller
        if necessary.
        
        Override this to change how the controller dispatch is handled.
        
        s1   No controller found, returning 404 HTTP Not Foundt	   __bases__s/   Controller appears to be a class, instantiatings   pylons.controllers,   Calling controller class with WSGI interface(   R#   R   R   R   R@   t   _pylons_log_debug(   R,   RE   RC   RD   R#   (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyR?   *  s    		
c         C   sá   |  i  o t i d ƒ n | d } | d } | i | d <| i | d <| i | d <| d <| i | d <| d	 <|  i d
 p | i | d <|  i | d <t	 | d ƒ o | i
 | d <n t	 | d ƒ o | i | d <n d S(   s%   Sets up our Paste testing environments.   Setting up paste testing environment variabless   paste.testing_variabless   pylons.pylonsR]   R3   t   tmpl_contextRM   RI   R[   s   pylons.hRJ   R   R   R   N(   R#   R   R   RH   R3   RM   RI   R   RJ   R@   R   R   (   R,   RC   t   testenvRP   (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyR8   F  s    


(   RB   t
   __module__t   __doc__R0   RF   RQ   R7   R>   R`   R?   R8   (    (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyR
      s   	/	8	 	;		!	(   Rw   R4   Ri   t   paste.registryR9   t   routesR    t	   webob.excR   R   R   t   pylons.legacyt   pylons.templatingt   pylons.controllers.utilR   R   t   pylons.i18n.translationR   t   pylons.utilR   R   R   R	   t   __all__t	   getLoggerRB   R   t   objectR
   (    (    (    sg   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.pyt   <module>   s   "	