Exemplo n.º 1
0
    def register_globals(self, environ):
        """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.

        """
        pylons_obj = environ['pylons.pylons']

        registry = environ['paste.registry']
        registry.register(pylons.response, pylons_obj.response)
        registry.register(pylons.request, pylons_obj.request)

        registry.register(pylons.app_globals, self.globals)
        registry.register(pylons.config, self.config)
        registry.register(pylons.h, self.helpers or
                          pylons.legacy.load_h(self.package_name))
        registry.register(pylons.c, pylons_obj.c)
        registry.register(pylons.translator, pylons_obj.translator)

        if self.buffet:
            registry.register(pylons.buffet, self.buffet)
        if 'session' in pylons_obj.__dict__:
            registry.register(pylons.session, pylons_obj.session)
        if 'cache' in pylons_obj.__dict__:
            registry.register(pylons.cache, pylons_obj.cache)

        if 'routes.url' in environ:
            registry.register(pylons.url, environ['routes.url'])
Exemplo n.º 2
0
    def register_globals(self, environ):
        """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.
        
        """
        pylons_obj = environ['pylons.pylons']

        registry = environ['paste.registry']
        registry.register(pylons.response, pylons_obj.response)
        registry.register(pylons.request, pylons_obj.request)

        registry.register(pylons.app_globals, self.globals)
        registry.register(pylons.config, self.config)
        registry.register(pylons.tmpl_context, pylons_obj.tmpl_context)
        registry.register(pylons.translator, pylons_obj.translator)

        if 'session' in pylons_obj.__dict__:
            registry.register(pylons.session, pylons_obj.session)
        if 'cache' in pylons_obj.__dict__:
            registry.register(pylons.cache, pylons_obj.cache)
        elif 'cache' in pylons_obj.app_globals.__dict__:
            registry.register(pylons.cache, pylons_obj.app_globals.cache)

        if 'routes.url' in environ:
            registry.register(pylons.url, environ['routes.url'])
Exemplo n.º 3
0
    def setup_app_env(self, environ, start_response):
        """Setup and register all the Pylons objects with the registry"""
        if self.log_debug:
            log.debug("Setting up Pylons stacked object globals")
        registry = environ['paste.registry']

        registry.register(WSGIRequest.defaults, self.request_options)
        registry.register(WSGIResponse.defaults, self.response_options)

        req = WSGIRequest(environ)
                
        # Setup the basic pylons global objects
        registry.register(pylons.request, req)
        registry.register(pylons.response, WSGIResponse())
        registry.register(pylons.buffet, self.buffet)
        registry.register(pylons.g, self.globals)
        registry.register(pylons.config, self.config)
        registry.register(pylons.h, self.helpers or \
                          pylons.legacy.load_h(self.package_name))
        
        # Setup the translator global object
        registry.register(pylons.translator, gettext.NullTranslations())
        lang = self.config.get('lang')
        if lang:
            set_lang(lang)
        
        if self.config['pylons.strict_c']:
            registry.register(pylons.c, ContextObj())
        else:
            registry.register(pylons.c, AttribSafeContextObj())
        
        econf = environ['pylons.environ_config']
        if econf.get('session'):
            registry.register(pylons.session, environ[econf['session']])
        if econf.get('cache'):
            registry.register(pylons.cache, environ[econf['cache']])
Exemplo n.º 4
0
    def setup_app_env(self, environ, start_response):
        """Setup and register all the Pylons objects with the registry"""
        if self.log_debug:
            log.debug("Setting up Pylons stacked object globals")
        registry = environ['paste.registry']

        registry.register(WSGIRequest.defaults, self.request_options)
        registry.register(WSGIResponse.defaults, self.response_options)

        req = WSGIRequest(environ)

        # Setup the basic pylons global objects
        registry.register(pylons.request, req)
        registry.register(pylons.response, WSGIResponse())
        registry.register(pylons.buffet, self.buffet)
        registry.register(pylons.g, self.globals)
        registry.register(pylons.config, self.config)
        registry.register(pylons.h, self.helpers or \
                          pylons.legacy.load_h(self.package_name))

        # Setup the translator global object
        registry.register(pylons.translator, gettext.NullTranslations())
        lang = self.config.get('lang')
        if lang:
            set_lang(lang)

        if self.config['pylons.strict_c']:
            registry.register(pylons.c, ContextObj())
        else:
            registry.register(pylons.c, AttribSafeContextObj())

        econf = environ['pylons.environ_config']
        if econf.get('session'):
            registry.register(pylons.session, environ[econf['session']])
        if econf.get('cache'):
            registry.register(pylons.cache, environ[econf['cache']])