hgweb: fix breaking tests on Python < 2.5
authorBryan O'Sullivan <bos@serpentine.com>
Wed, 28 Nov 2007 09:39:17 -0800
changeset 5563 d61fea133f2d
parent 5562 72cb6bde5355
child 5564 b4af2dd9868a
hgweb: fix breaking tests on Python < 2.5
mercurial/hgweb/common.py
mercurial/hgweb/hgweb_mod.py
mercurial/hgweb/request.py
--- a/mercurial/hgweb/common.py	Wed Nov 28 08:39:05 2007 -0800
+++ b/mercurial/hgweb/common.py	Wed Nov 28 09:39:17 2007 -0800
@@ -12,11 +12,18 @@
     def __init__(self, code, message=None):
         Exception.__init__(self)
         self.code = code
-        if message is None:
-            from httplib import responses
-            self.message = responses.get(code, 'Error')
+        if message:
+            self.message = message
         else:
-            self.message = message
+            self.message = _statusmessage(code)
+
+def _statusmessage(code):
+    from BaseHTTPServer import BaseHTTPRequestHandler
+    responses = BaseHTTPRequestHandler.responses
+    return responses.get(code, ('Error', 'Unknown error'))[0]
+    
+def statusmessage(code):
+    return '%d %s' % (code, _statusmessage(code))
 
 def get_mtime(repo_path):
     store_path = os.path.join(repo_path, ".hg")
--- a/mercurial/hgweb/hgweb_mod.py	Wed Nov 28 08:39:05 2007 -0800
+++ b/mercurial/hgweb/hgweb_mod.py	Wed Nov 28 09:39:17 2007 -0800
@@ -13,6 +13,7 @@
 from mercurial import mdiff, ui, hg, util, archival, streamclone, patch
 from mercurial import revlog, templater
 from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen
+from common import statusmsg
 
 def _up(p):
     if p[0] != "/":
--- a/mercurial/hgweb/request.py	Wed Nov 28 08:39:05 2007 -0800
+++ b/mercurial/hgweb/request.py	Wed Nov 28 09:39:17 2007 -0800
@@ -8,7 +8,7 @@
 
 import socket, cgi, errno
 from mercurial.i18n import gettext as _
-from common import ErrorResponse
+from common import ErrorResponse, statusmessage
 
 class wsgiapplication(object):
     def __init__(self, destmaker):
@@ -53,15 +53,10 @@
                 if self.server_write is None:
                     if not self.headers:
                         raise RuntimeError("request.write called before headers sent (%s)." % thing)
-                    code = None
                     if isinstance(status, ErrorResponse):
-                        code = status.code
+                        status = statusmessage(status.code)
                     elif isinstance(status, int):
-                        code = status
-                    if code:
-                        from httplib import responses
-                        status = '%d %s' % (
-                            code, responses.get(code, 'Error'))
+                        status = statusmessage(status)
                     self.server_write = self.start_response(status,
                                                             self.headers)
                     self.start_response = None