changeset 766:b5b4b465e84c trunk

Fix bug where in some cases match templates would incorrectly applied multiple times.
author cmlenz
date Fri, 27 Jun 2008 14:20:05 +0000
parents df2eda814f2d
children f5d5afd2df2b
files ChangeLog genshi/template/markup.py
diffstat 2 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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
Copyright (C) 2012-2017 Edgewall Software