[ZPT] CVS: Packages/TAL - TALGenerator.py:1.28
guido@digicool.com
guido@digicool.com
Mon, 26 Mar 2001 17:25:55 -0500 (EST)
Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv3834
Modified Files:
TALGenerator.py
Log Message:
Move compile() into the DummyEngine() class (deleting our
DummyCompiler class), and make sure to call it everywhere it is
needed (in particular for attribute replacements).
Emit a new opcode, "mode", with an argument "html" or "xml", depending
on the value of the xml argument to the constructor. (This requires a
matching checkin of TALInterpreter.) (This comment was mistakenly
added to the previous checkin of DummyCompiler.py.)
Don't append to self.program directly; always call self.emit().
--- Updated File TALGenerator.py in package Packages/TAL --
--- TALGenerator.py 2001/03/26 14:25:57 1.27
+++ TALGenerator.py 2001/03/26 22:25:54 1.28
@@ -91,17 +91,13 @@
import cgi
from TALDefs import *
+from DummyEngine import DummyEngine
-class DummyCompiler:
-
- def compile(self, expr):
- return expr
-
class TALGenerator:
def __init__(self, expressionCompiler=None, xml=1):
if not expressionCompiler:
- expressionCompiler = DummyCompiler()
+ expressionCompiler = DummyEngine()
self.expressionCompiler = expressionCompiler
self.program = []
self.stack = []
@@ -111,6 +107,7 @@
self.slotStack = []
self.xml = xml
self.emit("version", TAL_VERSION)
+ self.emit("mode", xml and "xml" or "html")
def getCode(self):
return self.optimize(self.program), self.macros
@@ -196,17 +193,17 @@
opcode = "startEndTag"
else:
opcode = "startTag"
- self.program.append((opcode, name, attrlist))
+ self.emit(opcode, name, attrlist)
def emitEndTag(self, name):
if self.xml and self.program and self.program[-1][0] == "startTag":
# Minimize empty element
self.program[-1] = ("startEndTag",) + self.program[-1][1:]
else:
- self.program.append(("endTag", name))
+ self.emit("endTag", name)
def emitRawText(self, text):
- self.program.append(("rawtext", text))
+ self.emit("rawtext", text)
def emitText(self, text):
self.emitRawText(cgi.escape(text))
@@ -329,7 +326,7 @@
rest = rest + string.join(collect, "")
del self.program[i:]
if text:
- self.program.append(("rawtext", text))
+ self.emit("rawtext", text)
return rest
return None
@@ -350,7 +347,7 @@
def emitStartElement(self, name, attrlist, taldict, metaldict,
position=(None, None), isend=0):
- if len(taldict) == len(metaldict) == 0:
+ if not taldict and not metaldict:
# Handle the simple, common case
self.emitStartTag(name, attrlist, isend)
self.todoPush({})
@@ -433,6 +430,8 @@
self.emitText(repeatWhitespace)
if attrsubst:
repldict = parseAttributeReplacements(attrsubst)
+ for key, value in repldict.items():
+ repldict[key] = self.expressionCompiler.compile(value)
else:
repldict = {}
if replace: