[lxml-dev] merging the ElementTree changes
Hi there, Stefan, all, I've been pondering over the changes Stefan implemented to make the ElementTree class work more like the original elementtree implementation, where multiple ElementTree's can exist for a single tree without affecting tree structure. I would like to see fakeRootDocument to be changed so that the fake document temporarily also fixes the parent reference, so that libxml2 is never exposed to inconsistent document structures. Of course now that I think of it, doing that may cause problems with namespace lookups and the like... Ugh... :( Anyway, still, I've decided the benefits outweigh the costs, even though I do feel uncomfortable about it. If you, Stefan, are willing to merge this set of changes before I do, then please do so. Otherwise I'll try to get around to it at the end of this week. Regards, Martijn
Martijn Faassen wrote:
I've been pondering over the changes Stefan implemented to make the ElementTree class work more like the original elementtree implementation, where multiple ElementTree's can exist for a single tree without affecting tree structure.
I would like to see fakeRootDocument to be changed so that the fake document temporarily also fixes the parent reference, so that libxml2 is never exposed to inconsistent document structures. Of course now that I think of it, doing that may cause problems with namespace lookups and the like... Ugh... :(
Anyway, still, I've decided the benefits outweigh the costs, even though I do feel uncomfortable about it.
If you, Stefan, are willing to merge this set of changes before I do, then please do so. Otherwise I'll try to get around to it at the end of this week.
I just applied the update to the trunk. I had to rewrite some smaller parts in xslt.pxi, since I had already added another major update to that file in scoder1/2 that implements XPath/XSLT extensions, so I couldn't reuse it as-is. I now use the documentOrRaise functions at a few places, which allows calls like XSLT() to accept either _ElementTree, _Element or (internally) _Document objects. I modified _fakeRootDoc to store the original context node in the _private field of the copied node, since this field is not used during any calls to libxml/xslt that is wrapped by the fake document calls. I then reset the parent pointers from that field when destroying the document after use. All tests pass, including those that I added from the scoder2 branch to test the new behaviour and to compare it to FL's ElementTree. Have fun - and feel free to give it some more testing. Stefan
participants (2)
-
Martijn Faassen -
Stefan Behnel