|
|
|
@ -5,7 +5,7 @@ Preserve is a simple framework to painlessly convert your python objects and
|
|
|
|
data structures into a nested structure containing only primitive types.
|
|
|
|
data structures into a nested structure containing only primitive types.
|
|
|
|
|
|
|
|
|
|
|
|
While intended for use in serialisation, Preserve stops short of the actual
|
|
|
|
While intended for use in serialisation, Preserve stops short of the actual
|
|
|
|
serialisation bit - you can then use whatever method you prefer to dump
|
|
|
|
serialisation bit - you can then use whatever method you prefer to dump
|
|
|
|
the nested primitive structure to JSON, TOML, or some other message packing
|
|
|
|
the nested primitive structure to JSON, TOML, or some other message packing
|
|
|
|
or storage system - most of which handle all primitive types by default.
|
|
|
|
or storage system - most of which handle all primitive types by default.
|
|
|
|
|
|
|
|
|
|
|
|
@ -41,12 +41,12 @@ to class instances.
|
|
|
|
def preservable(cls, restore_method=RestoreMethod.DIRECT, name=None):
|
|
|
|
def preservable(cls, restore_method=RestoreMethod.DIRECT, name=None):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Decorator to mark class as preservable and keep track of associated names
|
|
|
|
Decorator to mark class as preservable and keep track of associated names
|
|
|
|
and classes.
|
|
|
|
and classes.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
restore_method: One of the available preserve.RestoreMethod values.
|
|
|
|
restore_method: One of the available preserve.RestoreMethod values.
|
|
|
|
Sets the method used for restoring this class. Defaults to
|
|
|
|
Sets the method used for restoring this class. Defaults to
|
|
|
|
``DIRECT``, skipping the ``__init__`` method and setting all
|
|
|
|
``DIRECT``, skipping the ``__init__`` method and setting all
|
|
|
|
attributes as they were.
|
|
|
|
attributes as they were.
|
|
|
|
name: The string used to indentify this class in the preserved dict.
|
|
|
|
name: The string used to indentify this class in the preserved dict.
|
|
|
|
Must be unique among all ``@preservable`` classes. Defaults to the
|
|
|
|
Must be unique among all ``@preservable`` classes. Defaults to the
|
|
|
|
@ -79,7 +79,7 @@ def preserve(target_obj):
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
target_obj: The object to be preserved. This object and all its nested
|
|
|
|
target_obj: The object to be preserved. This object and all its nested
|
|
|
|
contents must either be primitive types or objects of a
|
|
|
|
contents must either be primitive types or objects of a
|
|
|
|
``@preservable`` class.
|
|
|
|
``@preservable`` class.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
@ -121,7 +121,7 @@ def restore(obj_jam):
|
|
|
|
``@preservable`` classes according to their ``restore_method``.
|
|
|
|
``@preservable`` classes according to their ``restore_method``.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
obj_jam: The data structure to restore, usually the result of a
|
|
|
|
obj_jam: The data structure to restore, usually the result of a
|
|
|
|
``preserve()`` call.
|
|
|
|
``preserve()`` call.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if isinstance(obj_jam, (str, int, float, bool, type(None))):
|
|
|
|
if isinstance(obj_jam, (str, int, float, bool, type(None))):
|
|
|
|
|