[ZPT] CVS: Packages/TAL - DummyEngine.py:1.25
fred@digicool.com
fred@digicool.com
Tue, 12 Jun 2001 11:00:20 -0400 (EDT)
Update of /cvs-repository/Packages/TAL
In directory korak.digicool.com:/tmp/cvs-serv1030
Modified Files:
DummyEngine.py
Log Message:
Small optimizations to get this a little more out of the way when profiling.
--- Updated File DummyEngine.py in package Packages/TAL --
--- DummyEngine.py 2001/05/16 17:12:48 1.24
+++ DummyEngine.py 2001/06/12 15:00:19 1.25
@@ -88,12 +88,16 @@
import re
import sys
-import string
+from string import rfind, strip
+import driver
+
from TALDefs import NAME_RE, TALError, TALESError
Default = []
+name_match = re.compile(r"(?s)(%s):(.*)\Z" % NAME_RE).match
+
class DummyEngine:
def __init__(self, macros=None):
@@ -128,8 +132,9 @@
self.globals[name] = value
def evaluate(self, expression):
- expression = self.uncompile(expression)
- m = re.match(r"(?s)(%s):(.*)\Z" % NAME_RE, expression)
+ assert expression[:1] == "$" == expression[-1:], expression
+ expression = expression[1:-1]
+ m = name_match(expression)
if m:
type, expr = m.group(1, 2)
else:
@@ -138,7 +143,7 @@
if type in ("string", "str"):
return expr
if type in ("path", "var", "global", "local"):
- expr = string.strip(expr)
+ expr = strip(expr)
if self.locals.has_key(expr):
return self.locals[expr]
elif self.globals.has_key(expr):
@@ -146,8 +151,7 @@
else:
raise TALESError("unknown variable: %s" % `expr`)
if type == "not":
- v = self.evaluate(expr)
- return not v
+ return not self.evaluate(expr)
if type == "exists":
return self.locals.has_key(expr) or self.globals.has_key(expr)
if type == "python":
@@ -180,15 +184,15 @@
return self.evaluate(expr)
def evaluateMacro(self, macroName):
- macroName = self.uncompile(macroName)
+ assert macroName[:1] == "$" == macroName[-1:], macroName
+ macroName = macroName[1:-1]
file, localName = self.findMacroFile(macroName)
if not file:
# Local macro
macro = self.macros[localName]
else:
# External macro
- from driver import compilefile
- program, macros = compilefile(file)
+ program, macros = driver.compilefile(file)
macro = macros.get(localName)
if not macro:
raise TALESError("macro %s not found in file %s" %
@@ -199,14 +203,13 @@
file, localName = self.findMacroFile(macroName)
if not file:
return file, localName
- from driver import parsefile
- doc = parsefile(file)
+ doc = driver.parsefile(file)
return doc, localName
def findMacroFile(self, macroName):
if not macroName:
raise TALESError("empty macro name")
- i = string.rfind(macroName, '/')
+ i = rfind(macroName, '/')
if i < 0:
# No slash -- must be a locally defined macro
return None, macroName