Example #1
0
    def setup_app_env(self, environ, start_response):
        """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.
        
        """
        if self.log_debug:
            log.debug("Setting up Pylons stacked object globals")

        # Setup the basic pylons global objects
        req_options = self.request_options
        req = Request(environ,
                      charset=req_options['charset'],
                      unicode_errors=req_options['errors'],
                      decode_param_names=req_options['decode_param_names'])
        req.language = req_options['language']
        req.config = self.config
        req.link, req.route_dict = environ['wsgiorg.routing_args']

        response = Response(content_type=self.response_options['content_type'],
                            charset=self.response_options['charset'])
        response.headers.update(self.response_options['headers'])

        # Store a copy of the request/response in environ for faster access
        pylons_obj = PylonsContext()
        pylons_obj.config = self.config
        pylons_obj.request = req
        pylons_obj.response = response
        pylons_obj.app_globals = self.globals
        pylons_obj.h = self.helpers

        if 'routes.url' in environ:
            pylons_obj.url = environ['routes.url']

        environ['pylons.pylons'] = pylons_obj

        environ['pylons.environ_config'] = self.environ_config

        # Setup the translator object
        lang = self.config['lang']
        pylons_obj.translator = _get_translator(lang,
                                                pylons_config=self.config)

        if self.config['pylons.strict_tmpl_context']:
            tmpl_context = ContextObj()
        else:
            tmpl_context = AttribSafeContextObj()
        pylons_obj.tmpl_context = req.tmpl_context = tmpl_context

        if self._session_key in environ:
            pylons_obj.session = req.session = environ[self._session_key]
        if self._cache_key in environ:
            pylons_obj.cache = environ[self._cache_key]

        # Load the globals with the registry if around
        if 'paste.registry' in environ:
            self.register_globals(environ)
Example #2
0
 def setup_app_env(self, environ, start_response):
     """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.
     
     """
     if self.log_debug:
         log.debug("Setting up Pylons stacked object globals")
     
     
     # Setup the basic pylons global objects
     req_options = self.request_options
     req = Request(environ, charset=req_options['charset'],
                   unicode_errors=req_options['errors'],
                   decode_param_names=req_options['decode_param_names'])
     req.language = req_options['language']
     req.config = self.config
     req.link, req.route_dict = environ['wsgiorg.routing_args']
     
     response = Response(
         content_type=self.response_options['content_type'],
         charset=self.response_options['charset'])
     response.headers.update(self.response_options['headers'])
     
     # Store a copy of the request/response in environ for faster access
     pylons_obj = PylonsContext()
     pylons_obj.config = self.config
     pylons_obj.request = req
     pylons_obj.response = response
     pylons_obj.app_globals = self.globals
     pylons_obj.h = self.helpers
     
     if 'routes.url' in environ:
         pylons_obj.url = environ['routes.url']
             
     environ['pylons.pylons'] = pylons_obj
     
     environ['pylons.environ_config'] = self.environ_config
     
     # Setup the translator object
     lang = self.config['lang']
     pylons_obj.translator = _get_translator(lang, pylons_config=self.config)
     
     if self.config['pylons.strict_tmpl_context']:
         tmpl_context = ContextObj()
     else:
         tmpl_context = AttribSafeContextObj()
     pylons_obj.tmpl_context = req.tmpl_context = tmpl_context
     
     if self._session_key in environ:
         pylons_obj.session = req.session = environ[self._session_key]
     if self._cache_key in environ:
         pylons_obj.cache = environ[self._cache_key]
     
     # Load the globals with the registry if around
     if 'paste.registry' in environ:
         self.register_globals(environ)