1 """Provides a serializer for arbitrary Python objects"""
3 jsonpickle
.set_encoder_options('simplejson', indent
=4)
11 utils
.write(path
, encode(obj
))
16 return decode(utils
.slurp(path
))
20 # Go in and out of encode/decode to return a clone
21 return decode(encode(obj
))
25 handler
= _gethandler(obj
)
27 handler
.pre_encode_hook()
28 jsonstr
= jsonpickle
.encode(obj
)
30 handler
.post_encode_hook()
35 obj
= jsonpickle
.decode(jsonstr
)
36 handler
= _gethandler(obj
)
38 handler
.post_decode_hook()
44 # Allow base classes to provide a serialization handlers
45 # for their subclasses
46 if hasattr(cls
, 'mro'):
47 for supercls
in cls
.mro():
48 if supercls
in handlers
:
49 return handlers
[supercls
](obj
)
51 return handlers
[cls
](obj
)