[Python-checkins] CVS: python/dist/src/Lib/xml/dom minidom.py,1.24,1.25 pulldom.py,1.18,1.19
Martin v. Löwis
loewis@users.sourceforge.net
Mon, 05 Feb 2001 17:16:08 -0800
- Previous message: [Python-checkins] CVS: python/dist/src/Lib os.py,1.40,1.41 ntpath.py,1.33,1.34 nturl2path.py,1.7,1.8 nntplib.py,1.24,1.25 netrc.py,1.9,1.10 mutex.py,1.7,1.8 multifile.py,1.14,1.15
- Next message: [Python-checkins] CVS: python/dist/src/Lib/test test_minidom.py,1.23,1.24
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/python/python/dist/src/Lib/xml/dom
In directory usw-pr-cvs1:/tmp/cvs-serv11973
Modified Files:
minidom.py pulldom.py
Log Message:
Do not allow empty qualifiedName in createDocument.
Rearrange pulldom to create documents with root element.
Provide clear methods so that the ContentHandler releases its hold on the
document.
Index: minidom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/minidom.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** minidom.py 2001/02/06 00:14:08 1.24
--- minidom.py 2001/02/06 01:16:06 1.25
***************
*** 652,666 ****
if doctype is None:
doctype = self.createDocumentType(qualifiedName, None, None)
! if qualifiedName:
! prefix, localname = _nssplit(qualifiedName)
! if prefix == "xml" \
! and namespaceURI != "http://www.w3.org/XML/1998/namespace":
! raise xml.dom.NamespaceErr("illegal use of 'xml' prefix")
! if prefix and not namespaceURI:
! raise xml.dom.NamespaceErr(
! "illegal use of prefix without namespaces")
! element = doc.createElementNS(namespaceURI, qualifiedName)
! doc.appendChild(element)
! # XXX else, raise an error? Empty qname is illegal in the DOM spec!
doctype.parentNode = doc
doc.doctype = doctype
--- 652,672 ----
if doctype is None:
doctype = self.createDocumentType(qualifiedName, None, None)
! if not qualifiedName:
! # The spec is unclear what to raise here; SyntaxErr
! # would be the other obvious candidate. Since Xerces raises
! # InvalidCharacterErr, and since SyntaxErr is not listed
! # for createDocument, that seems to be the better choice.
! # XXX: need to check for illegal characters here and in
! # createElement.
! raise xml.dom.InvalidCharacterErr("Element with no name")
! prefix, localname = _nssplit(qualifiedName)
! if prefix == "xml" \
! and namespaceURI != "http://www.w3.org/XML/1998/namespace":
! raise xml.dom.NamespaceErr("illegal use of 'xml' prefix")
! if prefix and not namespaceURI:
! raise xml.dom.NamespaceErr(
! "illegal use of prefix without namespaces")
! element = doc.createElementNS(namespaceURI, qualifiedName)
! doc.appendChild(element)
doctype.parentNode = doc
doc.doctype = doctype
***************
*** 762,765 ****
--- 768,772 ----
toktype, rootNode = events.getEvent()
events.expandNode(rootNode)
+ events.clear()
return rootNode
Index: pulldom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/pulldom.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -r1.18 -r1.19
*** pulldom.py 2001/02/05 18:50:15 1.18
--- pulldom.py 2001/02/06 01:16:06 1.19
***************
*** 62,70 ****
else:
tagName = localname
! node = self.document.createElementNS(uri, tagName)
else:
# When the tagname is not prefixed, it just appears as
# localname
! node = self.document.createElement(localname)
for aname,value in attrs.items():
--- 62,76 ----
else:
tagName = localname
! if self.document:
! node = self.document.createElementNS(uri, tagName)
! else:
! node = self.buildDocument(uri, tagName)
else:
# When the tagname is not prefixed, it just appears as
# localname
! if self.document:
! node = self.document.createElement(localname)
! else:
! node = self.buildDocument(None, localname)
for aname,value in attrs.items():
***************
*** 91,95 ****
def startElement(self, name, attrs):
! node = self.document.createElement(name)
for aname,value in attrs.items():
--- 97,104 ----
def startElement(self, name, attrs):
! if self.document:
! node = self.document.createElement(name)
! else:
! node = self.buildDocument(None, name)
for aname,value in attrs.items():
***************
*** 128,143 ****
def startDocument(self):
- publicId = systemId = None
- if self._locator:
- publicId = self._locator.getPublicId()
- systemId = self._locator.getSystemId()
if self.documentFactory is None:
import xml.dom.minidom
self.documentFactory = xml.dom.minidom.Document.implementation
! node = self.documentFactory.createDocument(None, publicId, systemId)
self.document = node
self.lastEvent[1] = [(START_DOCUMENT, node), None]
self.lastEvent = self.lastEvent[1]
self.push(node)
def endDocument(self):
--- 137,153 ----
def startDocument(self):
if self.documentFactory is None:
import xml.dom.minidom
self.documentFactory = xml.dom.minidom.Document.implementation
!
! def buildDocument(self, uri, tagname):
! # Can't do that in startDocument, since we need the tagname
! # XXX: obtain DocumentType
! node = self.documentFactory.createDocument(uri, tagname, None)
self.document = node
self.lastEvent[1] = [(START_DOCUMENT, node), None]
self.lastEvent = self.lastEvent[1]
self.push(node)
+ return node.firstChild
def endDocument(self):
***************
*** 145,148 ****
--- 155,162 ----
self.pop()
+ def clear(self):
+ "clear(): Explicitly release parsing structures"
+ self.document = None
+
class ErrorHandler:
def warning(self, exception):
***************
*** 199,202 ****
--- 213,223 ----
self.pulldom.firstEvent[1] = self.pulldom.firstEvent[1][1]
return rc
+
+ def clear(self):
+ "clear(): Explicitly release parsing objects"
+ self.pulldom.clear()
+ del self.pulldom
+ self.parser = None
+ self.stream = None
class SAX2DOM(PullDOM):
- Previous message: [Python-checkins] CVS: python/dist/src/Lib os.py,1.40,1.41 ntpath.py,1.33,1.34 nturl2path.py,1.7,1.8 nntplib.py,1.24,1.25 netrc.py,1.9,1.10 mutex.py,1.7,1.8 multifile.py,1.14,1.15
- Next message: [Python-checkins] CVS: python/dist/src/Lib/test test_minidom.py,1.23,1.24
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]