comparison markup/template.py @ 92:3b75c6730b29

More performance improvements... this time for whitespace normalization and template loops.
author cmlenz
date Thu, 20 Jul 2006 23:06:36 +0000
parents 242610137d1f
children f648152df7fd
comparison
equal deleted inserted replaced
91:e82d1bb07464 92:3b75c6730b29
365 365
366 def __call__(self, stream, ctxt, directives): 366 def __call__(self, stream, ctxt, directives):
367 iterable = self.expr.evaluate(ctxt) 367 iterable = self.expr.evaluate(ctxt)
368 if iterable is not None: 368 if iterable is not None:
369 stream = list(stream) 369 stream = list(stream)
370 scope = {}
371 targets = self.targets
370 for item in iter(iterable): 372 for item in iter(iterable):
371 if len(self.targets) == 1: 373 if len(targets) == 1:
372 item = [item] 374 scope[targets[0]] = item
373 scope = {} 375 else:
374 for idx, name in enumerate(self.targets): 376 for idx, name in enumerate(targets):
375 scope[name] = item[idx] 377 scope[name] = item[idx]
376 ctxt.push(**scope) 378 ctxt.push(**scope)
377 for event in _apply_directives(stream, ctxt, directives): 379 for event in _apply_directives(stream, ctxt, directives):
378 yield event 380 yield event
379 ctxt.pop() 381 ctxt.pop()
380 382
879 substream = _apply_directives(substream, ctxt, directives) 881 substream = _apply_directives(substream, ctxt, directives)
880 for filter_ in (self._eval, self._match, self._flatten): 882 for filter_ in (self._eval, self._match, self._flatten):
881 substream = filter_(substream, ctxt) 883 substream = filter_(substream, ctxt)
882 for event in substream: 884 for event in substream:
883 yield event 885 yield event
884 continue
885 else: 886 else:
886 yield kind, data, pos 887 yield kind, data, pos
887 888
888 def _match(self, stream, ctxt=None, match_templates=None): 889 def _match(self, stream, ctxt=None, match_templates=None):
889 """Internal stream filter that applies any defined match templates 890 """Internal stream filter that applies any defined match templates
894 895
895 for kind, data, pos in stream: 896 for kind, data, pos in stream:
896 897
897 # We (currently) only care about start and end events for matching 898 # We (currently) only care about start and end events for matching
898 # We might care about namespace events in the future, though 899 # We might care about namespace events in the future, though
899 if kind not in (START, END): 900 if not match_templates or kind not in (START, END):
900 yield kind, data, pos 901 yield kind, data, pos
901 continue 902 continue
902 903
903 for idx, (test, path, template, directives) in \ 904 for idx, (test, path, template, directives) in \
904 enumerate(match_templates): 905 enumerate(match_templates):
Copyright (C) 2012-2017 Edgewall Software