47 self.filters = filters |
47 self.filters = filters |
48 self.defaults = defaults |
48 self.defaults = defaults |
49 self.cache = {} |
49 self.cache = {} |
50 self.parsecache = {} |
50 self.parsecache = {} |
51 |
51 |
52 def process(self, t, map): |
52 def process(self, t, mapping): |
53 '''Perform expansion. t is name of map element to expand. map contains |
53 '''Perform expansion. t is name of map element to expand. mapping contains |
54 added elements for use during expansion. Is a generator.''' |
54 added elements for use during expansion. Is a generator.''' |
55 if t not in self.parsecache: |
55 if t not in self.parsecache: |
56 tmpl = self.loader(t) |
56 tmpl = self.loader(t) |
57 self.parsecache[t] = self._parse(tmpl) |
57 self.parsecache[t] = self._parse(tmpl) |
58 parsed = self.parsecache[t] |
58 parsed = self.parsecache[t] |
59 iters = [self._process(parsed, map)] |
59 iters = [self._process(parsed, mapping)] |
60 while iters: |
60 while iters: |
61 try: |
61 try: |
62 item = iters[0].next() |
62 item = iters[0].next() |
63 except StopIteration: |
63 except StopIteration: |
64 iters.pop(0) |
64 iters.pop(0) |
205 except IOError, inst: |
205 except IOError, inst: |
206 raise IOError(inst.args[0], _('template file %s: %s') % |
206 raise IOError(inst.args[0], _('template file %s: %s') % |
207 (self.map[t][1], inst.args[1])) |
207 (self.map[t][1], inst.args[1])) |
208 return self.cache[t] |
208 return self.cache[t] |
209 |
209 |
210 def __call__(self, t, **map): |
210 def __call__(self, t, **mapping): |
211 ttype = t in self.map and self.map[t][0] or 'default' |
211 ttype = t in self.map and self.map[t][0] or 'default' |
212 proc = self.engines.get(ttype) |
212 proc = self.engines.get(ttype) |
213 if proc is None: |
213 if proc is None: |
214 proc = engines[ttype](self.load, self.filters, self.defaults) |
214 proc = engines[ttype](self.load, self.filters, self.defaults) |
215 self.engines[ttype] = proc |
215 self.engines[ttype] = proc |
216 |
216 |
217 stream = proc.process(t, map) |
217 stream = proc.process(t, mapping) |
218 if self.minchunk: |
218 if self.minchunk: |
219 stream = util.increasingchunks(stream, min=self.minchunk, |
219 stream = util.increasingchunks(stream, min=self.minchunk, |
220 max=self.maxchunk) |
220 max=self.maxchunk) |
221 return stream |
221 return stream |
222 |
222 |