# HG changeset patch # User Bryan O'Sullivan # Date 2007-11-28 17:39:17 # Node ID d61fea133f2d2859550a352279434a446d6bfa18 # Parent 72cb6bde5355799ddcc4b35830eacf573d17c06b hgweb: fix breaking tests on Python < 2.5 diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py --- a/mercurial/hgweb/common.py +++ b/mercurial/hgweb/common.py @@ -12,11 +12,18 @@ class ErrorResponse(Exception): 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") diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py --- a/mercurial/hgweb/hgweb_mod.py +++ b/mercurial/hgweb/hgweb_mod.py @@ -13,6 +13,7 @@ from mercurial.i18n import gettext as _ 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] != "/": diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -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 @@ class _wsgirequest(object): 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