# HG changeset patch # User cmlenz # Date 1214576405 0 # Node ID b5b4b465e84c751ff638b3ec889e57ee673bf67d # Parent df2eda814f2d6b354e1c14cca42dd9ea8c15e4a6 Fix bug where in some cases match templates would incorrectly applied multiple times. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,7 @@ text nodes to fail if the translation function returned an object that was not directly a string, but rather something like an instance of the `LazyProxy` class in Babel (ticket #145). + * Fix problem with match templates incorrectly being applied multiple times. Version 0.5 diff --git a/genshi/template/markup.py b/genshi/template/markup.py --- a/genshi/template/markup.py +++ b/genshi/template/markup.py @@ -221,12 +221,11 @@ assert len(streams) == 1 return streams[0] - def _match(self, stream, ctxt, match_templates=None, offset=0, **vars): + def _match(self, stream, ctxt, start=0, end=None, **vars): """Internal stream filter that applies any defined match templates to the stream. """ - if match_templates is None: - match_templates = ctxt._match_templates + match_templates = ctxt._match_templates tail = [] def _strip(stream): @@ -254,7 +253,7 @@ for idx, (test, path, template, hints, namespaces, directives) \ in enumerate(match_templates): - if idx < offset: + if idx < start or end is not None and idx >= end: continue if test(event, namespaces, ctxt) is True: @@ -269,12 +268,12 @@ # Consume and store all events until an end event # corresponding to this start event is encountered - pre_match_templates = match_templates[:idx + 1] + pre_end = idx + 1 if 'match_once' not in hints and 'not_recursive' in hints: - pre_match_templates.pop() + pre_end -= 1 inner = _strip(stream) - if pre_match_templates: - inner = self._match(inner, ctxt, pre_match_templates) + if pre_end > 0: + inner = self._match(inner, ctxt, end=pre_end) content = self._include(chain([event], inner, tail), ctxt) if 'not_buffered' not in hints: content = list(content) @@ -298,7 +297,7 @@ self._flatten(template, ctxt, **vars), ctxt, **vars), ctxt, **vars), - ctxt, match_templates, offset=idx + 1, **vars): + ctxt, start=idx + 1, **vars): yield event break