dulwich-users team mailing list archive
-
dulwich-users team
-
Mailing list archive
-
Message #00097
[PATCH 1/4] Move reference WSGI handler to web.py.
From: Dave Borowitz <dborowitz@xxxxxxxxxx>
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.
Change-Id: I0cbeb7fa878f8567e059409e87b7f4225fda143f
---
NEWS | 2 ++
bin/dul-web | 16 +---------------
dulwich/web.py | 26 ++++++++++++++++++++++++++
3 files changed, 29 insertions(+), 15 deletions(-)
mode change 100644 => 100755 bin/dul-web
diff --git a/NEWS b/NEWS
index f0910a1..0855788 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,8 @@
* Clean up file headers. (Dave Borowitz)
+ * Move reference WSGI handler to web.py. (Dave Borowitz)
+
0.6.0 2010-05-22
diff --git a/bin/dul-web b/bin/dul-web
old mode 100644
new mode 100755
index 15b1a0e..c68a7b2
--- a/bin/dul-web
+++ b/bin/dul-web
@@ -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
diff --git a/dulwich/web.py b/dulwich/web.py
index 633ffea..d1a60d4 100644
--- a/dulwich/web.py
+++ b/dulwich/web.py
@@ -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
--
1.7.0.4
References