[ZPT] CVS: Packages/TAL - HTMLTALParser.py:1.26 README.txt:1.16 TALDefs.py:1.15 TALInterpreter.py:1.32 TALParser.py:1.13 driver.py:1.20
guido@digicool.com
guido@digicool.com
Sat, 7 Apr 2001 15:25:05 -0400 (EDT)
Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv4976
Modified Files:
HTMLTALParser.py README.txt TALDefs.py TALInterpreter.py
TALParser.py driver.py
Log Message:
Changes to suppress TAL attributes (and METAL attributes, and selected
XMLNS attributes) in rendered output, with an option to keep the old
behavior.
HTMLTALParser.py, TALParser.py:
Mark TAL, METAL and TAL/METAL-related XMLNS attributes in the
attribute list; the old macroHack marking is subsumed in this.
The marking is a third value in the list item describing the
attribute, saying "tal", "metal" or "xmlns". All TAL and METAL
attributes are marked; only XMLNS attributes whose namespace URI
value is the special marker for TAL or METAL are marked.
TALInterpreter.py:
- Get rid of the non-functional 'html' keyword argument.
- Add new 'showtal' keyword argument to constructor; this defaults
to -1, which means that the value should default to 0 if TAL
expansion is requested (through the 'tal' keyword argument) and
1 if TAL expansion is not requested.
- In do_startEndTag(), don't special-case empty HTML tags; this is
already taken care of by TALGenerator.
- Implement the showtal behavior: when this flag is false, don't
output TAL, METAL and XMLNS attributes (that are marked as such
by the parser).
- Fix a bug: <img src="foo" tal:attributes="src nothing"> should
render as <img>, not as <img src>.
TALDefs.py:
Bumped TAL_VERSION to "1.0.1"
driver.py:
New command line option -t to show tal in output
README.txt:
Update TO DO list.
--- Updated File HTMLTALParser.py in package Packages/TAL --
--- HTMLTALParser.py 2001/03/27 17:23:26 1.25
+++ HTMLTALParser.py 2001/04/07 19:25:03 1.26
@@ -317,15 +317,16 @@
if metaldict.has_key(suffix):
raise METALError("duplicate METAL attribute " +
`suffix`, self.getpos())
- item = (key, value)
+ item = (key, value, "metal")
metaldict[suffix] = value
- if suffix == "define-macro":
- item = (key,value,"macroHack")
elif nsuri == ZOPE_TAL_NS:
if taldict.has_key(suffix):
raise TALError("duplicate TAL attribute " +
`suffix`, self.getpos())
- item = (key, value)
+ item = (key, value, "tal")
taldict[suffix] = value
+ elif (prefix == "xmlns" and
+ value in (ZOPE_METAL_NS, ZOPE_TAL_NS)):
+ item = (key, value, "xmlns")
attrlist.append(item)
return attrlist, taldict, metaldict
--- Updated File README.txt in package Packages/TAL --
--- README.txt 2001/04/07 02:01:08 1.15
+++ README.txt 2001/04/07 19:25:03 1.16
@@ -91,6 +91,3 @@
tal:replace and tal:attributes should not be required to do
attribute replacement on the inserted text -- this would require a
change to the TAL spec though.
-
-- In rendered HTML or XML, the TAL attributes should be suppressed.
- (Effectively, when TALInterpreter is invoked with tal=1.)
--- Updated File TALDefs.py in package Packages/TAL --
--- TALDefs.py 2001/03/26 17:02:50 1.14
+++ TALDefs.py 2001/04/07 19:25:03 1.15
@@ -86,7 +86,7 @@
Common definitions used by TAL and METAL compilation an transformation.
"""
-TAL_VERSION = "1.0"
+TAL_VERSION = "1.0.1"
XML_NS = "http://www.w3.org/XML/1998/namespace" # URI for XML namespace
XMLNS_NS = "http://www.w3.org/2000/xmlns/" # URI for XML NS declarations
--- Updated File TALInterpreter.py in package Packages/TAL --
--- TALInterpreter.py 2001/04/06 21:35:03 1.31
+++ TALInterpreter.py 2001/04/07 19:25:03 1.32
@@ -150,7 +150,7 @@
class TALInterpreter:
def __init__(self, program, macros, engine, stream=None,
- debug=0, wrap=60, metal=1, tal=1, html=0):
+ debug=0, wrap=60, metal=1, tal=1, showtal=-1):
self.program = program
self.macros = macros
self.engine = engine
@@ -160,7 +160,11 @@
self.wrap = wrap
self.metal = metal
self.tal = tal
- self.html = html
+ assert showtal in (-1, 0, 1)
+ if showtal == -1:
+ showtal = (not tal)
+ self.showtal = showtal
+ self.html = 0
self.slots = {}
self.currentMacro = None
self.position = None, None # (lineno, offset)
@@ -225,18 +229,14 @@
assert version == TAL_VERSION
def do_mode(self, mode):
- assert mode in ["html", "xml"]
+ assert mode in ("html", "xml")
self.html = (mode == "html")
def do_setPosition(self, position):
self.position = position
def do_startEndTag(self, name, attrList):
- if self.html and string.lower(name) not in EMPTY_HTML_TAGS:
- self.do_startTag(name, attrList)
- self.do_endTag(name)
- else:
- self.startTagCommon(name, attrList, self.endsep)
+ self.startTagCommon(name, attrList, self.endsep)
def do_startTag(self, name, attrList):
self.startTagCommon(name, attrList, ">")
@@ -251,6 +251,8 @@
name, value = item[:2]
if len(item) > 2:
action = item[2]
+ if not self.showtal and action in ("tal", "metal", "xmlns"):
+ continue
if action == "replace" and len(item) > 3 and self.tal:
if self.html and string.lower(name) in BOOLEAN_HTML_ATTRS:
ok = self.engine.evaluateBoolean(item[3])
@@ -260,7 +262,9 @@
value = None
else:
value = self.engine.evaluateText(item[3])
- elif (action == "macroHack" and self.currentMacro and
+ if value is None:
+ continue
+ elif (action == "metal" and self.currentMacro and
name[-13:] == ":define-macro" and self.metal):
name = name[:-13] + ":use-macro"
value = self.currentMacro
--- Updated File TALParser.py in package Packages/TAL --
--- TALParser.py 2001/03/16 17:24:47 1.12
+++ TALParser.py 2001/04/07 19:25:03 1.13
@@ -144,10 +144,10 @@
item = self.fixname(key), value
if key[:nmetal] == metalprefix:
metaldict[key[nmetal:]] = value
- if key[nmetal:] == "define-macro":
- item = item + ("macroHack",)
+ item = item + ("metal",)
elif key[:ntal] == talprefix:
taldict[key[ntal:]] = value
+ item = item + ("tal",)
fixedattrlist.append(item)
return fixedattrlist, taldict, metaldict
@@ -155,9 +155,14 @@
newlist = []
for prefix, uri in self.nsNew:
if prefix:
- newlist.append(("xmlns:" + prefix, uri))
+ key = "xmlns:" + prefix
else:
- newlist.append(("xmlns", uri))
+ key = "xmlns"
+ if uri in (ZOPE_METAL_NS, ZOPE_TAL_NS):
+ item = (key, uri, "xmlns")
+ else:
+ item = (key, uri)
+ newlist.append(item)
self.nsNew = []
return newlist
--- Updated File driver.py in package Packages/TAL --
--- driver.py 2001/03/27 17:16:07 1.19
+++ driver.py 2001/04/07 19:25:03 1.20
@@ -109,16 +109,18 @@
macros = 0
mode = None
showcode = 0
+ showtal = -1
try:
- opts, args = getopt.getopt(sys.argv[1:], "hxmns")
+ opts, args = getopt.getopt(sys.argv[1:], "hxmnst")
except getopt.error, msg:
sys.stderr.write("\n%s\n" % str(msg))
sys.stderr.write(
- "usage: driver.py [-h|-x] [-m] [-n] [s] [file]\n")
+ "usage: driver.py [-h|-x] [-m] [-n] [-s] [-t] [file]\n")
sys.stderr.write("-h/-x -- HTML/XML input (default auto)\n")
sys.stderr.write("-m -- macro expansion only\n")
sys.stderr.write("-n -- turn off the Python 1.5.2 test\n")
sys.stderr.write("-s -- print intermediate code\n")
+ sys.stderr.write("-t -- leave tal/metal attributes in output\n")
sys.exit(2)
for o, a in opts:
if o == '-h':
@@ -131,6 +133,8 @@
mode = "xml"
if o == '-s':
showcode = 1
+ if o == '-t':
+ showtal = 1
if not versionTest:
if sys.version[:5] != "1.5.2":
sys.stderr.write(
@@ -142,14 +146,15 @@
file = FILE
it = compilefile(file, mode)
if showcode: showit(it)
- else: interpretit(it, tal=(not macros))
+ else: interpretit(it, tal=(not macros), showtal=showtal)
-def interpretit(it, engine=None, stream=None, tal=1):
+def interpretit(it, engine=None, stream=None, tal=1, showtal=-1):
from TALInterpreter import TALInterpreter
program, macros = it
if engine is None:
engine = DummyEngine(macros)
- TALInterpreter(program, macros, engine, stream, wrap=0, tal=tal)()
+ TALInterpreter(program, macros, engine, stream, wrap=0,
+ tal=tal, showtal=showtal)()
def compilefile(file, mode=None):
assert mode in ("html", "xml", None)