def deserialize(name_d, func_code_d, args_d, clos_d, type_obj):
"""A function to deserialize an object serialized with the serialize
function.
Args:
name_d(unicode): the dumped name of the object
func_code_d(unicode): the dumped byte code of the function
args_d(unicode): the dumped information about the arguments
clos_d(unicode): the dumped information about the function closure
Returns:
a deserialized object"""
if type_obj == 'func':
name = pickle.loads(name_d.encode('raw_unicode_escape'))
code = dill.loads(func_code_d.encode('raw_unicode_escape'))
args = pickle.loads(args_d.encode('raw_unicode_escape'))
clos = dill.loads(clos_d.encode('raw_unicode_escape'))
loaded_obj = types.FunctionType(code, globals(), name, args, clos)
else: # pragma: no cover
loaded_obj = dill.loads(func_code_d.encode('raw_unicode_escape'))
return loaded_obj
# Serialization utilities
评论列表
文章目录