Example #1
0
File: wsgi.py Project: jamslevy/PQ
 def get(self):
     from utils.utils import tpl_path
     from utils.webapp import template
     path = tpl_path('utils/404.html')
     template_values = {'no_load': True}
     response = Response()
     response.set_status(404)
     response.out.write(template.render(path, template_values))
Example #2
0
File: wsgi.py Project: jamslevy/PQ
 def __call__(self, environ, start_response):
     """Called by WSGI when a request comes in."""
     request = Request(environ)
     response = Response()
     WSGIApplication.active_instance = self
     # Match the path against registered routes.
     #return environ['HTTP_USER_AGENT']#: redirect('browser_error')
     kargs = self.mapper.match(request.path)
     if kargs is None:
         #nf = NotFoundPageHandler()
         #nf.get()
         raise TypeError('No routes match. Provide a fallback to avoid this.')
     # Extract the module and controller names from the route.
     try:
         module_name, class_name = kargs['controller'].split(':', 1)
         del kargs['controller']
     except:
         raise TypeError('Controller is not set, or not formatted in the form "my.module.name:MyControllerName".')
     # Initialize matched controller from given module.
     __import__(module_name)
     module = sys.modules[module_name]
     controller = getattr(module, class_name)()
     controller.initialize(request, response)
     # Use the action set in the route, or the HTTP method.
     """
     if 'action' in kargs:
         print ""
         print environ['REQUEST_METHOD'].lower()
         action = kargs['action']
         del kargs['action']
     else:
         action = environ['REQUEST_METHOD'].lower()
         if action not in ['get', 'post', 'head', 'options', 'put', 'delete', 'trace']:
             action = None
     """
     action = environ['REQUEST_METHOD'].lower()
     if controller and action:
         try:
             # Execute the requested action, passing the route dictionary as
             # named parameters.
             method = getattr(controller, action)
             method()
         except Exception, e:
             controller.handle_exception(e, self.__debug)  
         response.wsgi_write(start_response)
         return ['']