# HG changeset patch # User cmlenz # Date 1158488175 0 # Node ID 2471c608ce73068ad20f565e877dcf9e76fd4b1a # Parent b8932429dbd0ad9e4ae1ea92f14f6ef8e51a2a0b * Add `MANIFEST.in` so that the generated HTML documentation is included in the source distribution. * Remove duplicate `_match` implementation. * Allow shorthand expressions to start with an underscore. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,5 @@ +exclude doc/2000ft.graffle +exclude doc/docutils.conf +exclude doc/logo.lineform +exclude doc/Makefile +include doc/*.html diff --git a/genshi/template.py b/genshi/template.py --- a/genshi/template.py +++ b/genshi/template.py @@ -783,7 +783,7 @@ raise NotImplementedError _FULL_EXPR_RE = re.compile(r'(? 0: - yield kind, data, pos - else: - tail[:] = [(kind, data, pos)] - break - - for kind, data, pos in stream: - - # We (currently) only care about start and end events for matching - # We might care about namespace events in the future, though - if not match_templates or kind not in (START, END): - yield kind, data, pos - continue - - for idx, (test, path, template, directives) in \ - enumerate(match_templates): - - if test(kind, data, pos, nsprefix, ctxt) is True: - - # Let the remaining match templates know about the event so - # they get a chance to update their internal state - for test in [mt[0] for mt in match_templates[idx + 1:]]: - test(kind, data, pos, nsprefix, ctxt) - - # Consume and store all events until an end event - # corresponding to this start event is encountered - content = [(kind, data, pos)] - content += list(self._match(_strip(stream), ctxt)) + tail - - kind, data, pos = tail[0] - for test in [mt[0] for mt in match_templates]: - test(kind, data, pos, nsprefix, ctxt) - - # Make the select() function available in the body of the - # match template - def select(path): - return Stream(content).select(path) - ctxt.push(dict(select=select)) - - # Recursively process the output - template = _apply_directives(template, ctxt, directives) - for event in self._match(self._eval(self._flatten(template, - ctxt), - ctxt), ctxt, - match_templates[:idx] + - match_templates[idx + 1:]): - yield event - - ctxt.pop() - break - - else: # no matches - yield kind, data, pos - EXPR = Template.EXPR SUB = Template.SUB diff --git a/genshi/tests/template.py b/genshi/tests/template.py --- a/genshi/tests/template.py +++ b/genshi/tests/template.py @@ -827,6 +827,36 @@ self.assertEqual(Template.EXPR, parts[0][0]) self.assertEqual('bla', parts[0][1].source) + def test_interpolate_short(self): + parts = list(Template._interpolate('$bla')) + self.assertEqual(1, len(parts)) + self.assertEqual(Template.EXPR, parts[0][0]) + self.assertEqual('bla', parts[0][1].source) + + def test_interpolate_short_starting_with_underscore(self): + parts = list(Template._interpolate('$_bla')) + self.assertEqual(1, len(parts)) + self.assertEqual(Template.EXPR, parts[0][0]) + self.assertEqual('_bla', parts[0][1].source) + + def test_interpolate_short_containing_underscore(self): + parts = list(Template._interpolate('$foo_bar')) + self.assertEqual(1, len(parts)) + self.assertEqual(Template.EXPR, parts[0][0]) + self.assertEqual('foo_bar', parts[0][1].source) + + def test_interpolate_short_starting_with_dot(self): + parts = list(Template._interpolate('$.bla')) + self.assertEqual(1, len(parts)) + self.assertEqual(Stream.TEXT, parts[0][0]) + self.assertEqual('$.bla', parts[0][1]) + + def test_interpolate_short_containing_dot(self): + parts = list(Template._interpolate('$foo.bar')) + self.assertEqual(1, len(parts)) + self.assertEqual(Template.EXPR, parts[0][0]) + self.assertEqual('foo.bar', parts[0][1].source) + def test_interpolate_mixed1(self): parts = list(Template._interpolate('$foo bar $baz')) self.assertEqual(3, len(parts)) @@ -847,6 +877,15 @@ self.assertEqual(Stream.TEXT, parts[2][0]) self.assertEqual(' baz', parts[2][1]) + def test_interpolate_mixed1(self): + parts = list(Template._interpolate('$foo bar $baz')) + self.assertEqual(3, len(parts)) + self.assertEqual(Template.EXPR, parts[0][0]) + self.assertEqual('foo', parts[0][1].source) + self.assertEqual(Stream.TEXT, parts[1][0]) + self.assertEqual(' bar ', parts[1][1]) + self.assertEqual(Template.EXPR, parts[2][0]) + self.assertEqual('baz', parts[2][1].source) class MarkupTemplateTestCase(unittest.TestCase): """Tests for markup template processing."""