diff -r f0f830114a9b -r d2bb66a8a435 mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py Mon Mar 24 11:12:57 2008 -0500 +++ b/mercurial/hgweb/hgwebdir_mod.py Mon Mar 24 13:45:01 2008 -0300 @@ -6,7 +6,7 @@ # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -import os +import os, mimetools, cStringIO from mercurial.i18n import gettext as _ from mercurial.repo import RepoError from mercurial import ui, hg, util, templater, templatefilters @@ -81,8 +81,17 @@ virtual = req.env.get("PATH_INFO", "").strip('/') tmpl = self.templater(req) - ctype = tmpl('mimetype', encoding=util._encoding) - ctype = templater.stringify(ctype) + try: + ctype = tmpl('mimetype', encoding=util._encoding) + ctype = templater.stringify(ctype) + except KeyError: + # old templates with inline HTTP headers? + if 'mimetype' in tmpl: + raise + header = tmpl('header', encoding=util._encoding) + header_file = cStringIO.StringIO(templater.stringify(header)) + msg = mimetools.Message(header_file, 0) + ctype = msg['content-type'] # a static file if virtual.startswith('static/') or 'static' in req.form: @@ -246,7 +255,13 @@ def templater(self, req): def header(**map): - yield tmpl('header', encoding=util._encoding, **map) + header = tmpl('header', encoding=util._encoding, **map) + if 'mimetype' not in tmpl: + # old template with inline HTTP headers + header_file = cStringIO.StringIO(templater.stringify(header)) + msg = mimetools.Message(header_file, 0) + header = header_file.read() + yield header def footer(**map): yield tmpl("footer", **map)