Commit 2b768f74 authored by Guido van Rossum's avatar Guido van Rossum

Add evaluateMacro() method, and optional macros argument to

constructor.
parent 4f09969b
......@@ -89,10 +89,15 @@ Dummy TALES engine so that I can test out the TAL implementation.
import re
import string
from TALVisitor import NAME_RE
from TALVisitor import macroIndexer
from TALCompiler import TALCompiler
class DummyEngine:
def __init__(self):
def __init__(self, macros=None):
if macros is None:
macros = {}
self.macros = macros
dict = {}
self.locals = self.globals = dict
self.stack = [dict]
......@@ -157,6 +162,21 @@ class DummyEngine:
# XXX Should return a sequence
return self.evaluate(expr)
def evaluateMacro(self, macroName):
doc, localName = self.findMacroDocument(macroName)
if not doc:
# Local macro
macro = self.macros[localName]
else:
# External macro
macroDict = macroIndexer(doc)
if not macroDict.has_key(localName):
print "Macro", macroName, "not found"
return
macroNode = macroDict[localName]
macro, dummy = TALCompiler(macroNode)()
return macro
def findMacroDocument(self, macroName):
if not macroName:
print "Empty macro name:", macroName
......
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