Mercurial > genshi > genshi-test
diff markup/template.py @ 217:d8b195b22a44
Fix `py:match` directive which would screw up in some scenarios due to incorrect handling of the substream. Closes #49.
author | cmlenz |
---|---|
date | Mon, 04 Sep 2006 23:27:38 +0000 |
parents | 813b7115d27f |
children | c62dbea15f36 |
line wrap: on
line diff
--- a/markup/template.py +++ b/markup/template.py @@ -996,6 +996,21 @@ if match_templates is None: match_templates = ctxt._match_templates + tail = [] + def _strip(stream): + depth = 1 + while 1: + kind, data, pos = stream.next() + if kind is START: + depth += 1 + elif kind is END: + depth -= 1 + if depth > 0: + yield kind, data, pos + else: + tail[:] = [(kind, data, pos)] + break + for kind, data, pos in stream: # We (currently) only care about start and end events for matching @@ -1017,15 +1032,11 @@ # Consume and store all events until an end event # corresponding to this start event is encountered content = [(kind, data, pos)] - depth = 1 - stream = self._match(stream, ctxt) - while depth > 0: - kind, data, pos = stream.next() - if kind is START: - depth += 1 - elif kind is END: - depth -= 1 - content.append((kind, data, pos)) + content += list(self._match(_strip(stream), ctxt)) + tail + + kind, data, pos = tail[0] + for test in [mt[0] for mt in match_templates]: + test(kind, data, pos, ctxt) # Make the select() function available in the body of the # match template