Mercurial > genshi > mirror
changeset 206:75c9c019de88 trunk
`TypeError`s raised by `py:def` macros (and other expressions producing streams) are no longer silently ignored. Closes #44.
author | cmlenz |
---|---|
date | Tue, 29 Aug 2006 10:56:33 +0000 |
parents | b700e5326421 |
children | 28bfc6aafab7 |
files | markup/template.py markup/tests/template.py |
diffstat | 2 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/markup/template.py +++ b/markup/template.py @@ -961,15 +961,16 @@ # Test if the expression evaluated to an iterable, in which # case we yield the individual items try: - substream = _ensure(result) + substream = _ensure(iter(result)) + except TypeError: + # Neither a string nor an iterable, so just pass it + # through + yield TEXT, unicode(result), pos + else: for filter_ in filters: substream = filter_(substream, ctxt) for event in substream: yield event - except TypeError: - # Neither a string nor an iterable, so just pass it - # through - yield TEXT, unicode(result), pos else: yield kind, data, pos
--- a/markup/tests/template.py +++ b/markup/tests/template.py @@ -319,6 +319,17 @@ <p>bar</p> </doc>""", str(tmpl.generate())) + def test_function_raising_typeerror(self): + def badfunc(): + raise TypeError + tmpl = Template("""<html xmlns:py="http://markup.edgewall.org/"> + <div py:def="dobadfunc()"> + ${badfunc()} + </div> + <div py:content="dobadfunc()"/> + </html>""") + self.assertRaises(TypeError, list, tmpl.generate(badfunc=badfunc)) + class ForDirectiveTestCase(unittest.TestCase): """Tests for the `py:for` template directive."""