From ccb879e495570963ec0f15c8071bd9096bf404c8 Mon Sep 17 00:00:00 2001 From: noah morrison Date: Sat, 22 Nov 2014 18:18:17 -0500 Subject: [PATCH] Removed custom exception in favor of a builtin --- chevron/__init__.py | 3 +-- chevron/tokenizer.py | 10 +++------- test_spec.py | 6 ++---- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/chevron/__init__.py b/chevron/__init__.py index 14c6ea8..0d4ad77 100644 --- a/chevron/__init__.py +++ b/chevron/__init__.py @@ -1,5 +1,4 @@ from .main import main, cli_main from .renderer import render -from .tokenizer import UnclosedSection -__all__ = ['main', 'render', 'UnclosedSection', 'cli_main'] +__all__ = ['main', 'render', 'cli_main'] diff --git a/chevron/tokenizer.py b/chevron/tokenizer.py index 3b3abd1..af3997b 100644 --- a/chevron/tokenizer.py +++ b/chevron/tokenizer.py @@ -1,11 +1,6 @@ #!/usr/bin/python -class UnclosedSection(Exception): - """Raised when you have unbalanced section tags""" - pass - - def tokenize(template, def_ldel='{{', def_rdel='}}'): """Tokenize a mustache template @@ -117,7 +112,8 @@ def tokenize(template, def_ldel='{{', def_rdel='}}'): last_section = open_sections.pop() if tag_key != last_section: # Otherwise we need to complain - raise UnclosedSection() + raise SyntaxError("End tag does not match ." + "the currently opened section") # Check right side if we might be a standalone if is_standalone and tag_type not in ['variable', 'no escape']: @@ -149,4 +145,4 @@ def tokenize(template, def_ldel='{{', def_rdel='}}'): # If there are any open sections when we're done if open_sections: # Then we need to complain - raise UnclosedSection() + raise SyntaxError("End of file while a section was open") diff --git a/test_spec.py b/test_spec.py index 8754f6b..7787625 100755 --- a/test_spec.py +++ b/test_spec.py @@ -60,10 +60,8 @@ class ExpandedCoverage(unittest.TestCase): 'template': '{{# section }} end of file' } - self.assertRaises(chevron.tokenizer.UnclosedSection, - chevron.render, **test1) - self.assertRaises(chevron.tokenizer.UnclosedSection, - chevron.render, **test2) + self.assertRaises(SyntaxError, chevron.render, **test1) + self.assertRaises(SyntaxError, chevron.render, **test2) def test_unicode_basic(self): args = { -- 2.47.3