from .main import main, cli_main
from .renderer import render
+from .tokenizer import ChevronError
-__all__ = ['main', 'render', 'cli_main']
+__all__ = ['main', 'render', 'cli_main', 'ChevronError']
_LAST_TAG_LINE = None
+class ChevronError(SyntaxError):
+ pass
+
#
# Helper functions
#
+
def grab_literal(template, l_del):
"""Parse a literal from the template"""
# Otherwise we should complain
else:
- raise SyntaxError('unclosed set delimiter tag\n'
- 'at line {0}'.format(_CURRENT_LINE))
+ raise ChevronError('unclosed set delimiter tag\n'
+ 'at line {0}'.format(_CURRENT_LINE))
# If we might be a no html escape tag
elif tag_type == 'no escape?':
last_section = open_sections.pop()
if tag_key != last_section:
# Otherwise we need to complain
- raise SyntaxError('Trying to close tag "{0}"\n'
- 'last open tag is "{1}"\n'
- 'line {2}'
- .format(tag_key, last_section,
- _CURRENT_LINE + 1))
+ raise ChevronError('Trying to close tag "{0}"\n'
+ 'last open tag is "{1}"\n'
+ 'line {2}'
+ .format(tag_key, last_section,
+ _CURRENT_LINE + 1))
# Do the second check to see if we're a standalone
is_standalone = r_sa_check(template, tag_type, is_standalone)
# If there are any open sections when we're done
if open_sections:
# Then we need to complain
- raise SyntaxError('Unexpected EOF\n'
- 'the tag "{0}" was never closed\n'
- 'was opened at line {1}'
- .format(open_sections[-1], _LAST_TAG_LINE))
+ raise ChevronError('Unexpected EOF\n'
+ 'the tag "{0}" was never closed\n'
+ 'was opened at line {1}'
+ .format(open_sections[-1], _LAST_TAG_LINE))
'template': '{{# section }} end of file'
}
+ self.assertRaises(chevron.ChevronError, chevron.render, **test1)
+ self.assertRaises(chevron.ChevronError, chevron.render, **test2)
+ # check SyntaxError still catches ChevronError:
self.assertRaises(SyntaxError, chevron.render, **test1)
- self.assertRaises(SyntaxError, chevron.render, **test2)
def test_bad_set_delimiter_tag(self):
args = {