Merge changes of PyXML 1.13:

Use nodeName, not tagName in attributes.
Provide get method for dictionary-like objects.
Use DOM exceptions instead of standard exceptions.
This commit is contained in:
Martin v. Löwis 2001-01-27 08:38:34 +00:00
parent e3fc722628
commit d5fb58f1e3
1 changed files with 10 additions and 9 deletions

View File

@ -31,8 +31,6 @@ del types
import xml.dom
_Node = xml.dom.Node
del xml
class Node(_Node):
allnodes = {}
@ -317,7 +315,7 @@ class NamedNodeMap:
def items(self):
L = []
for node in self._attrs.values():
L.append((node.tagName, node.value))
L.append((node.nodeName, node.value))
return L
def itemsNS(self):
@ -335,6 +333,9 @@ class NamedNodeMap:
def values(self):
return self._attrs.values()
def get(self, name, value = None):
return self._attrs.get(name, value)
def __len__(self):
return self.length
@ -453,7 +454,7 @@ class Element(Node):
def setAttributeNode(self, attr):
if attr.ownerElement not in (None, self):
raise ValueError, "attribute node already owned"
raise xml.dom.InuseAttributeErr("attribute node already owned")
old = self._attrs.get(attr.name, None)
if old:
old.unlink()
@ -567,7 +568,7 @@ class Text(Node):
def splitText(self, offset):
if offset < 0 or offset > len(self.data):
raise ValueError, "illegal offset value for splitText()"
raise xml.dom.IndexSizeErr("illegal offset value")
newText = Text(self.data[offset:])
next = self.nextSibling
if self.parentNode and self in self.parentNode.childNodes:
@ -616,7 +617,7 @@ class DOMImplementation:
def createDocument(self, namespaceURI, qualifiedName, doctype):
if doctype and doctype.parentNode is not None:
raise ValueError, "doctype object owned by another DOM tree"
raise xml.dom.WrongDocumentErr("doctype object owned by another DOM tree")
doc = Document()
if doctype is None:
doctype = self.createDocumentType(qualifiedName, None, None)
@ -624,9 +625,9 @@ class DOMImplementation:
prefix, localname = _nssplit(qualifiedName)
if prefix == "xml" \
and namespaceURI != "http://www.w3.org/XML/1998/namespace":
raise ValueError, "illegal use of 'xml' prefix"
raise xml.dom.NamespaceErr("illegal use of 'xml' prefix")
if prefix and not namespaceURI:
raise ValueError, "illegal use of prefix without namespaces"
raise xml.dom.NamespaceErr("illegal use of prefix without namespaces")
doctype.parentNode = doc
doc.doctype = doctype
doc.implementation = self
@ -660,7 +661,7 @@ class Document(Node):
if node.nodeType == Node.ELEMENT_NODE \
and self._get_documentElement():
raise TypeError, "two document elements disallowed"
raise xml.dom.HierarchyRequestErr("two document elements disallowed")
return Node.appendChild(self, node)
def removeChild(self, oldChild):