ó
ZËTc           @   sñ   d  d l  Z  d  d l Z d  d l Z d  d l m Z e j e ƒ Z d  d l Z d  d l m	 Z	 d  d l
 m Z d  d l m Z m Z d  d l m Z m Z y d  d l Z e Z Wn e Z n Xd e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d S(   iÿÿÿÿN(   t   HTTPNotFound(   t   request_local(   t   _get_translator(   t   Requestt   Response(   t
   ContextObjt   AttribSafeContextObjt   RequestLocalsc        	   B   s   e  Z d	 Z RS(
   t   responset   requestt   app_globalst   configt   tmpl_contextt
   translatort   sessiont   cachet   url(	   s   responses   requests   app_globalss   configs   tmpl_contexts
   translators   sessions   caches   url(   t   __name__t
   __module__t	   __slots__(    (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyR      s     t   TGAppc           B   s\   e  Z d	 d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   c         K   sk  | p t  j j ƒ  |  _ } | j d ƒ |  _ | d |  _ i  |  _ i  |  _ |  j d |  _ |  j j d t	 ƒ |  _
 |  j j d t ƒ |  _ | j d t d d d	 d
 d i d d 6d d 6d d 6d d 6ƒ ƒ |  _ |  j |  _ x_ |  j j d g  ƒ D]H } y | |  j |  j ƒ |  _ Wqõ t k
 r<| |  j ƒ |  _ qõ Xqõ Wd |  j k rg|  j d |  j d <n  d S(   s(  Initialize a base WSGI application

        Given an application configuration creates the WSGI
        application for it, if no configuration is provided
        then tg.config is used.

        TGApp constructor is also in charge of actually
        initializing application wrappers.
        s   tg.app_globalst   package_names   tg.strict_tmpl_contexts   tg.pylons_compatiblet   enable_routess   tg.response_optionst   content_types	   text/htmlt   charsets   utf-8t   headerss   no-caches   Cache-Controlt   Pragmas   Content-Typet   0s   Content-Lengtht   application_wrapperss   tg.root_controllert   rootN(   t   tgR   t   _current_objt   gett   globalsR   t   controller_classest   controller_instancest   strict_tmpl_contextt   Truet   pylons_compatiblet   FalseR   t   dictt   Nonet   resp_optionst   dispatcht   wrapped_dispatcht	   TypeError(   t   selfR   t   kwargst   wrapper(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyt   __init__   s.    
			
c         C   sÊ   y² | | d <| d | d <|  j  |  j d <t j t _ t j t _ t j t _ t j t _ t j t _ t j t _ t j	 t _	 t j
 t _
 |  j r± | d | d <t j t _ n  Wn t k
 rÅ n Xd S(   s5   Updates environ to be backward compatible with Pylonss   pylons.controllers	   tg.localss   pylons.pylonss   pylons.app_globalss   tg.routes_dicts   pylons.routes_dictN(   R!   R   R   R	   t   pylonsR   R
   R   R   R   R   R   R   t   ImportError(   R.   t   environt
   controller(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyt   setup_pylons_compatibilityC   s"    
	c   	      C   s  d } |  j  | ƒ \ } } | t k rk | d d k rk | d } | j ƒ  | d d g ƒ d j d	 ƒ g S|  j | | ƒ } |  j | | | ƒ } | t k r¯ | | d
 d <n  z- | d  k	 rË | | | ƒ St d | ƒ ‚ Wd  | d =t rd | k r| d =n  Xd  S(   Nt   beforet	   PATH_INFOs   /_test_varss   paste.registrys   200 OKs   Content-types
   text/plaint   DONEs   utf-8s   paste.testing_variablesR   sK   No content returned by controller (Did you remember to 'return' it?) in: %rs	   tg.localss   pylons.pylons(   s   Content-types
   text/plain(	   t   setup_app_envR%   t   preservet   encodet   resolveR,   R)   t	   Exceptiont
   has_pylons(	   R.   R4   t   start_responset   __traceback_hide__t   testmodet   contextt   registryR5   R   (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyt   __call__Z   s&    

c         C   sò  |  j  } t | ƒ } | j d | d ƒ | j d d ƒ |  j } t d | d d | d d | d ƒ } | d } t | d | ƒ} |  j rš t ƒ  } n	 t	 ƒ  } |  j
 }	 | j d ƒ }
 | j d	 ƒ } t ƒ  } | | _ | | _ |	 | _ | | _  | | _ | | _ |
 | _ | | _ |  j r?| j d
 ƒ } | | _ n  | | d <| d } | j t j  | ƒ | j t j | ƒ d | k rè| d } | | d <| | d <| | d <|  j
 | d <| | d <| j | d <| j | d <t | f St | f S(   s  Setup Request, Response and TurboGears context objects.

        Is also in charge of pushing TurboGears context into the
        paste registry and detect test mode. Returns whenever
        the testmode is enabled or not and the TurboGears context.
        t	   _languaget   langt   _response_typeR   R   R   t	   tg_configs   beaker.sessions   beaker.caches
   routes.urls	   tg.localss   paste.registrys   paste.testing_variablest   reqR   R   R
   R   R   R   N(   R   R   t   _fast_setattrR)   R*   R   R   R$   R   R   R!   R    R   R   R	   R
   R   R   R   R   R   R   t   registerR   RC   R%   R'   (   R.   R4   t   confRJ   R*   R   RG   R   R   R
   R   R   t   localsR   RD   t   testenv(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyR:   |   sX    		


													







c         C   sP   |  j  r= | d d } | | d <| j d ƒ } | sC d Sn d } |  j | ƒ 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   tg.routes_dictR5   R   N(   R   R    R)   t   get_controller_instance(   R.   R4   RC   t   matchR5   (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyR=   ¿   s    
	
c         C   s2   | j  d d ƒ j d ƒ } d j d „  | Dƒ ƒ S(   Nt   -t   _t    c         s   s   |  ] } | j  ƒ  Vq d  S(   N(   t   title(   t   .0t   w(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pys	   <genexpr>Ö   s    (   t   replacet   splitt   join(   R.   t   module_namet   words(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyt   class_name_from_module_nameÔ   s    c   
      C   sô   | |  j  k r |  j  | S|  j d d } |  j d d } | j | ƒ sQ t ‚ | t | ƒ d } d j |  j g | j t j	 ƒ | j d ƒ ƒ } d } t
 | ƒ | j d ƒ d } |  j | ƒ d	 } t t j | | ƒ }	 |	 |  j  | <|	 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.

        t   pathsR   t   controllersi   t   .t   /t   before_and_thisiÿÿÿÿt
   Controller(   R"   R   t
   startswitht   AssertionErrort   lenRZ   R   RY   t   ost   sept
   __import__R]   t   getattrt   syst   modules(
   R.   R5   t   root_module_patht   base_controller_patht   controller_patht   full_module_nameRA   R[   t
   class_namet   mycontroller(    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyt   find_controllerØ   s    	,
c         C   s_   y |  j  | SWnI t k
 rZ |  j | ƒ } t | d ƒ rI | ƒ  } n  | |  j  | <| SXd  S(   Nt	   __bases__(   R#   t   KeyErrorRs   t   hasattr(   R.   R5   Rr   (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyRP   ú   s    c         C   s<   | s t  ƒ  St r/ |  j r/ |  j | | ƒ n  | | | ƒ S(   s¼   Dispatches to a controller, the controller itself is expected
        to implement the routing system.

        Override this to change how requests are dispatched to controllers.
        (   R    R?   R&   R6   (   R.   R5   R4   RC   (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyR+     s
    N(   R   R   R)   R1   R6   RE   R:   R=   R]   Rs   RP   R+   (    (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyR      s   )		"	C			"	(   Rg   Rk   t   loggingt	   webob.excR    t	   getLoggerR   t   logR   R   t   tg.i18nR   t   tg.request_localR   R   t   tg.utilR   R   R2   R%   R?   R'   t   objectR   R   (    (    (    sh   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.7/site-packages/TurboGears2-2.3.3-py2.7.egg/tg/wsgiapp.pyt   <module>   s   $

