diff -r 76445d7e613f Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py Sun May 20 15:37:33 2012 +0100 +++ b/Lib/test/test_minidom.py Sun May 20 12:17:34 2012 -0700 @@ -1521,6 +1521,19 @@ num_children_after = len(doc.childNodes) self.assertTrue(num_children_after == num_children_before - 1) + def testCloneOrphanElement(self): + node_name = 'foo' + element = xml.dom.minidom.Element(node_name) + clone = element.cloneNode(False) + self.assertEquals(clone.nodeName, node_name) + self.assertIsNone(clone.ownerDocument) + + def testImportingOrphanElementInDocument(self): + node_name = 'foo' + element = xml.dom.minidom.Element(node_name) + document = xml.dom.minidom.Document() + document.importNode(element, False) + def test_main(): run_unittest(MinidomTest) diff -r 76445d7e613f Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Sun May 20 15:37:33 2012 +0100 +++ b/Lib/xml/dom/minidom.py Sun May 20 12:17:34 2012 -0700 @@ -200,7 +200,8 @@ self.childNodes[:] = L def cloneNode(self, deep): - return _clone_node(self, deep, self.ownerDocument or self) + return _clone_node(self, deep, self.documentOwner or Document()) + def isSupported(self, feature, version): return self.ownerDocument.implementation.hasFeature(feature, version) @@ -661,8 +662,8 @@ _no_type = TypeInfo(None, None) class Element(Node): - __slots__=('ownerDocument', 'parentNode', 'tagName', 'nodeName', 'prefix', - 'namespaceURI', '_localName', 'childNodes', '_attrs', '_attrsNS', + __slots__=('parentNode', 'tagName', 'nodeName', 'prefix', 'namespaceURI', + '_localName', 'childNodes', '_attrs', '_attrsNS', 'nextSibling', 'previousSibling') nodeType = Node.ELEMENT_NODE nodeValue = None @@ -1861,7 +1862,7 @@ Clone a node and give it the new owner document. Called by Node.cloneNode and Document.importNode """ - if node.ownerDocument.isSameNode(newOwnerDocument): + if node.ownerDocument and node.ownerDocument.isSameNode(newOwnerDocument): operation = xml.dom.UserDataHandler.NODE_CLONED else: operation = xml.dom.UserDataHandler.NODE_IMPORTED diff -r 76445d7e613f Misc/ACKS --- a/Misc/ACKS Sun May 20 15:37:33 2012 +0100 +++ b/Misc/ACKS Sun May 20 12:17:34 2012 -0700 @@ -1143,6 +1143,7 @@ Bernard Yue Moshe Zadka Milan Zamazal +Alexandre Zani Artur Zaprzala Mike Zarnstorff Siebren van der Zee