PseudoPickler
A simple plugin to work like pickle, in that it should
hopefully support serializing arbitrary python objects, but which
doesn’t attempt to put stuff down to a single bytearray
, instead
supporting objects with to_state
and from_state
methods by converting
them to more primitive serializble types like arrays, strings, numbers,
etc.
Falls back to naive pickling when necessary.
__init__(self, allow_pickle=False, protocol=1, b64encode=False):
to_state(self, obj, cache=None):
Tries to extract state from obj
, first through its to_state
interface, but that failing by recursively walking the object
tree
obj
:Any
:returns
:_
serialize(self, obj, cache=None):
Serializes an object first by checking for a to_state
method, and that missing, by converting to primitive-ish types
in a recursive strategy if the object passes is_simple
, otherwise
falling back to pickle
obj
:Any
object to be serialized
:returns
:dict
s p e c
f o r
t h e
p s e u d o - p i c k l e d
d a t a
deserialize(self, spec):
Deserializes from an object spec, dispatching to regular pickle where necessary
object
:Any
:returns
:_