# HG changeset patch # User paulb # Date 1137367227 0 # Node ID 6b5f9c83c1928725f4eb0644cd97b7f8244d088d # Parent 830490f109f0727a7cd1a6f28252d41c2b22fd21 [project @ 2006-01-15 23:20:27 by paulb] Made the address parameter a consistent part of all deploy functions. Added deploy function support in Django, JavaServlet, ModPython and Webware (for Webware > 0.8.1). Fixed virtual path support for Django. diff -r 830490f109f0 -r 6b5f9c83c192 WebStack/Adapters/CGI.py --- a/WebStack/Adapters/CGI.py Sun Jan 15 23:18:29 2006 +0000 +++ b/WebStack/Adapters/CGI.py Sun Jan 15 23:20:27 2006 +0000 @@ -24,7 +24,8 @@ from WebStack.Generic import EndOfResponse import sys, os -def deploy(resource, authenticator=None, input=None, output=None, env=None, handle_errors=1): +def deploy(resource, authenticator=None, input=None, output=None, env=None, + address=None, handle_errors=1): """ Dispatch to the root application-specific 'resource'. Employ the optional @@ -34,6 +35,8 @@ environment respectively. Note that 'env' must evaluate to true for it to replace the default. The optional 'handle_errors' parameter (if true) causes handlers to deal with uncaught exceptions cleanly. + + The optional 'address' parameter is deliberately ignored. """ trans = WebStack.CGI.Transaction(input or sys.stdin, output or sys.stdout, diff -r 830490f109f0 -r 6b5f9c83c192 WebStack/Adapters/Django.py --- a/WebStack/Adapters/Django.py Sun Jan 15 23:18:29 2006 +0000 +++ b/WebStack/Adapters/Django.py Sun Jan 15 23:20:27 2006 +0000 @@ -23,16 +23,36 @@ import WebStack.Django from WebStack.Generic import EndOfResponse -def respond(request, resource, authenticator=None, handle_errors=1): +def deploy(resource, authenticator=None, address=None, handle_errors=1): + + """ + Deploy the given 'resource', employing the optional 'authenticator' to + protect it. The optional 'handle_errors' parameter (if true) causes handlers + to deal with uncaught exceptions cleanly. + + The optional 'address' parameter is deliberately ignored. + """ + + def _deploy(request, *args, **kw): + return respond(request, resource, authenticator=authenticator, + virtual_path_info=kw.get("vp"), handle_errors=handle_errors) + return _deploy + +def respond(request, resource, authenticator=None, virtual_path_info=None, handle_errors=1): """ Dispatch to the root application-specific 'resource'. Employ the optional - 'authenticator' to control access to the resource. The optional - 'handle_errors' parameter (if true) causes handlers to deal with uncaught - exceptions cleanly. + 'authenticator' to control access to the resource. Define the optional + 'virtual_path_info' as the path information considered to belong to the + given 'resource'. + + The optional 'handle_errors' parameter (if true) causes handlers to deal + with uncaught exceptions cleanly. """ trans = WebStack.Django.Transaction(request) + if virtual_path_info: + trans.set_virtual_path_info(virtual_path_info) try: if authenticator is None or authenticator.authenticate(trans): diff -r 830490f109f0 -r 6b5f9c83c192 WebStack/Adapters/JavaServlet.py --- a/WebStack/Adapters/JavaServlet.py Sun Jan 15 23:18:29 2006 +0000 +++ b/WebStack/Adapters/JavaServlet.py Sun Jan 15 23:20:27 2006 +0000 @@ -22,6 +22,35 @@ import WebStack.JavaServlet from WebStack.Generic import EndOfResponse +from javax.servlet.http import HttpServlet + +def deploy(resource, authenticator=None, address=None, handle_errors=1): + + """ + Deploy the given 'resource' and optional 'authenticator'. + The optional 'handle_errors' flag, if set to false, causes tracebacks to be + displayed in the browser. + + The optional 'address' parameter is deliberately ignored. + """ + + # NOTE: Since jython 2.1 does not support the nested scope mechanisms + # NOTE: required to just drop the above parameters into methods even as + # NOTE: default parameters, we employ class attributes. + + class _Deploy(HttpServlet): + def __init__(self): + HttpServlet.__init__(self) + self.dispatcher = Dispatcher(self.resource, self.authenticator, self.handle_errors) + + def service(self, request, response): + self.dispatcher.service(request, response) + + _Deploy.resource = resource + _Deploy.authenticator = authenticator + _Deploy.handle_errors = handle_errors + + return _Deploy class Dispatcher: diff -r 830490f109f0 -r 6b5f9c83c192 WebStack/Adapters/ModPython.py --- a/WebStack/Adapters/ModPython.py Sun Jan 15 23:18:29 2006 +0000 +++ b/WebStack/Adapters/ModPython.py Sun Jan 15 23:20:27 2006 +0000 @@ -24,6 +24,22 @@ from WebStack.Generic import EndOfResponse from mod_python import apache +def deploy(resource, authenticator=None, address=None, handle_errors=1): + + """ + Deploy the given 'resource' and optional 'authenticator'. + The optional 'handle_errors' flag, if set to false, causes tracebacks to be + displayed in the browser. + + The optional 'address' parameter is deliberately ignored. + """ + + def _respond(request): + return respond(request, resource, handle_errors=handle_errors) + def _authenticate(request): + return authenticate(request, authenticator, handle_errors=handle_errors) + return _respond, _authenticate + def respond(request, resource, handle_errors=1): """ diff -r 830490f109f0 -r 6b5f9c83c192 WebStack/Adapters/Webware.py --- a/WebStack/Adapters/Webware.py Sun Jan 15 23:18:29 2006 +0000 +++ b/WebStack/Adapters/Webware.py Sun Jan 15 23:20:27 2006 +0000 @@ -74,6 +74,11 @@ return WebStackServlet(self.webstack_resource, self.webstack_authenticator, self.handle_errors) + # Convenience function. + + def deploy(resource, authenticator=None, address=None, handle_errors=1): + return WebStackURLParser(resource, authenticator=authenticator, handle_errors=handle_errors) + # For Webware 0.8.1 and earlier, employ servlet factories and servlets. from WebKit.ServletFactory import ServletFactory