Show More
@@ -48,6 +48,7 b' class engine(object):' | |||
|
48 | 48 | self.loader = loader |
|
49 | 49 | self.filters = filters |
|
50 | 50 | self.defaults = defaults |
|
51 | self.cache = {} | |
|
51 | 52 | |
|
52 | 53 | def process(self, t, map): |
|
53 | 54 | '''Perform expansion. t is name of map element to expand. map contains |
@@ -80,11 +81,17 b' class engine(object):' | |||
|
80 | 81 | yield self.process(format, lm) |
|
81 | 82 | |
|
82 | 83 | def _filter(self, expr, get, map): |
|
84 | if expr not in self.cache: | |
|
83 | 85 | parts = expr.split('|') |
|
84 |
|
|
|
85 |
for f in |
|
|
86 |
|
|
|
87 | return v | |
|
86 | filters = parts[1:] | |
|
87 | for f in filters: | |
|
88 | if f not in self.filters: | |
|
89 | raise SyntaxError(_("unknown filter '%s'") % expr) | |
|
90 | calls = '('.join(i for i in reversed(filters)) | |
|
91 | end = ')' * len(filters) | |
|
92 | code = "lambda _get: %s(_get('%s')%s" % (calls, parts[0], end) | |
|
93 | self.cache[expr] = eval(code, self.filters) | |
|
94 | return self.cache[expr](get) | |
|
88 | 95 | |
|
89 | 96 | def _process(self, tmpl, map): |
|
90 | 97 | '''Render a template. Returns a generator.''' |
General Comments 0
You need to be logged in to leave comments.
Login now