serialize a class to XML and back

Irmen de Jong irmen.NOSPAM at xs4all.nl
Mon May 27 14:45:07 EDT 2013


On 27-5-2013 2:39, Roy Smith wrote:
> In article <51a28f42$0$15870$e4fe514c at news.xs4all.nl>,
>  Irmen de Jong <irmen.NOSPAM at xs4all.nl> wrote:
> 
>> On 26-5-2013 22:48, Roy Smith wrote:
>>
>>> The advantage of pickle over json is that pickle can serialize many 
>>> types of objects that json can't.  The other side of the coin is that 
>>> pickle is python-specific, so if you think you'll ever need to read your 
>>> data from other languages, pickle is right out.
>>
>> That is not entirely true :)  I've written a pickle implementation for Java 
>> and .NET
>> that is almost feature complete; it is part of 
>> http://pythonhosted.org/Pyro4/pyrolite.html
> 
> Very cool
> 
>> Still, pickle may not be the best choice here.
> 
> Perhaps not, but lots of points for the awesomeness factor.
> 

Thanks for the praise :)

There's another interesting thing perhaps to also mention about Pyrolite. Its Pickle
implementation obviously maps built in types to their counterparts in Java/.NET, but it
is also capable of unpickling custom classes. It defaults to outputting a simple
hashtable with the class's properties in it, but you can also provide a custom
deserializer to recreate a custom object (it already does this automatically for a few
complex types such as DateTime, BigDecimal, and a bunch of Pyro specific types).

As the unpicklers are not executing any Java or .NET code dynamically they are not
susceptible to the security issue that Python's pickle has. Still: tread with care.
(Especially if you use the lib to pickle stuff and unpickle it on the Python side).

Also, the one missing feature is memo-ing when pickling so that you can pickle recursive
object graphs. It now throws a stack overflow exception instead.


Irmen





More information about the Python-list mailing list