[Zpt] CVS: Packages/TAL - HTMLTALParser.py:1.9 nsgmllib.py:1.8
guido@digicool.com
guido@digicool.com
Thu, 15 Mar 2001 14:00:42 -0500 (EST)
Update of /cvs-repository/Packages/TAL
In directory korak:/tmp/cvs-serv31176
Modified Files:
HTMLTALParser.py nsgmllib.py
Log Message:
Move the unescaping of & etc. in attribute values to nsgmlparser.
Add new test files for HTML, plus their output (not yet hand-checked).
Fix the input *and* output for test9 -- it was referencing an
undefined macro before.
--- Updated File HTMLTALParser.py in package Packages/TAL --
--- HTMLTALParser.py 2001/03/15 18:41:50 1.8
+++ HTMLTALParser.py 2001/03/15 19:00:41 1.9
@@ -146,13 +146,11 @@
prefix, suffix = string.split(key, ':', 1)
nsuri = self.nsdict.get(prefix)
if nsuri == ZOPE_METAL_NS:
- value = unescape(value)
item = (key, value)
metaldict[suffix] = value
if suffix == "define-macro":
item = (key,value,"macroHack")
elif nsuri == ZOPE_TAL_NS:
- value = unescape(value)
item = (key, value)
taldict[suffix] = value
attrlist.append(item)
@@ -206,13 +204,3 @@
def handle_pi(self, data):
self.gen.emitRawText("<?%s>" % data)
-
-# Helper
-
-def unescape(s):
- if '&' not in s:
- return s
- s = string.replace(s, "<", "<")
- s = string.replace(s, ">", ">")
- s = string.replace(s, "&", "&") # Must be last
- return s
--- Updated File nsgmllib.py in package Packages/TAL --
--- nsgmllib.py 2001/03/15 18:19:14 1.7
+++ nsgmllib.py 2001/03/15 19:00:41 1.8
@@ -239,6 +239,7 @@
elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
attrvalue[:1] == '"' == attrvalue[-1:]:
attrvalue = attrvalue[1:-1]
+ attrvalue = self.unescape(attrvalue)
attrs.append((string.lower(attrname), attrvalue))
k = m.end(0)
if rawdata[j:j+1] == '/>':
@@ -371,6 +372,17 @@
def unknown_endtag(self, tag): pass
def unknown_charref(self, ref): pass
def unknown_entityref(self, ref): pass
+
+ # Helper to remove special character quoting
+ def unescape(self, s):
+ if '&' not in s:
+ return s
+ s = string.replace(s, "<", "<")
+ s = string.replace(s, ">", ">")
+ s = string.replace(s, "'", "'")
+ s = string.replace(s, """, '"')
+ s = string.replace(s, "&", "&") # Must be last
+ return s
class TestSGMLParser(SGMLParser):