diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py --- a/mercurial/hgweb/common.py +++ b/mercurial/hgweb/common.py @@ -78,25 +78,6 @@ def staticfile(directory, fname, req): else: raise ErrorResponse(HTTP_SERVER_ERROR, err.strerror) -def style_map(templatepath, style): - """Return path to mapfile for a given style. - - Searches mapfile in the following locations: - 1. templatepath/style/map - 2. templatepath/map-style - 3. templatepath/map - """ - locations = style and [os.path.join(style, "map"), "map-"+style] or [] - locations.append("map") - if isinstance(templatepath, str): - templatepath = [templatepath] - for path in templatepath: - for location in locations: - mapfile = os.path.join(path, location) - if os.path.isfile(mapfile): - return mapfile - raise RuntimeError("No hgweb templates found in %r" % templatepath) - def paritygen(stripecount, offset=0): """count parity of horizontal stripes for easier reading""" if stripecount and offset: 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 @@ -9,7 +9,7 @@ import os from mercurial import ui, hg, util, hook, error, encoding from mercurial import templater, templatefilters -from common import get_mtime, style_map, ErrorResponse +from common import get_mtime, ErrorResponse from common import HTTP_OK, HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_SERVER_ERROR from common import HTTP_UNAUTHORIZED, HTTP_METHOD_NOT_ALLOWED from request import wsgirequest @@ -37,9 +37,7 @@ class hgweb(object): self.stripecount = 1 # a repo owner may set web.templates in .hg/hgrc to get any file # readable by the user running the CGI script - self.templatepath = self.config("web", "templates", - templater.templatepath(), - untrusted=False) + self.templatepath = self.config('web', 'templates') # The CGI scripts are often run by a user different from the repo owner. # Trust the settings from the .hg/hgrc files by default. @@ -237,7 +235,7 @@ class hgweb(object): start = req.url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) - mapfile = style_map(self.templatepath, style) + mapfile = templater.stylemap(style, self.templatepath) if not self.reponame: self.reponame = (self.config("web", "name") diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py --- a/mercurial/hgweb/hgwebdir_mod.py +++ b/mercurial/hgweb/hgwebdir_mod.py @@ -9,7 +9,7 @@ import os from mercurial.i18n import _ from mercurial import ui, hg, util, templater, templatefilters, error, encoding -from common import ErrorResponse, get_mtime, staticfile, style_map, paritygen,\ +from common import ErrorResponse, get_mtime, staticfile, paritygen,\ get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR from hgweb_mod import hgweb from request import wsgirequest @@ -317,7 +317,7 @@ class hgwebdir(object): style = req.form['style'][0] if self.stripecount is None: self.stripecount = int(config('web', 'stripes', 1)) - mapfile = style_map(templater.templatepath(), style) + mapfile = templater.stylemap(style) tmpl = templater.templater(mapfile, templatefilters.filters, defaults={"header": header, "footer": footer, diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py --- a/mercurial/hgweb/webcommands.py +++ b/mercurial/hgweb/webcommands.py @@ -7,7 +7,7 @@ import os, mimetypes, re, cgi, copy import webutil -from mercurial import error, archival, templatefilters +from mercurial import error, archival, templater, templatefilters from mercurial.node import short, hex from mercurial.util import binary from common import paritygen, staticfile, get_contact, ErrorResponse @@ -610,7 +610,7 @@ def static(web, req, tmpl): # readable by the user running the CGI script static = web.config("web", "static", None, untrusted=False) if not static: - tp = web.templatepath + tp = web.templatepath or templater.templatepath() if isinstance(tp, str): tp = [tp] static = [os.path.join(p, 'static') for p in tp] diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -183,9 +183,32 @@ def templatepath(name=None): return normpaths +def stylemap(style, paths=None): + """Return path to mapfile for a given style. + + Searches mapfile in the following locations: + 1. templatepath/style/map + 2. templatepath/map-style + 3. templatepath/map + """ + + if paths is None: + paths = templatepath() + elif isinstance(paths, str): + paths = [templatepath] + + locations = style and [os.path.join(style, "map"), "map-" + style] or [] + locations.append("map") + for path in paths: + for location in locations: + mapfile = os.path.join(path, location) + if os.path.isfile(mapfile): + return mapfile + + raise RuntimeError("No hgweb templates found in %r" % paths) + def stringify(thing): '''turn nested template iterator into string.''' if hasattr(thing, '__iter__'): return "".join([stringify(t) for t in thing if t is not None]) return str(thing) -