Pickle Serializer

pickle-based packet serializer module.

Danger

Read the security considerations for using pickle module.

class easynetwork.serializers.pickle.PickleSerializer

Bases: AbstractPacketSerializer[Any, Any]

A one-shot serializer built on top of the pickle module.

See also

How-to — Serializer Combinations

This class cannot be used directly with a StreamProtocol. This page explains possible workarounds.

__init__(pickler_config: PicklerConfig | None = None, unpickler_config: UnpicklerConfig | None = None, *, pickler_cls: type[TypeAliasForwardRef('pickle.Pickler')] | None = None, unpickler_cls: type[TypeAliasForwardRef('pickle.Unpickler')] | None = None, pickler_optimize: bool = False, debug: bool = False) None
Parameters:
final serialize(packet: Any) bytes

Returns the pickle representation of the Python object packet.

Roughly equivalent to:

def serialize(self, packet):
    return pickle.dumps(packet)
Parameters:

packet (Any) – The Python object to serialize.

Returns:

a byte sequence.

Return type:

bytes

final deserialize(data: bytes) Any

Creates a Python object representing the raw pickle packet from data.

Roughly equivalent to:

def deserialize(self, data):
    return pickle.loads(data)
Parameters:

data (bytes) – The byte sequence to deserialize.

Raises:
Returns:

the deserialized Python object.

Return type:

Any

property debug: bool

The debug mode flag. Read-only attribute.

Configuration

class easynetwork.serializers.pickle.PicklerConfig

Bases: object

A dataclass with the Pickler options.

See pickle.Pickler for details.

protocol: int
fix_imports: bool = False
__init__(*, protocol: int = <factory>, fix_imports: bool = False) None
class easynetwork.serializers.pickle.UnpicklerConfig

Bases: object

A dataclass with the Unpickler options.

See pickle.Unpickler for details.

fix_imports: bool = False
encoding: str = 'utf-8'
errors: str = 'strict'
__init__(*, fix_imports: bool = False, encoding: str = 'utf-8', errors: str = 'strict') None