diff options
author | Florian Weimer <fw@deneb.enyo.de> | 2009-10-11 10:23:56 +0000 |
---|---|---|
committer | Florian Weimer <fw@deneb.enyo.de> | 2009-10-11 10:23:56 +0000 |
commit | 48f5d929f223e62304640fd8eff34a40f52c8440 (patch) | |
tree | 6593e97570e69d9d64957919fbab8839a69c5de4 /lib/python/web_support.py | |
parent | 075cad698835b01ac5158fff1ce8eaf6dce1af8b (diff) |
lib/python/web_support.py (WebServiceBase): new class
Factored common functionality into base class, in preparation of
alternative invocation methods.
git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@12983 e39458fd-73e7-0310-bf30-c45bca0a0e42
Diffstat (limited to 'lib/python/web_support.py')
-rw-r--r-- | lib/python/web_support.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/python/web_support.py b/lib/python/web_support.py index d4e10ccb90..4c07cbf2ba 100644 --- a/lib/python/web_support.py +++ b/lib/python/web_support.py @@ -599,10 +599,9 @@ class BinaryResult(Result): write("Content-Type: %s\n\n" % self.mimetype) write(self.contents) -class WebService(Service): - def __init__(self, socket_name): - Service.__init__(self, socket_name) - self.__router = PathRouter() +class WebServiceBase: + def __init__(self): + self.router = PathRouter() def register(self, path, method): """Requests that method is invoked if path is encountered. @@ -616,11 +615,7 @@ class WebService(Service): The method is expected to return a HTMLResult object. """ - self.__router.register(path, method) - - def __writeError(self, result, code, msg): - result.write('Status: %d\nContent-Type: text/plain\n\n%s\n' - % (code, msg)) + self.router.register(path, method) def html_dtd(self): """Returns the DOCTYPE declaration to be used for HTML documents. @@ -654,6 +649,16 @@ class WebService(Service): """Invoked by handle prior to calling the registered handler.""" pass +class WebService(Service, WebServiceBase): + "CGI service implemented using servinvoke" + def __init__(self, socket_name): + Service.__init__(self, socket_name) + WebServiceBase.__init__(self) + + def __writeError(self, result, code, msg): + result.write('Status: %d\nContent-Type: text/plain\n\n%s\n' + % (code, msg)) + def handle(self, args, environment, data, result): params = cgi.parse(data, environment) path = environment.get('PATH_INFO', '') @@ -664,7 +669,7 @@ class WebService(Service): script_name = environment.get('SCRIPT_NAME', '') try: - (method, remaining) = self.__router.get(path) + (method, remaining) = self.router.get(path) except InvalidPath: self.__writeError(result, 404, "page not found") return |