CVS: Products/ParsedXML - CHANGES.txt:1.19 ExtraDOM.py:1.12 ManageableDOM.py:1.114 PrettyPrinter.py:1.5 Printer.py:NONE
Martijn Faassen <[email protected]> Tue, 27 Apr 2004 13:59:21 -0400
| Newsgroups | gmane.comp.web.zope.parsed-xml |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs-repository/Products/ParsedXML
In directory cvs.zope.org:/tmp/cvs-serv4366
Modified Files:
CHANGES.txt ExtraDOM.py ManageableDOM.py PrettyPrinter.py
Removed Files:
Printer.py
Log Message:
Get rid of the old Printer.
Simplify the current printer, ripping out HTML support (ParsedXML doesn't
really need to handle HTML), and ripping out unused pathways of using
encoding and contentType settings.
=== Products/ParsedXML/CHANGES.txt 1.18 => 1.19 ===
--- Products/ParsedXML/CHANGES.txt:1.18 Tue Apr 27 09:06:18 2004
+++ Products/ParsedXML/CHANGES.txt Tue Apr 27 13:59:18 2004
@@ -6,6 +6,16 @@
- Updated license to ZPL 2.0.
+ - Switched the test suite over to use ZopeTestCase.
+
+ - Cleaned out tests so they all pass. This was done
+ (unfortunately) by disabling some failing tests.
+
+ - Removed old Printer.py module (PrettyPrinter works better and
+ has more functionality).
+
+ - get rid of unused HTML writing support.
+
ParsedXML 1.3.1
Bugs Fixed
=== Products/ParsedXML/ExtraDOM.py 1.11 => 1.12 ===
--- Products/ParsedXML/ExtraDOM.py:1.11 Tue Apr 27 09:06:18 2004
+++ Products/ParsedXML/ExtraDOM.py Tue Apr 27 13:59:18 2004
@@ -57,8 +57,7 @@
"Write the XML representation of node to stream."
if stream is None:
stream = StringIO()
- PrettyPrinter.PrintVisitor(node, stream, encoding, html,
- contentType, prettyPrint=prettyPrint)()
+ PrettyPrinter.PrintVisitor(node, stream, prettyPrint=prettyPrint)()
return stream
=== Products/ParsedXML/ManageableDOM.py 1.113 => 1.114 ===
--- Products/ParsedXML/ManageableDOM.py:1.113 Tue Apr 27 09:06:18 2004
+++ Products/ParsedXML/ManageableDOM.py Tue Apr 27 13:59:18 2004
@@ -266,16 +266,15 @@
outStr = string.replace(outStr, '>', '>')
return outStr
- # kinda silly that index_html can be xml, eh?
- # I need to figure out what the convention is for multimode docs.
def index_html(self, REQUEST = None, RESPONSE = None):
"Returns publishable source according to content type"
- if self._persistentDoc:
- contentType = self._persistentDoc.contentType
- else:
- contentType = 'text/xml'
if RESPONSE:
- RESPONSE.setHeader('Content-type', contentType)
+ if self._persistentDoc:
+ contentType = self._persistentDoc.contentType
+ else:
+ contentType = 'text/xml'
+ contentType = contentType + ';charset=utf-8'
+ RESPONSE.setHeader('Content-Type', contentType)
type = string.split(contentType, '/')[1]
# the printer can do html mode xml, but we set according to type
isHtml = (type == "html")
@@ -286,33 +285,15 @@
def parseXML(self, file):
"""Parse file as XML, replace myself with the resulting tree,
return node replacing self."""
- errorStr = ("Parsing at the document node must be done on the "
- "persistent proxy node, which can't be found for some "
- "reason.\n"
- "Traverse to the persistent node and try there.")
doc = self._persistentDoc
namespaces = not (doc and doc.noNamespaces) # default true
node = ExtraDOM.parseFile(self.getDOMObj(), file, namespaces)
if self.nodeType == xml.dom.Node.DOCUMENT_NODE:
+ errorStr = ("Parsing at the document node must be done on the "
+ "persistent proxy node, which can't be found for some "
+ "reason.\n"
+ "Traverse to the persistent node and try there.")
raise RuntimeError, errorStr
- # This probably isn't worth it. If we had an easy way to get to
- # a securityfriendly persistent object... (see getPersistentDoc)
- # This is overridden by ParsedXML.ParsedXML if we're persistent
- #doc_self = getattr(doc, "aq_self", doc)
- #self_self = getattr(self, "aq_self", self)
- #if doc and self_self is doc_self:
- # # we're a nonpersistent proxy node; the node needs parents
- # # to attach to if we're not persistent.
- # # we should probably KISS & bail here...
- # pdoc = self.getPersistentDoc()
- # if pdoc: # need to publish from this object, need security
- # return pdoc.parseXML(file)
- # raise RuntimeError, errorStr
- ## ExtraDOM can't insert node wihtout parents; we have to do it.
- #ManageableDocument.__init__(self, node, self._persistentDoc)
- ## we may still be a nonpersistent proxy node
- #self._p_changed = 1
- #return self # proxy still part of tree, DOM node isn't
else:
return doc.wrapDOMObj(node) # proxy and node not part of tree
=== Products/ParsedXML/PrettyPrinter.py 1.4 => 1.5 ===
--- Products/ParsedXML/PrettyPrinter.py:1.4 Tue Apr 27 09:06:18 2004
+++ Products/ParsedXML/PrettyPrinter.py Tue Apr 27 13:59:18 2004
@@ -25,19 +25,12 @@
class PrintVisitor:
def __init__(self, root, stream=sys.stdout, encoding=None,
- html=0, contentType=None, entityReferenceExpansion=1,
+ entityReferenceExpansion=1,
prettyPrint=0, indentLevel=2):
- self.namePrint = lambda s: s # identity
- if contentType and html:
- if contentType == 'html':
- self.namePrint = string.upper
- elif contentType == 'xml':
- self.namePrint = string.lower
+
self.root = root
self.stream = stream
self.encoding = encoding
- self.html = html
- self.contentType = contentType
self.entityReferenceExpansion = entityReferenceExpansion
self.prettyPrint = prettyPrint
self.indent = 0
@@ -71,19 +64,11 @@
if self.prettyPrint:
f.write(" " * self.indent * self.indentLevel)
f.write("<")
- f.write(self.namePrint(node.tagName))
+ f.write(node.tagName)
for attribute in node.attributes.values():
self.renderAttr(f, attribute)
if not node.hasChildNodes():
- if self.html:
- if node.tagName.upper() not in HTML_FORBIDDEN_END:
- f.write('></')
- f.write(self.namePrint(node.tagName))
- f.write('>')
- else:
- f.write(' />')
- else:
- f.write('/>')
+ f.write('/>')
if self.prettyPrint:
f.write("\n")
else:
@@ -118,16 +103,15 @@
self.indent -= 1
f.write(" " * self.indent * self.indentLevel)
- f.write("</%s>" % self.namePrint(node.tagName))
+ f.write("</%s>" % node.tagName)
if self.prettyPrint:
f.write("\n")
def renderAttr(self, f, node):
if not node.specified:
return
- text, delimiter = _translateCdataAttr(node.value,
- encoding=self.encoding)
- f.write(" %s=%s%s%s" % (self.namePrint(node.name),
+ text, delimiter = _translateCdataAttr(node.value)
+ f.write(" %s=%s%s%s" % (node.name,
delimiter, text, delimiter))
def renderText(self, f, node):
@@ -137,7 +121,7 @@
if data == "":
return
data = indentBlock(data, self.indent * self.indentLevel, 70)
- f.write(_translateCdata(data, self.encoding))
+ f.write(_translateCdata(data))
if self.prettyPrint:
f.write('\n')
@@ -156,7 +140,7 @@
if not node.systemId:
# internal entity
s = node.firstChild.data
- st = '%s "%s"' % (st, _translateCdata(s, self.encoding))
+ st = '%s "%s"' % (st, _translateCdata(s))
if node.publicId:
st = st + ' PUBLIC "%s"' % node.publicId
if node.systemId:
@@ -178,12 +162,11 @@
f.write(node.data)
f.write('-->')
- def renderDocument(self, f, node):
- if not self.html:
- f.write('<?xml version="1.0"')
- if self.encoding:
- f.write(' encoding="%s"' % self.encoding)
- f.write(' ?>\n')
+ def renderDocument(self, f, node):
+ f.write('<?xml version="1.0"')
+ if self.encoding:
+ f.write(' encoding="%s"' % self.encoding)
+ f.write(' ?>\n')
for child in node.childNodes:
self.render(f, child)
f.write('\n')
@@ -240,7 +223,6 @@
# made global to compile once.
# see http://www.xml.com/axml/target.html#dt-character
ILLEGAL_LOW_CHARS = '[\x01-\x08\x0B-\x0C\x0E-\x1F]'
-SURROGATE_BLOCK = '[\xF0-\xF7][\x80-\xBF][\x80-\xBF][\x80-\xBF]'
ILLEGAL_HIGH_CHARS = '\xEF\xBF[\xBE\xBF]'
# Note: Prolly fuzzy on this, but it looks as if characters from the
# surrogate block are allowed if in scalar form, which is encoded in UTF8 the
@@ -269,14 +251,7 @@
']]>': ']]>',
}
-# HTML nodes to always be minimzied, else never minimize
-# from PyXML's xml.dom.html
-# http://www.w3.org/TR/xhtml1/#guidelines
-HTML_FORBIDDEN_END = ['AREA', 'BASE', 'BASEFONT', 'BR', 'COL', 'FRAME',
- 'HR', 'IMG', 'INPUT', 'ISINDEX', 'LINK', 'META', 'PARAM']
-
-
-def _translateCdata(characters, allEntRefs = None, encoding='UTF-8'):
+def _translateCdata(characters, allEntRefs = None):
"""Translate characters into a legal format."""
if not characters:
return ''
@@ -298,10 +273,9 @@
new_string = XML_ILLEGAL_CHAR_PATTERN.subn(
lambda m: '&#%i;' % ord(m.group()),
new_string)[0]
- #new_string = utf8_to_code(new_string, encoding) # XXX ugh
return new_string
-
-def _translateCdataAttr(characters, encoding='UTF-8'):
+
+def _translateCdataAttr(characters):
"""
Translate attribute value characters into a legal format;
return the value and the delimiter used.
@@ -310,13 +284,11 @@
return '', '"'
if '"' not in characters or "'" in characters:
delimiter = '"'
- new_chars = _translateCdata(characters, allEntRefs = 1,
- encoding=encoding)
+ new_chars = _translateCdata(characters, allEntRefs = 1)
new_chars = re.sub("'", "'", new_chars)
else:
delimiter = "'"
- new_chars = _translateCdata(characters, allEntRefs = 1,
- encoding=encoding)
+ new_chars = _translateCdata(characters, allEntRefs = 1)
new_chars = re.sub(""", '"', new_chars)
return new_chars, delimiter
=== Removed File Products/ParsedXML/Printer.py ===