コード例 #1
0
ファイル: wsgi.py プロジェクト: philpeace/Pointy-Pointy
    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.
        kargs = self.mapper.match(request.path)

        logging.critical('request.path = '+str(request.path))
        logging.critical('initial kargs = '+str(kargs))

        try:
            if kargs is None or 'controller' not in kargs:
                logging.info('kargs is None')
                kargs = dict(controller='Error', status='404')

            module_name, class_name = Manager.getModuleAndControllerNames(kargs['controller'])

            del kargs['controller']

            logging.info('module_name = ' + module_name)
            logging.info('class_name = ' + class_name)
        except Exception, e:
            logging.info('CRITICAL: ' + str(e))
            raise TypeError('Controller is not set, or not formatted in the form "my.module.name:MyControllerName".' + str(e))
コード例 #2
0
ファイル: Controller.py プロジェクト: philpeace/Pointy-Pointy
    def transfer(self, controller, action, **kargs):
        """Transfers control to another Controller

        Args:
          controller: The module_name:class_name of the controller
          action: The name of the action
          kargs: Arguments to pass to the action
        """

        module_name, class_name = Manager.getModuleAndControllerNames(controller)

#        if controller.find(':') == -1:
#            module_name = 'controllers.%s' % controller
#            class_name = controller
#        else:
#            module_name, class_name = controller.split(':', 1)

        __import__(module_name)
        module = sys.modules[module_name]

        if (module is not None and hasattr(module, class_name)):
            c = getattr(module, class_name)(self.request, self.response)
        else:
            raise ImportError('Controller %s could not be initialized.' % (controller))

        if kargs is not None:
            getattr(c, action)(**kargs)
        else:
            getattr(c, action)()