changeset 921:178c32ec7700 experimental-py3k

Fix handling of tails in py:match processing. See Genshi ticket #399.
author hodgestar
date Mon, 29 Nov 2010 20:45:22 +0000
parents f4bf11c716cc
children d5c71dff3dd0
files genshi/template/markup.py genshi/template/tests/markup.py
diffstat 2 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/genshi/template/markup.py
+++ b/genshi/template/markup.py
@@ -308,8 +308,7 @@
         """
         match_templates = ctxt._match_templates
 
-        tail = []
-        def _strip(stream, append=tail.append):
+        def _strip(stream, append):
             depth = 1
             next = stream.next
             while 1:
@@ -353,7 +352,8 @@
                     pre_end = idx + 1
                     if 'match_once' not in hints and 'not_recursive' in hints:
                         pre_end -= 1
-                    inner = _strip(stream)
+                    tail = []
+                    inner = _strip(stream, tail.append)
                     if pre_end > 0:
                         inner = self._match(inner, ctxt, start=start,
                                             end=pre_end, **vars)
--- a/genshi/template/tests/markup.py
+++ b/genshi/template/tests/markup.py
@@ -732,6 +732,30 @@
             </body>
         </html>""", tmpl.generate().render(encoding=None))
 
+    def test_match_tail_handling(self):
+        # See <http://genshi.edgewall.org/ticket/399>
+        xml = ("""<rhyme xmlns:py="http://genshi.edgewall.org/">
+          <py:match path="*[@type]">
+            ${select('.')}
+          </py:match>
+    
+          <lines>
+            <first type="one">fish</first>
+            <second type="two">fish</second>
+            <third type="red">fish</third>
+            <fourth type="blue">fish</fourth>
+          </lines>
+        </rhyme>""")
+        tmpl = MarkupTemplate(xml, filename='test.html')
+        self.assertEqual("""<rhyme>
+          <lines>
+            <first type="one">fish</first>
+            <second type="two">fish</second>
+            <third type="red">fish</third>
+            <fourth type="blue">fish</fourth>
+          </lines>
+        </rhyme>""", tmpl.generate().render(encoding=None))
+
 
 def suite():
     suite = unittest.TestSuite()
Copyright (C) 2012-2017 Edgewall Software