Ejemplo n.º 1
0
 def application(environ, start_response):
     from mobilize.handlers import (
         passthrough,
         securityblock,
         )
     from mobilize.secure import DropResponseSignal
     from mobilize.exceptions import NoMatchingHandlerException
     def response(_handler):
         return _handler.wsgi_response(msite, environ, start_response)
     try:
         handler = msite.handler_map.get_handler_for(get_rel_url(environ))
     except NoMatchingHandlerException:
         handler = passthrough
     
     try:
         return response(handler)
     except DropResponseSignal:
         return response(securityblock)
     except Exception as ex:
         # Something went fatally wrong, so attempt to fallback on the passthrough handler.
         try:
             reqinfo = RequestInfo(environ)
             logger.critical('Fatal error for {} {}: {}'.format(reqinfo.method, reqinfo.rel_url, str(ex)))
         except:
             logger.critical('Very Fatal error for {}'.format(environ.get('REQUEST_URI', '???')))
         if not msite.is_production:
             # Don't mask the problem in development mode
             raise
         if handler == passthrough:
             # Nothing to do here...
             raise
         return response(passthrough)
Ejemplo n.º 2
0
    def get_template(self, name):
        '''
        Load a template

        @param name : Name of template to load, or prioritized list of names
        @type  name : str, or list of str
        
        @return     : ready-to-render Jinja2 template
        @rtype      : jinja2.Template
        
        '''
        from jinja2.exceptions import TemplatesNotFound
        template = None
        try:
            template = self.jenv.get_or_select_template(name)
        except TemplatesNotFound:
            logger.critical('Could not find any template for names: {}'.format(str(name)))
            raise
        return template