[ZPT] CVS: Packages/TAL - DummyEngine.py:1.15

guido@digicool.com guido@digicool.com
Fri, 23 Mar 2001 14:48:46 -0500 (EST)


Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv31070

Modified Files:
	DummyEngine.py 
Log Message:
Define TALESError, an exception class that carries another
exception+traceback around.  This is raised by evaluate().

Fix evaluate() to support string:, path:, not:, and exists:.  For
compatibility it still recognizes str: as an alias for string:, and
var:, global: and local: as aliases for path:.



--- Updated File DummyEngine.py in package Packages/TAL --
--- DummyEngine.py	2001/03/17 03:49:29	1.14
+++ DummyEngine.py	2001/03/23 19:48:45	1.15
@@ -87,13 +87,11 @@
 """
 
 import re
+import sys
 import string
 
-from TALDefs import NAME_RE, TALError
+from TALDefs import NAME_RE, TALError, TALESError
 
-class TALESError(TALError):
-    pass
-
 class DummyEngine:
 
     def __init__(self, macros=None):
@@ -125,22 +123,30 @@
         if m:
             type, expr = m.group(1, 2)
         else:
-            type = "var"
+            type = "path"
             expr = expression
-        if type == "str":
+        if type in ("string", "str"):
             return expr
-        if type == "local":
-            return self.locals[string.strip(expr)]
-        if type == "global":
-            return self.globals[string.strip(expr)]
-        if type == "var":
+        if type in ("path", "var", "global", "local"):
             expr = string.strip(expr)
             if self.locals.has_key(expr):
                 return self.locals[expr]
-            else:
+            elif self.globals.has_key(expr):
                 return self.globals[expr]
+            else:
+                raise TALESError("unknown variable: %s", expr)
+        if type == "not":
+            v = self.evaluate(expr)
+            return not v
+        if type == "exists":
+            return self.locals.has_key(expr) or self.globals.has_key(expr)
         if type == "python":
-            return eval(expr, self.globals, self.locals)
+            try:
+                return eval(expr, self.globals, self.locals)
+            except:
+                t, v, tb = info = sys.exc_info()
+                raise TALESError("evaluation error in %s" % `expr`,
+                                 info=sys.exc_info())
         raise TALESError("unrecognized expression: " + `expression`)
 
     def evaluateValue(self, expr):