# HG changeset patch # User paulb # Date 1075649305 0 # Node ID b6e0befece75d0507af4064e4bab6c0c12b9078a # Parent 95501d8e090b27a81730f35defa005c4bdd5eb8e [project @ 2004-02-01 15:28:25 by paulb] Implemented simple adapters for mod_python and Twisted. diff -r 95501d8e090b -r b6e0befece75 WebStack/Adapters/ModPython.py --- a/WebStack/Adapters/ModPython.py Sun Feb 01 15:28:08 2004 +0000 +++ b/WebStack/Adapters/ModPython.py Sun Feb 01 15:28:25 2004 +0000 @@ -5,8 +5,23 @@ """ import WebStack.ModPython +from mod_python import apache -# NOTE: Implement a handler function which converts a request to a transaction -# NOTE: and invokes application resources. +def dispatch(request, resource): + + "Dispatch the given 'request' to the root application-specific 'resource'." + + trans = WebStack.ModPython.Transaction(request) + try: + # NOTE: Resource pooling may be appropriate. + + resource.respond(trans) + return apache.OK + except: + + # NOTE: Error conditions should be investigated further, along with + # NOTE: other response states. + + return apache.INTERNAL_SERVER_ERROR # vim: tabstop=4 expandtab shiftwidth=4 diff -r 95501d8e090b -r b6e0befece75 WebStack/Adapters/Twisted.py --- a/WebStack/Adapters/Twisted.py Sun Feb 01 15:28:08 2004 +0000 +++ b/WebStack/Adapters/Twisted.py Sun Feb 01 15:28:25 2004 +0000 @@ -5,8 +5,31 @@ """ import WebStack.Twisted +import twisted.web.resource -# NOTE: Implement the module code which registers the various components with -# NOTE: the framework. +class Dispatcher(twisted.web.resource.Resource): + + "A class dispatching requests to WebStack resources." + + isLeaf = 1 + + def __init__(self, resource): + + "Initialise the root application-specific 'resource'." + + twisted.web.resource.Resource.__init__(self) + self.webstack_resource = resource + + def getChild(self, path, request): + raise NotImplementedError, "getChild" + + def render(self, request): + + "Dispatch the given 'request' to the root application-specific resource." + + trans = WebStack.Twisted.Transaction(request) + self.webstack_resource.respond(trans) + request.finish() + return twisted.web.server.NOT_DONE_YET # vim: tabstop=4 expandtab shiftwidth=4