Minidom bug: User-data handlers on attributes fail to fire...
| Newsgroups | gmane.comp.python.xml |
|---|---|
| Message-ID | <[email protected]> |
Summary User-data handlers on attributes fail to fire when deep cloning an element. (I think this is the right mailing-list for these sorts of things, if not then please direct me to where I want to be :) I have attached a py.test-style test case (ie: code that only falls over in the presence of the bug). I have attached a 2 line patch that fixes the bug. To whoever is in charge of mindom.py, please review and commit :) --anjansamanta _______________________________________________ XML-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/xml-sig
test_minidom.py
(application/x-python, 1.5 KB)
#-------------------------------------------------------------------------------
# Import the bits and pieces that we want to test ...
from xml.dom.minidom import getDOMImplementation
#-------------------------------------------------------------------------------
class CopyUserData:
# Ref: http://www.w3.org/TR/DOM-Level-3-Core/core.html#UserDataHandler
NODE_CLONED = 1
def handle(self, operation, key, data, src, dst):
assert operation == self.NODE_CLONED
assert key == 'fish'
assert data == 'meow'
dst.setUserData(key, data, self)
def test_cloneNode_and_user_data_handlers_on_attributes():
# Create DOM tree for: <a b=''/> ...
tree = getDOMImplementation().createDocument(None, 'a', None)
tree.firstChild.setAttribute('b', '')
elemA = tree.firstChild
attrB = elemA.getAttributeNode('b')
# Set some user data ...
attrB.setUserData('fish', 'meow', CopyUserData())
# Check that setUserData() really worked ...
assert attrB.getUserData('fish') == 'meow'
# Let's try just cloning the attribute ...
attrB2 = attrB.cloneNode(0)
attrB3 = attrB.cloneNode(1)
# Check that the user-data got copied ...
assert attrB2.getUserData('fish') == 'meow'
assert attrB3.getUserData('fish') == 'meow'
# Let's try cloning the element containing the attribute ...
elemA4 = elemA.cloneNode(1)
attrB4 = elemA4.getAttributeNode('b')
# Check that the user-data got copied ...
assert attrB4.getUserData('fish') == 'meow'
#-------------------------------------------------------------------------------
# END.
minidom-1.90-cloneNode.patch
(text/x-diff, 515 B)
--- minidom-1.90.py 2006-09-26 00:40:51.861071000 +0100
+++ minidom.py 2006-09-26 00:58:45.080917336 +0100
@@ -1824,6 +1824,8 @@
clone.setAttributeNS(attr.namespaceURI, attr.nodeName, attr.value)
a = clone.getAttributeNodeNS(attr.namespaceURI, attr.localName)
a.specified = attr.specified
+ if hasattr(attr, '_call_user_data_handler'):
+ attr._call_user_data_handler(operation, attr, a)
if deep:
for child in node.childNodes: