Move reference WSGI handler to web.py.
authorDave Borowitz <dborowitz@google.com>
Wed, 21 Jul 2010 11:34:28 +0000 (13:34 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Wed, 21 Jul 2010 11:34:28 +0000 (13:34 +0200)
This is conditionally defined only if wsgiref is available for python
2.4 compatibility. The failure mode is still the same: if wsgiref is not
installed, users can import the web module but not run dul-web.

NEWS
bin/dul-web
dulwich/web.py

diff --git a/NEWS b/NEWS
index e80d30cef48cd13a0b9ca3cab6fc7f16350fa200..5cfd44103359d867d46bf38b7cef2404ec8612da 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -43,6 +43,8 @@
   * Make dul-daemon a trivial wrapper around server functionality.
     (Dave Borowitz)
 
+  * Move reference WSGI handler to web.py. (Dave Borowitz)
+
 
 0.6.0  2010-05-22
 
index 15b1a0ead17d0b01db3396ba1afe71d8083443c1..c68a7b23690e84001ce27f846282a861644acdcd 100644 (file)
@@ -25,27 +25,13 @@ from dulwich.server import DictBackend
 from dulwich.web import (
     logger,
     HTTPGitApplication,
+    HTTPGitRequestHandler,
     )
 from wsgiref.simple_server import (
-    WSGIRequestHandler,
     make_server,
     )
 
 
-class HTTPGitRequestHandler(WSGIRequestHandler):
-    """Handler that uses dulwich's logger for logging exceptions."""
-
-    def log_exception(self, exc_info):
-        logger.exception('Exception happened during processing of request',
-                         exc_info=exc_info)
-
-    def log_message(self, format, *args):
-        logger.info(format, *args)
-
-    def log_error(self, *args):
-        logger.error(*args)
-
-
 # TODO: allow serving on other addresses/ports via command-line flag
 LISTEN_ADDR=''
 PORT = 8000
index 633ffea393ebd2e4f69eea292f711f5c3c8024d2..d1a60d4f29399c22a36adcc07dbaec838810c7a6 100644 (file)
@@ -343,3 +343,29 @@ class HTTPGitApplication(object):
         if handler is None:
             return req.not_found('Sorry, that method is not supported')
         return handler(req, self.backend, mat)
+
+
+# The reference server implementation is based on wsgiref, which is not
+# distributed with python 2.4. If wsgiref is not present, users will not be able
+# to use the HTTP server without a little extra work.
+try:
+    from wsgiref.simple_server import (
+        WSGIRequestHandler,
+        )
+
+    class HTTPGitRequestHandler(WSGIRequestHandler):
+        """Handler that uses dulwich's logger for logging exceptions."""
+
+        def log_exception(self, exc_info):
+            logger.exception('Exception happened during processing of request',
+                             exc_info=exc_info)
+
+        def log_message(self, format, *args):
+            logger.info(format, *args)
+
+        def log_error(self, *args):
+            logger.error(*args)
+except ImportError:
+    # No wsgiref found; don't provide the reference functionality, but leave the
+    # rest of the WSGI-based implementation.
+    pass