4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
4 # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
5 # |
5 # |
6 # This software may be used and distributed according to the terms |
6 # This software may be used and distributed according to the terms |
7 # of the GNU General Public License, incorporated herein by reference. |
7 # of the GNU General Public License, incorporated herein by reference. |
8 |
8 |
9 import os, mimetypes, re |
9 import os, mimetypes, re, mimetools, cStringIO |
10 from mercurial.node import hex, nullid, short |
10 from mercurial.node import hex, nullid, short |
11 from mercurial.repo import RepoError |
11 from mercurial.repo import RepoError |
12 from mercurial import mdiff, ui, hg, util, archival, patch, hook |
12 from mercurial import mdiff, ui, hg, util, archival, patch, hook |
13 from mercurial import revlog, templater, templatefilters, changegroup |
13 from mercurial import revlog, templater, templatefilters, changegroup |
14 from common import get_mtime, style_map, paritygen, countgen, get_contact |
14 from common import get_mtime, style_map, paritygen, countgen, get_contact |
224 # process the web interface request |
224 # process the web interface request |
225 |
225 |
226 try: |
226 try: |
227 |
227 |
228 tmpl = self.templater(req) |
228 tmpl = self.templater(req) |
229 ctype = tmpl('mimetype', encoding=self.encoding) |
229 try: |
230 ctype = templater.stringify(ctype) |
230 ctype = tmpl('mimetype', encoding=self.encoding) |
|
231 ctype = templater.stringify(ctype) |
|
232 except KeyError: |
|
233 # old templates with inline HTTP headers? |
|
234 if 'mimetype' in tmpl: |
|
235 raise |
|
236 header = tmpl('header', encoding=self.encoding) |
|
237 header_file = cStringIO.StringIO(templater.stringify(header)) |
|
238 msg = mimetools.Message(header_file, 0) |
|
239 ctype = msg['content-type'] |
231 |
240 |
232 if cmd == '': |
241 if cmd == '': |
233 req.form['cmd'] = [tmpl.cache['default']] |
242 req.form['cmd'] = [tmpl.cache['default']] |
234 cmd = req.form['cmd'][0] |
243 cmd = req.form['cmd'][0] |
235 |
244 |
280 staticurl += '/' |
289 staticurl += '/' |
281 |
290 |
282 # some functions for the templater |
291 # some functions for the templater |
283 |
292 |
284 def header(**map): |
293 def header(**map): |
285 yield tmpl('header', encoding=self.encoding, **map) |
294 header = tmpl('header', encoding=self.encoding, **map) |
|
295 if 'mimetype' not in tmpl: |
|
296 # old template with inline HTTP headers |
|
297 header_file = cStringIO.StringIO(templater.stringify(header)) |
|
298 msg = mimetools.Message(header_file, 0) |
|
299 header = header_file.read() |
|
300 yield header |
286 |
301 |
287 def footer(**map): |
302 def footer(**map): |
288 yield tmpl("footer", **map) |
303 yield tmpl("footer", **map) |
289 |
304 |
290 def motd(**map): |
305 def motd(**map): |