lodum.pickle module provides secure pickle serialization and deserialization for lodum-enabled classes with built-in safety checks.
Security
Thelodum.pickle module uses a SafeUnpickler that only allows safe, lodum-enabled classes to be loaded. It blocks potentially dangerous modules like os, sys, and subprocess to prevent arbitrary code execution.
Functions
dump
The object to encode. Must be a lodum-enabled class instance.
Optional file-like object or Path to write to.
Additional arguments for
pickle.dump(s).target is None, otherwise None.
Example:
dumps
dump(obj).
The object to encode.
Additional arguments for
pickle.dumps.load
The class to instantiate.
Pickle bytes, file-like object, or Path.
Maximum allowed size for bytes input.
cls.
Raises:
DeserializationErrorif the input is invalid, exceedsmax_size, or contains unsafe classes.pickle.UnpicklingErrorif attempting to unpickle a non-lodum type or unsafe module.
loads
load(cls, source).
The class to instantiate.
Pickle bytes to parse.
Additional arguments (e.g.,
max_size).cls.
SafeUnpickler
TheSafeUnpickler class restricts unpickling to safe types:
Allowed built-in types:
int,float,str,bool,bytes,bytearraylist,tuple,dict,set,frozensetcomplex,NoneType,type
collections.defaultdict,collections.OrderedDict,collections.Counterarray.array,array._array_reconstructor
- Only classes decorated with
@lodum(having_lodum_enabledattribute)
os,sys,subprocess(to prevent code execution)