diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_minidom.py | 11 | ||||
-rw-r--r-- | Lib/xml/dom/minidom.py | 3 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_minidom.py b/Lib/test/test_minidom.py index 4574803..5cc1e69 100644 --- a/Lib/test/test_minidom.py +++ b/Lib/test/test_minidom.py @@ -98,6 +98,17 @@ def testLegalChildren(): else: print "dom.appendChild didn't raise HierarchyRequestErr" + nodemap = elem.attributes + try: nodemap.setNamedItem(text) + except HierarchyRequestErr: pass + else: + print "NamedNodeMap.setNamedItem didn't raise HierarchyRequestErr" + + try: nodemap.setNamedItemNS(text) + except HierarchyRequestErr: pass + else: + print "NamedNodeMap.setNamedItemNS didn't raise HierarchyRequestErr" + elem.appendChild(text) dom.unlink() diff --git a/Lib/xml/dom/minidom.py b/Lib/xml/dom/minidom.py index ef1a2bf..b4ae267 100644 --- a/Lib/xml/dom/minidom.py +++ b/Lib/xml/dom/minidom.py @@ -378,6 +378,9 @@ class NamedNodeMap: self.setNamedItem(node) def setNamedItem(self, node): + if not isinstance(node, Attr): + raise HierarchyRequestErr, \ + "%s cannot be child of %s" % (repr(node), repr(self)) old = self._attrs.get(node.name) if old: old.unlink() |