예제 #1
0
    def view(cls, *args, **kwargs):
        # Construct request and response wrappers.
        async = cls.meta.asynchronous
        request = http.Request(path=kwargs.get('path', ''), asynchronous=async)
        response = http.Response(asynchronous=async)

        # Defer the execution thread if we're running asynchronously.
        if async:
            # Defer the view to pass of control.
            import gevent
            gevent.spawn(utils.super(Resource, cls).view, request, response)

            # Construct and return a streamer.
            return cls.stream(response, response)

        # Pass control off to the resource handler.
        return utils.super(Resource, cls).view(request, response)
예제 #2
0
    def view(cls, django_request, *args, **kwargs):
        # Construct request and response wrappers.
        async = cls.meta.asynchronous
        path = kwargs.get('path') or ''
        request = http.Request(django_request, path=path, asynchronous=async)
        response = http.Response(asynchronous=async)

        # Defer the execution thread if we're running asynchronously.
        if async:
            # Defer the view to pass of control.
            import gevent
            gevent.spawn(utils.super(Resource, cls).view, request, response)

            # Construct and return the generator response.
            response._handle.content = cls.stream(response, response)
            return response._handle

        # Pass control off to the resource handler.
        result = utils.super(Resource, cls).view(request, response)

        # Configure the response and return it.
        response._handle.content = result
        return response._handle
예제 #3
0
    def view(cls, *args, **kwargs):
        # Initiate the base view request cycle.
        path = kwargs.get('path', '')
        if flask.request.path.endswith('/'):
            # The trailing slash is stripped for fun by werkzeug.
            path += '/'

        # Construct request and response wrappers.
        async = cls.meta.asynchronous
        request = http.Request(path=path, asynchronous=async)
        response = http.Response(asynchronous=async)

        # Defer the execution thread if we're running asynchronously.
        if async:
            # Defer the view to pass of control.
            import gevent
            gevent.spawn(utils.super(Resource, cls).view, request, response)

            # Construct and return the generator response.
            response._handle.response = cls.stream(response, response)
            return response._handle

        # Pass control off to the resource handler.
        result = utils.super(Resource, cls).view(request, response)

        if isinstance(result, collections.Iterator):
            # Construct and return the generator response.
            response._handle.response = result
            return response._handle

        # Configure the response if we received any data.
        if result is not None:
            response._handle.data = result

        # Return the response.
        return response._handle
예제 #4
0
    def route(self, *args, **kwargs):
        # Establish a session.
        self.session = session = self.meta.Session()

        try:
            # Continue on with the cycle.
            result = utils.super(ModelResource, self).route(*args, **kwargs)

            # Commit the session.
            session.commit()

            # Return the result.
            return result

        except:
            # Something occurred; rollback the session.
            session.rollback()

            # Re-raise the exception.
            raise

        finally:
            # Close the session.
            session.close()