templater: simplify cache and remove filter argument in __call__
authorMatt Mackall <mpm@selenic.com>
Mon, 13 Nov 2006 13:26:57 -0600
changeset 3637 e7639888bb2f
parent 3636 dfbbb33f3fa3
child 3638 7b064d8bac5e
templater: simplify cache and remove filter argument in __call__
mercurial/templater.py
--- 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:]