Ticket #243: ticket243.diff
| File ticket243.diff, 2.7 KB (added by cmlenz, 4 years ago) |
|---|
-
genshi/template/markup.py
278 278 if 'not_buffered' not in hints: 279 279 content = list(content) 280 280 281 if tail:282 for test in [mt[0] for mt in match_templates]:283 test(tail[0], namespaces, ctxt, updateonly=True)284 285 281 # Make the select() function available in the body of the 286 282 # match template 283 selected = [False] 287 284 def select(path): 285 selected[0] = True 288 286 return Stream(content).select(path, namespaces, ctxt) 289 287 vars = dict(select=select) 290 288 … … 300 298 ctxt, start=idx + 1, **vars): 301 299 yield event 302 300 301 # If the match template did not actually call select to 302 # consume the matched stream, the original events need to 303 # be consumed here or they'll get appended to the output 304 if not selected[0]: 305 for event in content: 306 pass 307 308 # Let the remaining match templates know about the event so 309 # they get a chance to update their internal state 310 for test in [mt[0] for mt in match_templates]: 311 test(tail[0], namespaces, ctxt, updateonly=True) 312 303 313 break 304 314 305 315 else: # no matches -
genshi/template/tests/markup.py
708 708 </body> 709 709 </html>""", tmpl.generate().render()) 710 710 711 def test_match_without_select(self): 712 # See <http://genshi.edgewall.org/ticket/243> 713 xml = ("""<html xmlns:py="http://genshi.edgewall.org/"> 714 <py:match path="body" buffer="false"> 715 <body> 716 This replaces the other text. 717 </body> 718 </py:match> 719 <body> 720 This gets replaced. 721 </body> 722 </html>""") 723 tmpl = MarkupTemplate(xml, filename='test.html') 724 self.assertEqual("""<html> 725 <body> 726 This replaces the other text. 727 </body> 728 </html>""", tmpl.generate().render()) 711 729 730 712 731 def suite(): 713 732 suite = unittest.TestSuite() 714 733 suite.addTest(doctest.DocTestSuite(MarkupTemplate.__module__))
