[lxml-dev] Pickling objectified trees

Christian Zagrodnick cz at gocept.com
Mon Jun 9 10:06:33 CEST 2008


On 2008-06-09 09:50:54 +0200, Christian Zagrodnick <cz at gocept.com> said:

> Hi!
> 
> On 2007-02-25 15:06:00 +0100, Stefan Behnel <stefan_ml at behnel.de> said:
>> Christian Zagrodnick wrote:
>>> the other day I had to pickle objectified trees. I just thought to
>>> share my findings.
>>> 
> 
>>> You might consider just registering the reduce function in lxml itself.
>> 
> 
>> Interesting. Sure, why not? Objectify is totally about data classes after
>  all.
>> 
> 
>> Applied to the trunk (with small changes).
> 
> 
> I found a may-be-considered-a-bug. The script below shows that when
> 
> pickling the <cp/> node, the processing instruction is ommited.
> 
> When trying to pickle the root tree, the error is raised.
> 
> The problem is, that we pickle the `xml` object and get it back with
> 
> all its descendants. But after unpickling the whole tree is not as it
> 
> was before. So that's actually a bug.
> 
> I guess the best would be to
> 
> a) always serialize the roottree on pickle and
> b) remember which part of the tree actually was pickelt so on unpickle
> 
> this exact object can be restored.
> 
> I got to play with this a bit before I can deliver some useful code, thogh.

Well for pickling the root node all it really takes is to use the 
getroottree() for serializing. The fromstring method returns the right 
object anyway.

-- 
Christian Zagrodnick · cz at gocept.com
gocept gmbh & co. kg · forsterstraße 29 · 06112 halle (saale) · germany
http://gocept.com · tel +49 345 1229889 4 · fax +49 345 1229889 1
Zope and Plone consulting and development




More information about the lxml-dev mailing list