GNOME Bugzilla – Bug 345961
provide a __hash__ method for xmlNode objects
Last modified: 2006-06-26 19:44:26 UTC
Hi, here's another feature that I need when I want to use libxml2's python bindings. It adds the __hash__ function to xmlCore (and thus to all xmlNode objects), so that xmlNode's can be used as key for python dictionaries. The patch uses the xmlNodePtr and lets the python function PyLong_FromVoidPtr create a long for the pointer. This way __hash__ always returns the same value when the underlying C-Node is the same, which is needed as libxml2 creates new python objects on each call to children, for example. Patch will be attached and also includes a small testcase. I would try to also test what happens when an invalid node is given to the function, but I didn't know how to create an invalid xmlNode from within python. Andreas
Created attachment 68031 [details] [review] adds a __hash__ function to xmlCore As I explained in the report, this adds the __hash__ function to xmlCore which uses the xmlNodePtr for the returned long value.
I have combined this request with bug 345779, included the testing within the other test program, and committed to CVS. Bill
Thanks for that. Will this be available in libxml 2.7 oder only in 3.x? I'd just like to know what I have to state in the requirements for my application...
Unless someone discovers any problem caused by this change, it will appear in the next release (presumably 2.6.27), so currently your requirement would be libxml2 >= 2.6.27