Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5fb58f

Browse files
committed
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.
1 parent e3fc722 commit d5fb58f

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

Lib/xml/dom/minidom.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
import xml.dom
3333
_Node = xml.dom.Node
34-
del xml
35-
3634

3735
class Node(_Node):
3836
allnodes = {}
@@ -317,7 +315,7 @@ def item(self, index):
317315
def items(self):
318316
L = []
319317
for node in self._attrs.values():
320-
L.append((node.tagName, node.value))
318+
L.append((node.nodeName, node.value))
321319
return L
322320

323321
def itemsNS(self):
@@ -335,6 +333,9 @@ def keysNS(self):
335333
def values(self):
336334
return self._attrs.values()
337335

336+
def get(self, name, value = None):
337+
return self._attrs.get(name, value)
338+
338339
def __len__(self):
339340
return self.length
340341

@@ -453,7 +454,7 @@ def getAttributeNodeNS(self, namespaceURI, localName):
453454

454455
def setAttributeNode(self, attr):
455456
if attr.ownerElement not in (None, self):
456-
raise ValueError, "attribute node already owned"
457+
raise xml.dom.InuseAttributeErr("attribute node already owned")
457458
old = self._attrs.get(attr.name, None)
458459
if old:
459460
old.unlink()
@@ -567,7 +568,7 @@ def __repr__(self):
567568

568569
def splitText(self, offset):
569570
if offset < 0 or offset > len(self.data):
570-
raise ValueError, "illegal offset value for splitText()"
571+
raise xml.dom.IndexSizeErr("illegal offset value")
571572
newText = Text(self.data[offset:])
572573
next = self.nextSibling
573574
if self.parentNode and self in self.parentNode.childNodes:
@@ -616,17 +617,17 @@ def hasFeature(self, feature, version):
616617

617618
def createDocument(self, namespaceURI, qualifiedName, doctype):
618619
if doctype and doctype.parentNode is not None:
619-
raise ValueError, "doctype object owned by another DOM tree"
620+
raise xml.dom.WrongDocumentErr("doctype object owned by another DOM tree")
620621
doc = Document()
621622
if doctype is None:
622623
doctype = self.createDocumentType(qualifiedName, None, None)
623624
if qualifiedName:
624625
prefix, localname = _nssplit(qualifiedName)
625626
if prefix == "xml" \
626627
and namespaceURI != "http://www.w3.org/XML/1998/namespace":
627-
raise ValueError, "illegal use of 'xml' prefix"
628+
raise xml.dom.NamespaceErr("illegal use of 'xml' prefix")
628629
if prefix and not namespaceURI:
629-
raise ValueError, "illegal use of prefix without namespaces"
630+
raise xml.dom.NamespaceErr("illegal use of prefix without namespaces")
630631
doctype.parentNode = doc
631632
doc.doctype = doctype
632633
doc.implementation = self
@@ -660,7 +661,7 @@ def appendChild(self, node):
660661

661662
if node.nodeType == Node.ELEMENT_NODE \
662663
and self._get_documentElement():
663-
raise TypeError, "two document elements disallowed"
664+
raise xml.dom.HierarchyRequestErr("two document elements disallowed")
664665
return Node.appendChild(self, node)
665666

666667
def removeChild(self, oldChild):

0 commit comments

Comments
 (0)