]> granicus.if.org Git - python/commitdiff
Merge changes of PyXML 1.13:
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 27 Jan 2001 08:38:34 +0000 (08:38 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 27 Jan 2001 08:38:34 +0000 (08:38 +0000)
Use nodeName, not tagName in attributes.
Provide get method for dictionary-like objects.
Use DOM exceptions instead of standard exceptions.

Lib/xml/dom/minidom.py

index 65af4c72315dab1c2d7165389f457b576628cda4..54cdea4dfb28a0c93ce9ef1bf5b923ce2cb6fecf 100644 (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):