def handler(self, request): """Given an Aspen request, return an Aspen response. The default handler uses Resource subclasses to generate responses from simplates on the filesystem. See aspen/resources/__init__.py. You can monkey-patch this method to implement single-page web apps or other things in configure-aspen.py: from aspen import Response def greetings_program(website, request): return Response(200, "Greetings, program!") website.handler = greetings_program """ self.hooks.inbound_early.run(request) gauntlet.run(request) # sets request.fs request.socket = sockets.get(request) self.hooks.inbound_late.run(request) # Look for a Socket.IO socket (http://socket.io/). if isinstance(request.socket, Response): # handshake response = request.socket request.socket = None elif request.socket is None: # non-socket request.resource = resources.get(request) response = request.resource.respond(request) else: # socket response = request.socket.respond(request) return response
def handle(self, request): """Given an Aspen request, return an Aspen response. Aspen uses Resource subclasses to generate responses. See aspen/resources/__init__.py. """ try: try: self.copy_configuration_to(request) request.website = self self.hooks.run('inbound_early', request) gauntlet.run(request) # sets request.fs request.socket = sockets.get(request) self.hooks.run('inbound_late', request) # Look for a Socket.IO socket (http://socket.io/). if isinstance(request.socket, Response): # handshake response = request.socket request.socket = None elif request.socket is None: # non-socket request.resource = resources.get(request) response = request.resource.respond(request) else: # socket response = request.socket.respond(request) except: response = self.handle_error_nicely(request) except Response, response: # Grab the response object in the case where it was raised. In the # case where it was returned, response is set in a try block above. pass
def handler(self, request): """Given an Aspen request, return an Aspen response. The default handler uses Resource subclasses to generate responses from simplates on the filesystem. See aspen/resources/__init__.py. You can monkey-patch this method to implement single-page web apps or other things in configure-aspen.py: from aspen import Response def greetings_program(website, request): return Response(200, "Greetings, program!") website.handler = greetings_program """ self.hooks.inbound_early.run(request) self.check_auth(request) gauntlet.run(request) # sets request.fs request.socket = sockets.get(request) self.hooks.inbound_late.run(request) # Look for a Socket.IO socket (http://socket.io/). if isinstance(request.socket, Response): # handshake response = request.socket request.socket = None elif request.socket is None: # non-socket request.resource = resources.get(request) response = request.resource.respond(request) else: # socket response = request.socket.respond(request) return response
def run_inbound(self, request): """Factored out to support testing. """ self.hooks.inbound_early.run(request) self.check_auth(request) gauntlet.run(request) # sets request.fs request.socket = sockets.get(request) self.hooks.inbound_late.run(request)
def load_simplate(path): """Given an URL path, return resource. """ request = StubRequest(path) request.website = test_website # XXX HACK - aspen.website should be refactored from aspen import gauntlet, sockets test_website.hooks.inbound_early.run(request) gauntlet.run(request) # sets request.fs request.socket = sockets.get(request) test_website.hooks.inbound_late.run(request) return resources.get(request)