Exemplo n.º 1
0
    def resolve_action(self):
        """Resolve the URL's action
    """

        path = self.to_path
        request_type = self.request_type
        handler = router.resolve_path(path, request_type)
        args = self.args
        action = None

        if handler:
            import inspect

            if inspect.isclass(handler):
                handler_class = handler

                request_handler = handler_class()
                # request_handler.initialize(self.request, self.response)

                if request_type == 'get':
                    action = request_handler.get_action(*args)
                elif request_type == 'post':
                    action = request_handler.post_action(*args)
                elif request_type == 'head':
                    action = request_handler.head_action(*args)
                elif request_type == 'options':
                    action = request_handler.options_action(*args)
                elif request_type == 'put':
                    action = request_handler.put_action(*args)
                elif request_type == 'delete':
                    action = request_handler.delete_action(*args)
                elif request_type == 'trace':
                    action = request_handler.trace_action(*args)
                else:
                    # use get as default
                    action = request_handler.get_action(*args)

            elif inspect.isfunction(handler):
                handler_func = handler
                action = handler_func(self, *args)

        else:
            #exception happend
            raise CannotResolvePath(path)

        return action
Exemplo n.º 2
0
 def _handle_request(self, request_type, *args):
   path = self.request.path
   handler = router.resolve_path(path, request_type)
   
   if handler:
     import inspect
     
     if inspect.isclass(handler):
       handler_class = handler
       
       request_handler = handler_class()
       request_handler.initialize(self.request, self.response)
       
       if request_type == 'get':
         request_handler.get(*args)
       elif request_type == 'post':
         request_handler.post(*args)
       elif request_type == 'head':
         request_handler.head(*args)
       elif request_type == 'options':
         request_handler.options(*args)
       elif request_type == 'put':
         request_handler.put(*args)
       elif request_type == 'delete':
         request_handler.delete(*args)
       elif request_type == 'trace':
         request_handler.trace(*args)
       else:
         request_handler.error(501)
       
     elif inspect.isfunction(handler):
       handler_func = handler
       api_enabled(handler_func)(self, *args)
       
   else:
     #exception happend  
     raise CannotResolvePath(path)
Exemplo n.º 3
0
    def _handle_request(self, request_type, *args):
        path = self.request.path
        handler = router.resolve_path(path, request_type)

        if handler:
            import inspect

            if inspect.isclass(handler):
                handler_class = handler

                request_handler = handler_class()
                request_handler.initialize(self.request, self.response)

                if request_type == 'get':
                    request_handler.get(*args)
                elif request_type == 'post':
                    request_handler.post(*args)
                elif request_type == 'head':
                    request_handler.head(*args)
                elif request_type == 'options':
                    request_handler.options(*args)
                elif request_type == 'put':
                    request_handler.put(*args)
                elif request_type == 'delete':
                    request_handler.delete(*args)
                elif request_type == 'trace':
                    request_handler.trace(*args)
                else:
                    request_handler.error(501)

            elif inspect.isfunction(handler):
                handler_func = handler
                api_enabled(handler_func)(self, *args)

        else:
            #exception happend
            raise CannotResolvePath(path)