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)
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
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
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()