summaryrefslogtreecommitdiff
path: root/coverage/templite.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/templite.py')
-rw-r--r--coverage/templite.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/coverage/templite.py b/coverage/templite.py
index f61fbdc..0654f29 100644
--- a/coverage/templite.py
+++ b/coverage/templite.py
@@ -2,7 +2,7 @@
# Coincidentally named the same as http://code.activestate.com/recipes/496702/
-import re
+import re, sys
class Templite(object):
"""A simple template renderer, for a nano-subset of Django syntax.
@@ -80,7 +80,7 @@ class Templite(object):
ops = ops_stack.pop()
assert ops[-1][0] == words[0][3:]
else:
- raise Exception("Don't understand tag %r" % words)
+ raise SyntaxError("Don't understand tag %r" % words)
else:
ops.append(('lit', tok))
@@ -120,7 +120,13 @@ class _TempliteEngine(object):
if op == 'lit':
self.result += args
elif op == 'exp':
- self.result += str(self.evaluate(args))
+ try:
+ self.result += str(self.evaluate(args))
+ except:
+ exc_class, exc, _ = sys.exc_info()
+ new_exc = exc_class("Couldn't evaluate {{ %s }}: %s"
+ % (args, exc))
+ raise new_exc
elif op == 'if':
expr, body = args
if self.evaluate(expr):
@@ -132,7 +138,7 @@ class _TempliteEngine(object):
self.context[var] = val
self.execute(body)
else:
- raise Exception("TempliteEngine doesn't grok op %r" % op)
+ raise AssertionError("TempliteEngine doesn't grok op %r" % op)
def evaluate(self, expr):
"""Evaluate an expression.