##// END OF EJS Templates
templater: replace eval with closure
Matt Mackall -
r8492:d72d1a97 default
parent child Browse files
Show More
@@ -83,14 +83,17 b' class engine(object):'
83 def _filter(self, expr, get, map):
83 def _filter(self, expr, get, map):
84 if expr not in self.cache:
84 if expr not in self.cache:
85 parts = expr.split('|')
85 parts = expr.split('|')
86 filters = parts[1:]
86 val = parts[0]
87 for f in filters:
87 try:
88 if f not in self.filters:
88 filters = [self.filters[f] for f in parts[1:]]
89 raise SyntaxError(_("unknown filter '%s'") % expr)
89 except KeyError, i:
90 calls = '('.join(i for i in reversed(filters))
90 raise SyntaxError(_("unknown filter '%s'") % i[0])
91 end = ')' * len(filters)
91 def apply(get):
92 code = "lambda _get: %s(_get('%s')%s" % (calls, parts[0], end)
92 x = get(val)
93 self.cache[expr] = eval(code, self.filters)
93 for f in filters:
94 x = f(x)
95 return x
96 self.cache[expr] = apply
94 return self.cache[expr](get)
97 return self.cache[expr](get)
95
98
96 def _process(self, tmpl, map):
99 def _process(self, tmpl, map):
General Comments 0
You need to be logged in to leave comments. Login now