Ejemplo n.º 1
0
 def __call__(self, environ, start_response):
     request = Request(environ)
     logger.debug('%s - %s %s' %
                  (request.remote_addr, request.method, request.url))
     urls = self.url_map.bind_to_environ(environ)
     try:
         handler, request.args = urls.match()
         response = self.dispatch_request(handler, request)
     except Exception, e:
         response = self.handle_exception(e, request)
 def __call__(self, environ, start_response):
     request = Request(environ)
     logger.debug('%s - %s %s' %
                  (request.remote_addr, request.method, request.url))
     urls = self.url_map.bind_to_environ(environ)
     try:
         handler, request.args = urls.match()
         response = self.dispatch_request(handler, request)
     except Exception, e:
         response = self.handle_exception(e, request)
Ejemplo n.º 3
0
    def __call__(self, environ, start_response):
        request = Request(environ)
        urls = self.url_map.bind_to_environ(environ)

        try:
            logger.debug('%s - %s %s' %
                         (request.remote_addr, request.method, request.url))
            endpoint, params = urls.match()

            (controller_class, action) = endpoint
            controller = controller_class()
            response = self.dispatch(controller, action, request, params)
        except HTTPException, e:
            response = e
Ejemplo n.º 4
0
    def __call__(self, environ, start_response):
        request = Request(environ)
        urls = self.url_map.bind_to_environ(environ)

        try:
            logger.debug('%s - %s %s' %
                         (request.remote_addr, request.method, request.url))
            endpoint, params = urls.match()

            (controller_class, action) = endpoint
            controller = controller_class()
            response = self.dispatch(controller, action, request, params)
        except HTTPException, e:
            response = e
Ejemplo n.º 5
0
    def handle_exception(self, e, request):
        #TODO: make this handler defined function
        exc_type, exc_value, tb = sys.exc_info()
        assert exc_value is e

        if issubclass(exc_type, LibcloudRestError):
            error = e
            logger.debug('Exception on %s [%s]' %
                         (request.path, request.method),
                         exc_info=(exc_type, exc_value, tb))
        else:
            error = InternalError(detail=str(e))
            logger.error('Exception on %s [%s]' %
                         (request.path, request.method),
                         exc_info=(exc_type, exc_value, tb))
        return self.make_response(error.to_json(), error.http_status_code)
    def handle_exception(self, e, request):
        #TODO: make this handler defined function
        exc_type, exc_value, tb = sys.exc_info()
        assert exc_value is e

        if issubclass(exc_type, LibcloudRestError):
            error = e
            logger.debug('Exception on %s [%s]' % (
                request.path,
                request.method),
                exc_info=(exc_type, exc_value, tb)
            )
        else:
            error = InternalError(detail=str(e))
            logger.error('Exception on %s [%s]' % (
                request.path,
                request.method),
                exc_info=(exc_type, exc_value, tb)
            )
        return self.make_response(error.to_json(), error.http_status_code)
Ejemplo n.º 7
0
class LibcloudRestApp(object):
    """
    FIXME
    """
    url_map = urls

    def dispatch(self, controller, action_name, request, params):
        """

        @param controller:
        @param action_name:
        @param request:
        @param params:
        @return:
        """
        request_header_validator = valid.DictValidator({
            'Content-Length':
            valid.IntegerValidator(max=512),
            'Content-Type':
            valid.ConstValidator('application/json'),
        })
        controller.request = request
        controller.params = params
        action = getattr(controller, action_name)
        try:
            if request.method in ['POST', 'PUT']:
                request_header_validator(dict(request.headers))
            retval = action()
            return retval
        except LibcloudRestError, error:
            return Response(error.to_json(),
                            status=error.http_status_code,
                            mimetype='application/json')
        except BaseException, error:
            logger.debug(traceback.format_exc())
            fake_error = LibcloudRestError()  # FIXME
            return Response(
                fake_error.to_json(),
                status=fake_error.http_status_code,
                mimetype='application/json')  # FIXME: response error generator