robokudo.utils.serialization

@author: Max Gandyra

Based on: “https://github.com/jsonpickle/jsonpickle

Can encode/decode any object as JSON-object and also store and load them from files/strings.

Attributes

Classes

_PlaceholderObject

HandlerRegistry

Flatten

Unflatten

IteratorHandler

Helper class that provides a standard way to create an ABC using

DictSubClassHandler

Helper class that provides a standard way to create an ABC using

ListSubClassHandler

Helper class that provides a standard way to create an ABC using

NumpyHandler

Helper class that provides a standard way to create an ABC using

Open3DPointCloudHandler

Helper class that provides a standard way to create an ABC using

Functions

get_json_backend(→ types.ModuleType)

is_builtin_function(→ bool)

is_builtin_method(→ bool)

is_bool(→ bool)

is_bytes(→ bool)

is_dictionary(→ bool)

is_enum(→ bool)

is_function(→ bool)

is_lambda_function(→ bool)

is_list(→ bool)

is_method(→ bool)

is_module(→ bool)

is_number(→ bool)

is_none(→ bool)

is_set(→ bool)

is_string(→ bool)

is_tuple(→ bool)

is_type(→ bool)

is_generic_function(→ bool)

is_object(→ bool)

is_module_function(→ bool)

is_primitive(→ bool)

attr_in_dict(obj, attr[, default])

attr_in_slots(obj, attr[, default])

has_attr_with_class_filter(→ bool)

combine_module_class_name(→ str)

split_module_class_name(→ typing_extensions.List[str])

class_to_module_class_name(→ str)

Returns the combination of the module and fully qualified name of the class.

locate_and_load_module(→ type)

module_class_name_to_class(→ type)

Returns the class described via the combined module and fully qualified class name.

make_object_reference(→ typing_extensions.Tuple[bool, int])

swap_object_reference(→ None)

_object_set_attr_with_placeholder(→ None)

_object_set_value_with_placeholder(→ None)

make_new_placeholder_reference(...)

try_add_value_placeholder_swap(→ None)

set_and_swap_placeholder_with_object(→ None)

flatten(→ typing_extensions.Any)

encode(→ str)

unflatten(→ typing_extensions.Any)

decode(→ typing_extensions.Any)

deepcopy(→ typing_extensions.Any)

Module Contents

robokudo.utils.serialization.type_swap_obj
robokudo.utils.serialization.type_set_func
robokudo.utils.serialization.type_placeholders
robokudo.utils.serialization.BYTES: str = '<bytes>'
robokudo.utils.serialization.ID: str = '<id>'
robokudo.utils.serialization.JSON_KEY: str = '<json_key>:'
robokudo.utils.serialization.MODULE: str = '<module>'
robokudo.utils.serialization.MODULE_FUNCTION: str = '<module_function>'
robokudo.utils.serialization.NEWARGS: str = '<newargs>'
robokudo.utils.serialization.NEWARGS_EX: str = '<newargs_ex>'
robokudo.utils.serialization.OBJECT: str = '<object>'
robokudo.utils.serialization.REDUCE: str = '<reduce>'
robokudo.utils.serialization.SET: str = '<set>'
robokudo.utils.serialization.STATE: str = '<state>'
robokudo.utils.serialization.TUPLE: str = '<tuple>'
robokudo.utils.serialization.TYPE: str = '<type>'
robokudo.utils.serialization.FlattenKeys: typing_extensions.Set[str]
robokudo.utils.serialization.JSON_BACKEND_LIST: typing_extensions.List[str] = ['ujson', 'json']
robokudo.utils.serialization.get_json_backend() types.ModuleType
robokudo.utils.serialization.is_builtin_function(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_builtin_method(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_bool(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_bytes(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_dictionary(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_enum(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_function(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_lambda_function(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_list(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_method(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_module(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_number(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_none(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_set(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_string(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_tuple(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_type(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_generic_function(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_object(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_module_function(obj: typing_extensions.Any) bool
robokudo.utils.serialization.is_primitive(obj: typing_extensions.Any) bool
robokudo.utils.serialization.attr_in_dict(obj: object, attr: typing_extensions.Any, default: typing_extensions.Any = None)
robokudo.utils.serialization.attr_in_slots(obj: object, attr: typing_extensions.Any, default: typing_extensions.Any = None)
robokudo.utils.serialization.has_attr_with_class_filter(obj: object, attr: str, class_only: bool = False, exclude_list: typing_extensions.List[type] = None) bool
robokudo.utils.serialization.combine_module_class_name(module_name: str, class_name: str) str
robokudo.utils.serialization.split_module_class_name(module_class_name: str) typing_extensions.List[str]
robokudo.utils.serialization.class_to_module_class_name(cls: type, replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None) str

Returns the combination of the module and fully qualified name of the class.

robokudo.utils.serialization.locate_and_load_module(module_class_name: str, seperator: typing_extensions.Optional[str] = '.') type
robokudo.utils.serialization.module_class_name_to_class(module_class_name: str, replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None, cache: typing_extensions.Optional[typing_extensions.Dict[str, type]] = None, seperator: typing_extensions.Optional[str] = '.', module_class_seperator: typing_extensions.Optional[str] = '><') type

Returns the class described via the combined module and fully qualified class name.

robokudo.utils.serialization.make_object_reference(obj: typing_extensions.Any, obj_to_id: typing_extensions.Dict[typing_extensions.Any, int], id_to_obj: typing_extensions.List[typing_extensions.Any]) typing_extensions.Tuple[bool, int]
robokudo.utils.serialization.swap_object_reference(old_obj: typing_extensions.Any, new_obj: typing_extensions.Any, obj_to_id: typing_extensions.Dict[typing_extensions.Any, int], id_to_obj: typing_extensions.List[typing_extensions.Any]) None
class robokudo.utils.serialization._PlaceholderObject

Bases: object

obj: typing_extensions.Any = None
robokudo.utils.serialization._object_set_attr_with_placeholder(obj: object, attr: typing_extensions.Any, placeholder: _PlaceholderObject) None
robokudo.utils.serialization._object_set_value_with_placeholder(obj: typing_extensions.Union[typing_extensions.MutableSequence, typing_extensions.MutableMapping], index: typing_extensions.Any, placeholder: _PlaceholderObject) None
robokudo.utils.serialization.make_new_placeholder_reference(obj_to_id: typing_extensions.Dict[typing_extensions.Any, int], id_to_obj: typing_extensions.List[typing_extensions.Any]) typing_extensions.Tuple[_PlaceholderObject, bool, int]
robokudo.utils.serialization.try_add_value_placeholder_swap(obj: type_swap_obj, attr: typing_extensions.Any, value: typing_extensions.Any, set_func: type_set_func, placeholders: type_placeholders) None
robokudo.utils.serialization.set_and_swap_placeholder_with_object(placeholder: _PlaceholderObject, obj: typing_extensions.Any, obj_to_id: typing_extensions.Dict[typing_extensions.Any, int], id_to_obj: typing_extensions.List[typing_extensions.Any], placeholders: type_placeholders) None
class robokudo.utils.serialization.HandlerRegistry

Bases: object

class HandlerBase(context)

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

context: typing_extensions.Union[Flatten, Unflatten]
classmethod can_handle(obj_cls: type) bool
abstract flatten(obj: object, data: typing_extensions.Dict) typing_extensions.Dict
abstract unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional[object]) object
_primary_handlers: typing_extensions.Dict[type, HandlerRegistry]
_secondary_handlers: typing_extensions.Dict[type, HandlerRegistry]
_primary_base_handlers: typing_extensions.Dict[type, HandlerRegistry]
_secondary_base_handlers: typing_extensions.Dict[type, HandlerRegistry]
_get_handler_dicts(primary_handler: bool = True) typing_extensions.Tuple[typing_extensions.Dict[type, HandlerBase], typing_extensions.Dict[type, HandlerBase]]
get(cls_or_name: typing_extensions.Union[str, type], primary_handler: bool = True, default: typing_extensions.Optional[HandlerBase] = None) typing_extensions.Optional[HandlerBase]
register(cls_or_name: typing_extensions.Union[str, type], handler: typing_extensions.Optional[HandlerBase] = None, primary_handler: bool = True, as_normal: bool = True, as_base: bool = False) typing_extensions.Optional[typing_extensions.Callable[[HandlerBase], HandlerBase]]
unregister(cls_or_name: typing_extensions.Union[str, type], primary_handler: bool = True)
robokudo.utils.serialization.handler_registry: HandlerRegistry
class robokudo.utils.serialization.Flatten(max_depth: typing_extensions.Optional[int] = None, json_backend: typing_extensions.Optional[types.ModuleType] = None, bytes_to_base64: bool = True, use_bytes_references: bool = True, use_module_references: bool = True, use_module_function_references: bool = True, use_set_references: bool = True, use_string_references: bool = True, use_tuple_references: bool = True, use_type_references: bool = True, replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None)

Bases: object

_depth: int = 0
max_depth: typing_extensions.Optional[int] = None
json_backend: typing_extensions.Optional[types.ModuleType] = None
bytes_to_base64: bool = True
use_bytes_references: bool = True
use_module_references: bool = True
use_module_function_references: bool = True
use_set_references: bool = True
use_string_references: bool = True
use_tuple_references: bool = True
use_type_references: bool = True
replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None
_obj_to_id: typing_extensions.Dict[typing_extensions.Any, int]
_id_to_obj: typing_extensions.List[typing_extensions.Any] = []
_id_stack: typing_extensions.List[int] = []
_reset()
_class_to_module_class_name(cls: typing_extensions.Type) str
_flatten_bytes(obj: bytes) typing_extensions.Dict
_flatten_dict_object(obj: typing_extensions.Dict, data: typing_extensions.Dict) typing_extensions.Dict
_flatten_dict(obj: typing_extensions.Dict) typing_extensions.Dict
_flatten_id(ref_id) typing_extensions.Dict
_flatten_list_object(obj: typing_extensions.Iterable) typing_extensions.List
_flatten_list(obj: typing_extensions.List) typing_extensions.List
_flatten_module(obj: types.ModuleType) typing_extensions.Dict
_flatten_module_function(obj: type) typing_extensions.Dict
_flatten_slots_obj(obj: object, data: typing_extensions.Dict) typing_extensions.Dict
_flatten_object(obj: object) typing_extensions.Dict
_flatten_primitive(obj: typing_extensions.Any) typing_extensions.Any
_flatten_set(obj: typing_extensions.Set) typing_extensions.Dict
_flatten_tuple(obj: typing_extensions.Tuple) typing_extensions.Dict
_flatten_type(obj: type) typing_extensions.Dict
_get_flattener(obj: typing_extensions.Any) typing_extensions.Tuple[typing_extensions.Callable, bool, bool]
_flatten(obj: typing_extensions.Any) typing_extensions.Any
flatten(obj: typing_extensions.Any, pre_reset: bool = True, post_reset: bool = True, post_restore: bool = False) typing_extensions.Any
robokudo.utils.serialization.flatten(obj: typing_extensions.Any, max_depth: typing_extensions.Optional[int] = None, json_backend: typing_extensions.Optional[types.ModuleType] = None, bytes_to_base64: bool = True, use_bytes_references: bool = True, use_module_references: bool = True, use_module_function_references: bool = True, use_set_references: bool = True, use_string_references: bool = True, use_tuple_references: bool = True, use_type_references: bool = True, replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None) typing_extensions.Any
robokudo.utils.serialization.encode(obj: typing_extensions.Any, max_depth: typing_extensions.Optional[int] = None, json_backend: typing_extensions.Optional[types.ModuleType] = None, bytes_to_base64: bool = True, use_bytes_references: bool = True, use_module_references: bool = True, use_module_function_references: bool = True, use_set_references: bool = True, use_string_references: bool = True, use_tuple_references: bool = True, use_type_references: bool = True, replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None, *args, **kwargs) str
class robokudo.utils.serialization.Unflatten(json_backend: typing_extensions.Optional[types.ModuleType] = None, bytes_to_base64: bool = True, use_bytes_references: bool = True, use_module_references: bool = True, use_module_function_references: bool = True, use_set_references: bool = True, use_string_references: bool = True, use_tuple_references: bool = True, use_type_references: bool = True, replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None, use_name_to_class_cache: bool = True)

Bases: object

json_backend: typing_extensions.Optional[types.ModuleType] = None
bytes_to_base64: bool = True
use_bytes_references: bool = True
use_module_references: bool = True
use_module_function_references: bool = True
use_set_references: bool = True
use_string_references: bool = True
use_tuple_references: bool = True
use_type_references: bool = True
replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None
_name_to_class: typing_extensions.Optional[typing_extensions.Dict[str, str]]
_obj_to_id: typing_extensions.Dict[typing_extensions.Any, int]
_id_to_obj: typing_extensions.List[typing_extensions.Any] = []
_placeholders: type_placeholders
_reset()
_module_class_name_to_class(module_class_name: str, is_module_only: bool = False) type
_make_object_reference(obj: typing_extensions.Any) typing_extensions.Tuple[bool, int]
_make_new_placeholder_reference() typing_extensions.Tuple[_PlaceholderObject, bool, int]
_set_and_swap_placeholder_with_object(placeholder: _PlaceholderObject, obj: typing_extensions.Any) None
_try_add_value_placeholder_swap(obj: type_swap_obj, attr: typing_extensions.Any, value: typing_extensions.Any, set_func: type_set_func) None
_unflatten_bytes(data: typing_extensions.Dict) bytes
_unflatten_dict_object(data: typing_extensions.Dict, obj: object, use_setattr: bool) object
_unflatten_dict(data: typing_extensions.Dict) typing_extensions.Dict
_unflatten_id(data: typing_extensions.Dict) typing_extensions.Any
_unflatten_list_object(data, obj)
_unflatten_list(data: typing_extensions.List) typing_extensions.List
_unflatten_module(data: typing_extensions.Dict) types.ModuleType
_unflatten_module_function(data: typing_extensions.Dict) type
_unflatten_object(data: typing_extensions.Dict) object
_unflatten_reduce(data: typing_extensions.Dict) object
_unflatten_set(data: typing_extensions.Dict) typing_extensions.Set
_unflatten_tuple(data: typing_extensions.Dict) typing_extensions.Tuple
_unflatten_type(data: typing_extensions.Dict) type
_unflatten(data: typing_extensions.Any) typing_extensions.Any
unflatten(data: typing_extensions.Any, pre_reset: bool = True, post_reset: bool = True, post_restore: bool = False) typing_extensions.Any
robokudo.utils.serialization.unflatten(data: typing_extensions.Any, json_backend: typing_extensions.Optional[types.ModuleType] = None, bytes_to_base64: bool = True, use_bytes_references: bool = True, use_module_references: bool = True, use_module_function_references: bool = True, use_set_references: bool = True, use_string_references: bool = True, use_tuple_references: bool = True, use_type_references: bool = True, replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None, use_name_to_class_cache: bool = True) typing_extensions.Any
robokudo.utils.serialization.decode(data: str, json_backend: typing_extensions.Optional[types.ModuleType] = None, bytes_to_base64: bool = True, use_bytes_references: bool = True, use_module_references: bool = True, use_module_function_references: bool = True, use_set_references: bool = True, use_string_references: bool = True, use_tuple_references: bool = True, use_type_references: bool = True, replacement_names: typing_extensions.Optional[typing_extensions.Dict[str, str]] = None, use_name_to_class_cache: bool = True, *args, **kwargs) typing_extensions.Any
robokudo.utils.serialization.deepcopy(obj: typing_extensions.Any, max_depth: typing_extensions.Optional[int] = None, json_backend: typing_extensions.Optional[types.ModuleType] = None, bytes_to_base64: bool = True, use_bytes_references: bool = True, use_module_references: bool = True, use_module_function_references: bool = True, use_set_references: bool = True, use_string_references: bool = True, use_tuple_references: bool = True, use_type_references: bool = True, use_name_to_class_cache: bool = True, *args, **kwargs) typing_extensions.Any
class robokudo.utils.serialization.IteratorHandler(context)

Bases: HandlerRegistry

Helper class that provides a standard way to create an ABC using inheritance.

class DummyIterator

Bases: object

max_num_iter: typing_extensions.Optional[int] = None
flatten(obj: typing_extensions.Iterator, data: typing_extensions.Dict) typing_extensions.Dict
unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional) collections.abc.Iterator
class robokudo.utils.serialization.DictSubClassHandler(context)

Bases: HandlerRegistry

Helper class that provides a standard way to create an ABC using inheritance.

flatten(obj: typing_extensions.Dict, data: typing_extensions.Dict) typing_extensions.Dict
unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional[object]) typing_extensions.Dict
class robokudo.utils.serialization.ListSubClassHandler(context)

Bases: HandlerRegistry

Helper class that provides a standard way to create an ABC using inheritance.

flatten(obj: typing_extensions.List, data: typing_extensions.Dict) typing_extensions.Dict
unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional[typing_extensions.List]) typing_extensions.List
class robokudo.utils.serialization.NumpyHandler(context)

Bases: HandlerRegistry

Helper class that provides a standard way to create an ABC using inheritance.

flatten(obj: typing_extensions.Union[numpy.ndarray, numpy.generic], data: typing_extensions.Dict) typing_extensions.Dict
unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional) typing_extensions.Union[numpy.ndarray, numpy.generic]
class robokudo.utils.serialization.Open3DPointCloudHandler(context)

Bases: HandlerRegistry

Helper class that provides a standard way to create an ABC using inheritance.

flatten(obj: open3d.geometry.PointCloud, data: typing_extensions.Dict) typing_extensions.Dict
unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional) open3d.geometry.PointCloud