Author: fw
Date: 2009-10-11 10:23:56 +0000 (Sun, 11 Oct 2009)
New Revision: 12983

Modified:
   lib/python/web_support.py
Log:
lib/python/web_support.py (WebServiceBase): new class

Factored common functionality into base class, in preparation of
alternative invocation methods.


Modified: lib/python/web_support.py
===================================================================
--- lib/python/web_support.py   2009-10-10 23:42:52 UTC (rev 12982)
+++ lib/python/web_support.py   2009-10-11 10:23:56 UTC (rev 12983)
@@ -599,10 +599,9 @@
         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,12 +615,8 @@
 
         The method is expected to return a HTMLResult object.
         """
-        self.__router.register(path, method)
+        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))
-
     def html_dtd(self):
         """Returns the DOCTYPE declaration to be used for HTML documents.
         Can be overridden."""
@@ -654,6 +649,16 @@
         """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 @@
         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


_______________________________________________
Secure-testing-commits mailing list
Secure-testing-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/secure-testing-commits

Reply via email to