Commit a7b96a33 authored by Guido van Rossum's avatar Guido van Rossum

Raise exception (TALESError) for errors rather than printing a message.

parent f7b94ccd
...@@ -90,7 +90,10 @@ import re ...@@ -90,7 +90,10 @@ import re
import string import string
from TALDefs import NAME_RE, macroIndexer from TALDefs import NAME_RE, macroIndexer
from TALCompiler import TALCompiler from TALCompiler import TALCompiler, TALError
class TALESError(TALError):
pass
class DummyEngine: class DummyEngine:
...@@ -139,8 +142,7 @@ class DummyEngine: ...@@ -139,8 +142,7 @@ class DummyEngine:
return self.globals[expr] return self.globals[expr]
if type == "python": if type == "python":
return eval(expr, self.globals, self.locals) return eval(expr, self.globals, self.locals)
print "Unrecognized expression:", `expression` raise TALESError("unrecognized expression: " + `expression`)
return None
def evaluateValue(self, expr): def evaluateValue(self, expr):
return self.evaluate(expr) return self.evaluate(expr)
...@@ -171,16 +173,14 @@ class DummyEngine: ...@@ -171,16 +173,14 @@ class DummyEngine:
# External macro # External macro
macroDict = macroIndexer(doc) macroDict = macroIndexer(doc)
if not macroDict.has_key(localName): if not macroDict.has_key(localName):
print "Macro", macroName, "not found" raise TALESError("macro not found: " + `macroName`)
return
macroNode = macroDict[localName] macroNode = macroDict[localName]
macro, dummy = TALCompiler(macroNode)() macro, dummy = TALCompiler(macroNode)()
return macro return macro
def findMacroDocument(self, macroName): def findMacroDocument(self, macroName):
if not macroName: if not macroName:
print "Empty macro name:", macroName raise TALESError("empty macro name")
return None, None
i = string.rfind(macroName, '/') i = string.rfind(macroName, '/')
if i < 0: if i < 0:
# No slash -- must be a locally defined macro # No slash -- must be a locally defined macro
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment