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(self):
     c = ContextObj()
     py_obj = PylonsContext()
     py_obj.tmpl_context = c
     py_obj.request = py_obj.response = None
     self.environ = {
         'pylons.routes_dict': dict(action='index'),
         'paste.config': dict(global_conf=dict(debug=True)),
         'pylons.pylons': py_obj
     }
     pylons.tmpl_context._push_object(c)
Example #3
0
 def setUp(self):
     if not os.path.exists(session_dir):
         os.makedirs(session_dir)
     # Setting TG2 up:
     c = ContextObj()
     py_obj = PylonsContext()
     py_obj.c = c
     py_obj.request = py_obj.response = None
     environ = {'pylons.routes_dict': dict(action='index'),
                'pylons.pylons': py_obj}
     pylons.tmpl_context._push_object(c)
     self.app = make_app(DefaultLessTGController, environ, with_errors=True)
    def setup_class(cls):
        '''
        Setup database
        '''
        model.repo.rebuild_db()
        harvest_model.setup()
        kata_model.setup()

        # The Pylons globals are not available outside a request. This is a hack to provide context object.
        c = AttribSafeContextObj()
        py_obj = PylonsContext()
        py_obj.tmpl_context = c
        pylons.tmpl_context._push_object(c)
Example #5
0
 def setUp(self):
     # Creating the session dir:
     if not os.path.exists(session_dir):
         os.makedirs(session_dir)
     # Setting TG2 up:
     c = ContextObj()
     py_obj = PylonsContext()
     py_obj.c = c
     py_obj.request = py_obj.response = None
     environ = {'pylons.routes_dict': dict(action='index'),
                'pylons.pylons': py_obj}
     pylons.tmpl_context._push_object(c)
     # Finally, the app:
     self.app = make_app(self.controller, environ)
Example #6
0
 def setUp(self):
     # Creating the session dir:
     if not os.path.exists(session_dir):
         os.makedirs(session_dir)
     # Setting Pylons up:
     c = ContextObj()
     py_obj = PylonsContext()
     py_obj.c = c
     py_obj.request = py_obj.response = None
     self.environ = {
         'pylons.routes_dict': dict(action='index'),
         'paste.config': dict(global_conf=dict(debug=True)),
         'pylons.pylons': py_obj,
     }
     pylons.c._push_object(c)
     # Finally, the app:
     self.app = make_app(self.controller, self.environ)
Example #7
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.g = py_obj.app_globals = self.g
            registry.register(pylons.g, 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.c = 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)
Example #8
0
 def __init__(self, *args, **kw):
     RepozeBFGRequest.__init__(self, *args, **kw)
     attrs = self.__dict__
     attrs['tmpl_context'] = PylonsContext()