Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hgweb/hgweb_mod.py @ 6379:d2bb66a8a435
hgweb: add compatibility code for old templates
Up to changeset 3340aa5a64f7, HTTP headers were expected to be embedded
in the "headers" template. Since that changeset, the content-type is
supposed to be defined as the "mimetype" template in the map file.
This changeset makes sure the old templates still work.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Mon, 24 Mar 2008 13:45:01 -0300 |
parents | 31a01e3d99cc |
children | a1007f7b9b7b 8189e03adb44 |
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py Mon Mar 24 11:12:57 2008 -0500 +++ b/mercurial/hgweb/hgweb_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, mimetypes, re +import os, mimetypes, re, mimetools, cStringIO from mercurial.node import hex, nullid, short from mercurial.repo import RepoError from mercurial import mdiff, ui, hg, util, archival, patch, hook @@ -226,8 +226,17 @@ try: tmpl = self.templater(req) - ctype = tmpl('mimetype', encoding=self.encoding) - ctype = templater.stringify(ctype) + try: + ctype = tmpl('mimetype', encoding=self.encoding) + ctype = templater.stringify(ctype) + except KeyError: + # old templates with inline HTTP headers? + if 'mimetype' in tmpl: + raise + header = tmpl('header', encoding=self.encoding) + header_file = cStringIO.StringIO(templater.stringify(header)) + msg = mimetools.Message(header_file, 0) + ctype = msg['content-type'] if cmd == '': req.form['cmd'] = [tmpl.cache['default']] @@ -282,7 +291,13 @@ # some functions for the templater def header(**map): - yield tmpl('header', encoding=self.encoding, **map) + header = tmpl('header', encoding=self.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)