Mercurial > hg
changeset 3637:e7639888bb2f
templater: simplify cache and remove filter argument in __call__
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 13 Nov 2006 13:26:57 -0600 |
parents | dfbbb33f3fa3 |
children | 7b064d8bac5e |
files | mercurial/templater.py |
diffstat | 1 files changed, 6 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templater.py Mon Nov 13 13:26:57 2006 -0600 +++ b/mercurial/templater.py Mon Nov 13 13:26:57 2006 -0600 @@ -78,7 +78,7 @@ raise SyntaxError(_("%s:%s: parse error") % (mapfile, i)) def __contains__(self, key): - return key in self.cache + return key in self.cache or key in self.map def __call__(self, t, **map): '''perform expansion. @@ -86,20 +86,18 @@ map is added elements to use during expansion.''' m = self.defaults.copy() m.update(map) - try: - tmpl = self.cache[t] - except KeyError: + if not self.cache.has_key(t): try: - tmpl = self.cache[t] = file(self.map[t]).read() + self.cache[t] = file(self.map[t]).read() except IOError, inst: raise IOError(inst.args[0], _('template file %s: %s') % (self.map[t], inst.args[1])) - return self.template(tmpl, self.filters, **m) + return self.template(self.cache[t], **m) template_re = re.compile(r"(?:(?:#(?=[\w\|%]+#))|(?:{(?=[\w\|%]+})))" r"(\w+)((%\w+)*)((\|\w+)*)[#}]") - def template(self, tmpl, filters={}, **map): + def template(self, tmpl, **map): while tmpl: m = self.template_re.search(tmpl) if m: @@ -128,7 +126,7 @@ elif fl: for f in fl.split("|")[1:]: - v = filters[f](v) + v = self.filters[f](v) yield v tmpl = tmpl[end:]