Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
0
    def __call__(self, environ, start_response):
        registry = environ['paste.registry']
        py_obj = PylonsContext()
        environ_config = environ.setdefault('pylons.environ_config', {})
        if self.setup_cache:
            py_obj.cache = environ['beaker.cache']
            registry.register(pylons.cache, environ['beaker.cache'])
            environ_config['cache'] = 'beaker.cache'
        if self.setup_session:
            py_obj.session = environ['beaker.session']
            registry.register(pylons.session, environ['beaker.session'])
            environ_config['session'] = 'beaker.session'
        if self.setup_g:
            py_obj.app_globals = self.g
            registry.register(pylons.app_globals, self.g)
        translator = gettext.NullTranslations()
        py_obj.translator = translator
        registry.register(pylons.translator, translator)

        # Update the environ
        req = Request(environ, charset=request_defaults['charset'],
                      unicode_errors=request_defaults['errors'],
                      decode_param_names=request_defaults['decode_param_names']
        )
        req.language = request_defaults['language']

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

        environ.update(self.environ)
        py_obj.config = pylons.config._current_obj()
        py_obj.request = req
        py_obj.response = response
        py_obj.tmpl_context = ContextObj()
        environ['pylons.pylons'] = py_obj
        registry.register(pylons.request, req)
        registry.register(pylons.response, response)
        if 'routes.url' in environ:
            registry.register(pylons.url, environ['routes.url'])
        return self.app(environ, start_response)
Exemplo n.º 4
0
    def __call__(self, environ, start_response):
        registry = environ['paste.registry']
        py_obj = PylonsContext()
        environ_config = environ.setdefault('pylons.environ_config', {})
        if self.setup_cache:
            py_obj.cache = environ['beaker.cache']
            registry.register(pylons.cache, environ['beaker.cache'])
            environ_config['cache'] = 'beaker.cache'
        if self.setup_session:
            py_obj.session = environ['beaker.session']
            registry.register(pylons.session, environ['beaker.session'])
            environ_config['session'] = 'beaker.session'
        if self.setup_g:
            py_obj.app_globals = self.g
            registry.register(pylons.app_globals, self.g)
        translator = gettext.NullTranslations()
        py_obj.translator = translator
        registry.register(pylons.translator, translator)

        # Update the environ
        req = Request(
            environ,
            charset=request_defaults['charset'],
            unicode_errors=request_defaults['errors'],
            decode_param_names=request_defaults['decode_param_names'])
        req.language = request_defaults['language']

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

        environ.update(self.environ)
        py_obj.config = pylons.config._current_obj()
        py_obj.request = req
        py_obj.response = response
        py_obj.tmpl_context = ContextObj()
        environ['pylons.pylons'] = py_obj
        registry.register(pylons.request, req)
        registry.register(pylons.response, response)
        if 'routes.url' in environ:
            registry.register(pylons.url, environ['routes.url'])
        return self.app(environ, start_response)