# HG changeset patch # User cmlenz # Date 1150824692 0 # Node ID d88358f719fa45d729fea3bcf4920897e1aff2d8 # Parent 2483fe549959747640d071bcd08345de787f9b98 Separate match and eval filters from the include and user-supplied filters. diff --git a/examples/includes/run.py b/examples/includes/run.py --- a/examples/includes/run.py +++ b/examples/includes/run.py @@ -1,7 +1,6 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from datetime import datetime, timedelta import os import sys import timing diff --git a/markup/path.py b/markup/path.py --- a/markup/path.py +++ b/markup/path.py @@ -176,8 +176,6 @@ stack = [0] # stack of cursors into the location path def _test(kind, data, pos): - #print '\nTracker %r test [%s] %r' % (self, kind, data) - if not stack: return False @@ -191,7 +189,6 @@ matched = False closure, node_test, predicates = self.steps[stack[-1]] - #print ' Testing against %r' % node_test matched = node_test(kind, data, pos) if matched and predicates: for predicate in predicates: @@ -201,10 +198,8 @@ if matched: if stack[-1] == len(self.steps) - 1: - #print ' Last step %r... returned %r' % (node_test, matched) return matched - #print ' Matched intermediate step %r... proceed to next step %r' % (node_test, self.steps[stack[-1] + 1]) stack[-1] += 1 elif kind is Stream.START and not closure: diff --git a/markup/template.py b/markup/template.py --- a/markup/template.py +++ b/markup/template.py @@ -587,7 +587,7 @@ else: self.filepath = '' - self.filters = [self._eval, self._match] + self.filters = [] self.parse() def __repr__(self): @@ -692,7 +692,7 @@ yield result else: yield Stream.TEXT, group.replace('$$', '$'), \ - (lineno, offset) + (filename, lineno, offset) return _interpolate(text) _interpolate = classmethod(_interpolate) @@ -703,7 +703,8 @@ if not hasattr(ctxt, '_match_templates'): ctxt._match_templates = [] - return Stream(self._flatten(self.stream, ctxt)) + stream = self._match(self._eval(self.stream, ctxt), ctxt) + return Stream(self._flatten(stream, ctxt)) def _eval(self, stream, ctxt=None): for kind, data, pos in stream: @@ -726,7 +727,7 @@ value = filter(lambda x: x is not None, values) if not value: continue - new_attrib.append((name, ''.join(value))) + new_attrib.append((name, u''.join(value))) yield kind, (tag, Attributes(new_attrib)), pos elif kind is Template.EXPR: @@ -738,7 +739,7 @@ # succeeds, and the string will be chopped up into individual # characters if isinstance(result, basestring): - yield Stream.TEXT, result, pos + yield Stream.TEXT, unicode(result), pos else: # Test if the expression evaluated to an iterable, in which # case we yield the individual items @@ -752,10 +753,9 @@ else: yield kind, data, pos - def _flatten(self, stream, ctxt=None, apply_filters=True): - if apply_filters: - for filter_ in self.filters: - stream = filter_(iter(stream), ctxt) + def _flatten(self, stream, ctxt=None): + for filter_ in self.filters: + stream = filter_(iter(stream), ctxt) try: for kind, data, pos in stream: if kind is Template.SUB: @@ -766,6 +766,7 @@ directives.reverse() for directive in directives: substream = directive(iter(substream), ctxt) + substream = self._match(self._eval(substream, ctxt), ctxt) for event in self._flatten(substream, ctxt): yield event continue @@ -808,10 +809,9 @@ # enable the path to keep track of the stream state test(*event) - content = list(self._flatten(content, ctxt, False)) + content = list(self._flatten(content, ctxt)) def _apply(stream, ctxt): - stream = list(stream) ctxt.push(select=lambda path: Stream(stream).select(path)) for event in template: yield event