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.
- param json_backend:
-
JSON module to use (e.g. json, ujson)
- type json_backend:
-
ModuleType, optional
- param bytes_to_base64:
-
Whether to encode bytes as base64
- type bytes_to_base64:
-
bool, optional
- param use_bytes_references:
-
Whether to use references for bytes objects
- type use_bytes_references:
-
bool, optional
- param use_module_references:
-
Whether to use references for modules
- type use_module_references:
-
bool, optional
- param use_module_function_references:
-
Whether to use references for module functions
- type use_module_function_references:
-
bool, optional
- param use_set_references:
-
Whether to use references for sets
- type use_set_references:
-
bool, optional
- param use_string_references:
-
Whether to use references for strings
- type use_string_references:
-
bool, optional
- param use_tuple_references:
-
Whether to use references for tuples
- type use_tuple_references:
-
bool, optional
- param use_type_references:
-
Whether to use references for types
- type use_type_references:
-
bool, optional
- param replacement_names:
-
Mapping of old to new module/class names
- type replacement_names:
-
dict, optional
Dependencies¶
json/orjson/rapidjson for JSON serialization
numpy for array serialization
open3d for point cloud serialization
base64 for binary data encoding
See Also¶
robokudo.utils.file_loader: File path resolutionrobokudo.utils.transform: Transform serialization
Attributes¶
Classes¶
Registry for custom object serialization handlers. |
|
Convert Python objects to JSON-serializable format. |
|
Convert JSON-serializable format back to Python objects. |
|
Handler for serializing iterator objects. |
|
Handler for serializing dictionary subclasses. |
|
Handler for serializing list subclasses. |
|
Handler for serializing NumPy arrays and scalars. |
|
Handler for serializing Open3D point clouds. |
Functions¶
|
Get the first available JSON serialization backend. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns the combination of the module and fully qualified name of the class. |
|
Load a module from its fully qualified name. |
|
Returns the class described via the combined module and fully qualified class name. |
|
|
|
|
|
|
|
|
|
Encode a Python object to a JSON string. |
|
|
|
Decode a JSON string back to a Python object. |
|
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¶
-
Get the first available JSON serialization backend.
Tries to load backends in order from JSON_BACKEND_LIST until one succeeds.
- Returns:
-
Loaded JSON backend module
- Return type:
-
types.ModuleType
- Raises:
-
ImportError – If no backend could be loaded
- 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.
- Parameters:
-
cls (type) – The class to get the name for
replacement_names (dict, optional) – Dictionary mapping old module.class names to new ones, by default None
- Returns:
-
Combined module and class name in the format “module><class”
- Return type:
-
str
This function handles special cases like:
Classes without modules
Classes with __self__ attributes
Name replacements for refactoring
- robokudo.utils.serialization.locate_and_load_module(module_class_name: str, seperator: typing_extensions.Optional[str] = '.') type¶
-
Load a module from its fully qualified name.
- Parameters:
-
module_class_name (str) – Fully qualified module/class name
separator – Separator between module parts, by default “.”
- Returns:
-
Loaded module class
- Return type:
-
type
- Raises:
-
ImportError – If module cannot be loaded or does not exist
- 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.
- Parameters:
-
module_class_name (str) – Fully qualified module/class name
replacement_names (dict, optional) – Mapping of old to new module names
cache (dict, optional) – Cache of previously loaded classes
seperator (str, optional) – Separator between module parts, by default “.”
module_class_seperator (str, optional) – Separator between module and class, by default “><”
- Returns:
-
Loaded class
- Return type:
-
type
- Raises:
-
ImportError – If class cannot be loaded
ValueError – If module/class path format is invalid
- 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:
objectRegistry for custom object serialization handlers.
This class manages handlers for serializing custom objects to JSON format. It supports:
Registration of handlers for specific types
Base class handlers for subclass serialization
Primary and secondary handler chains
Normal and base handler modes
Attributes¶
- _primary_handlersdict
-
Mapping of types to primary handlers
- _secondary_handlersdict
-
Mapping of types to secondary handlers
- _primary_base_handlersdict
-
Mapping of base types to primary handlers
- _secondary_base_handlersdict
-
Mapping of base types to secondary handlers
- class HandlerBase(context)¶
-
Bases:
abc.ABCAbstract base class for custom serialization handlers.
- Parameters:
-
context (Union["Flatten", "Unflatten"]) – The Flatten or Unflatten context object
- classmethod can_handle(obj_cls: type) bool¶
-
Check if this handler can handle the given class.
- Parameters:
-
obj_cls (type) – The class to check
- Returns:
-
True if can handle, False otherwise
- Return type:
-
bool
- abstract flatten(obj: object, data: typing_extensions.Dict) typing_extensions.Dict¶
-
Flatten an object to a dictionary format.
- Parameters:
-
obj (object) – Object to flatten
data (dict) – Dictionary to store flattened data
- Returns:
-
Dictionary containing flattened object
- Return type:
-
dict
- Raises:
-
NotImplementedError – Must be implemented by subclass
- abstract unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional[object]) object¶
-
Unflatten a dictionary back into an object.
- Parameters:
-
data (dict) – Dictionary containing flattened data
obj (object, optional) – Optional existing object to unflatten into
- Returns:
-
Reconstructed object
- Return type:
-
object
- Raises:
-
NotImplementedError – Must be implemented by subclass
- _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:
objectConvert Python objects to JSON-serializable format.
This class handles flattening complex Python objects into simple types that can be serialized to JSON. It supports:
Circular references
Custom object handlers
Maximum recursion depth
Various reference types (bytes, modules, etc.)
Parameters¶
- max_depthint, optional
-
Maximum recursion depth, by default None (unlimited)
- json_backendModuleType, optional
-
JSON module to use (e.g. json, ujson), by default None
- bytes_to_base64bool, optional
-
Whether to encode bytes as base64, by default True
- use_bytes_referencesbool, optional
-
Whether to use references for bytes objects, by default True
- use_module_referencesbool, optional
-
Whether to use references for modules, by default True
- use_module_function_referencesbool, optional
-
Whether to use references for module functions, by default True
- use_set_referencesbool, optional
-
Whether to use references for sets, by default True
- use_string_referencesbool, optional
-
Whether to use references for strings, by default True
- use_tuple_referencesbool, optional
-
Whether to use references for tuples, by default True
- use_type_referencesbool, optional
-
Whether to use references for types, by default True
- replacement_namesdict, optional
-
Mapping of old to new module/class names, by default None
- _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¶
-
Encode a Python object to a JSON string.
This is a convenience function that combines flattening an object and converting it to a JSON string.
- Parameters:
-
obj (Any) – The Python object to encode
max_depth (int, optional) – Maximum recursion depth
json_backend (ModuleType, optional) – JSON module to use
bytes_to_base64 (bool, optional) – Whether to encode bytes as base64
use_bytes_references (bool, optional) – Whether to use references for bytes
use_module_references (bool, optional) – Whether to use references for modules
use_module_function_references (bool, optional) – Whether to use references for module functions
use_set_references (bool, optional) – Whether to use references for sets
use_string_references (bool, optional) – Whether to use references for strings
use_tuple_references (bool, optional) – Whether to use references for tuples
use_type_references (bool, optional) – Whether to use references for types
replacement_names (dict, optional) – Mapping of old to new module/class names
-
*args –
Additional arguments passed to json.dumps
-
**kwargs –
Additional keyword arguments passed to json.dumps
- Returns:
-
JSON string representation of the object
- Return type:
-
str
See Also¶
- 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:
objectConvert JSON-serializable format back to Python objects.
This class handles unflattening simple JSON-serializable types back into complex Python objects.
- Parameters:
-
json_backend (ModuleType, optional) – JSON module to use (e.g. json, ujson)
bytes_to_base64 (bool, optional) – Whether bytes are base64 encoded
use_bytes_references (bool, optional) – Whether to handle bytes references
use_module_references (bool, optional) – Whether to handle module references
use_module_function_references (bool, optional) – Whether to handle module function references
use_set_references (bool, optional) – Whether to handle set references
use_string_references (bool, optional) – Whether to handle string references
use_tuple_references (bool, optional) – Whether to handle tuple references
use_type_references (bool, optional) – Whether to handle type references
replacement_names (dict, optional) – Mapping of old to new module/class names
use_name_to_class_cache (bool, optional) – Whether to cache loaded classes
- 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¶
-
Decode a JSON string back to a Python object.
This is a convenience function that combines parsing a JSON string and unflattening it back into a Python object.
- Parameters:
-
data (str) – The JSON string to decode
json_backend (ModuleType, optional) – JSON module to use
bytes_to_base64 (bool, optional) – Whether bytes are base64 encoded
use_bytes_references (bool, optional) – Whether to handle bytes references
use_module_references (bool, optional) – Whether to handle module references
use_module_function_references (bool, optional) – Whether to handle module function references
use_set_references (bool, optional) – Whether to handle set references
use_string_references (bool, optional) – Whether to handle string references
use_tuple_references (bool, optional) – Whether to handle tuple references
use_type_references (bool, optional) – Whether to handle type references
replacement_names (dict, optional) – Mapping of old to new module/class names
use_name_to_class_cache (bool, optional) – Whether to cache loaded classes
-
*args –
Additional arguments passed to json.loads
-
**kwargs –
Additional keyword arguments passed to json.loads
- Returns:
-
Reconstructed Python object
- Return type:
-
Any
See Also¶
encode(): Convert Python object to JSON stringunflatten(): Convert JSON-serializable format back to object
- 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:
HandlerRegistryHandler for serializing iterator objects.
This handler can serialize simple iterator objects by converting them to lists. Only handles a limited number of elements defined by max_num_iter.
- Variables:
-
max_num_iter – Maximum number of elements to serialize from iterator
- class DummyIterator¶
-
Bases:
objectDummy class used as placeholder for iterator serialization.
- max_num_iter: typing_extensions.Optional[int] = None¶
- flatten(obj: typing_extensions.Iterator, data: typing_extensions.Dict) typing_extensions.Dict¶
-
Flatten an iterator to a dictionary format.
- Parameters:
-
obj (Iterator) – Iterator to flatten
data (dict) – Dictionary to store flattened data
- Returns:
-
Dictionary containing flattened iterator data
- Return type:
-
dict
- unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional) collections.abc.Iterator¶
-
Unflatten a dictionary back into an iterator.
- Parameters:
-
data (dict) – Dictionary containing flattened data
obj (object, optional) – Ignored for iterators
- Returns:
-
Reconstructed iterator
- Return type:
-
Iterator
- class robokudo.utils.serialization.DictSubClassHandler(context)¶
-
Bases:
HandlerRegistryHandler for serializing dictionary subclasses.
This handler can serialize dictionary subclasses that have additional attributes beyond the standard dictionary content.
- flatten(obj: typing_extensions.Dict, data: typing_extensions.Dict) typing_extensions.Dict¶
-
Flatten a dictionary subclass to a dictionary format.
- Parameters:
-
obj (dict) – Dictionary subclass to flatten
data (dict) – Dictionary to store flattened data
- Returns:
-
Dictionary containing flattened object data
- Return type:
-
dict
- unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional[object]) typing_extensions.Dict¶
-
Unflatten a dictionary back into a dictionary subclass.
- Parameters:
-
data (dict) – Dictionary containing flattened data
obj (object, optional) – Dictionary subclass instance to unflatten into
- Returns:
-
Reconstructed dictionary subclass
- Return type:
-
dict
- class robokudo.utils.serialization.ListSubClassHandler(context)¶
-
Bases:
HandlerRegistryHandler for serializing list subclasses.
This handler can serialize list subclasses that have additional attributes beyond the standard list content.
- flatten(obj: typing_extensions.List, data: typing_extensions.Dict) typing_extensions.Dict¶
-
Flatten a list subclass to a dictionary format.
- Parameters:
-
obj (list) – List subclass to flatten
data (dict) – Dictionary to store flattened data
- Returns:
-
Dictionary containing flattened object data
- Return type:
-
dict
- unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional[typing_extensions.List]) typing_extensions.List¶
-
Unflatten a dictionary back into a list subclass.
- Parameters:
-
data (dict) – Dictionary containing flattened data
obj (list, optional) – List subclass instance to unflatten into
- Returns:
-
Reconstructed list subclass
- Return type:
-
list
- class robokudo.utils.serialization.NumpyHandler(context)¶
-
Bases:
HandlerRegistryHandler for serializing NumPy arrays and scalars.
This handler serializes NumPy arrays and scalar values using NumPy’s save/load functionality.
- flatten(obj: typing_extensions.Union[numpy.ndarray, numpy.generic], data: typing_extensions.Dict) typing_extensions.Dict¶
-
Flatten a NumPy array/scalar to a dictionary format.
- Parameters:
-
obj (Union[np.ndarray, np.generic]) – NumPy array or scalar to flatten
data (dict) – Dictionary to store flattened data
- Returns:
-
Dictionary containing flattened array data
- Return type:
-
dict
- unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional) typing_extensions.Union[numpy.ndarray, numpy.generic]¶
-
Unflatten a dictionary back into a NumPy array/scalar.
- Parameters:
-
data (dict) – Dictionary containing flattened data
obj (object, optional) – Ignored for NumPy arrays
- Returns:
-
Reconstructed NumPy array or scalar
- Return type:
-
Union[np.ndarray, np.generic]
- Raises:
-
ValueError – If data key is missing or None
- class robokudo.utils.serialization.Open3DPointCloudHandler(context)¶
-
Bases:
HandlerRegistryHandler for serializing Open3D point clouds.
This handler serializes Open3D point cloud objects using Open3D’s read/write functionality with temporary files.
- flatten(obj: open3d.geometry.PointCloud, data: typing_extensions.Dict) typing_extensions.Dict¶
-
Flatten an Open3D point cloud to a dictionary format.
- Parameters:
-
obj (o3d.geometry.PointCloud) – Point cloud to flatten
data (dict) – Dictionary to store flattened data
- Returns:
-
Dictionary containing flattened point cloud data
- Return type:
-
dict
- unflatten(data: typing_extensions.Dict, obj: typing_extensions.Optional) open3d.geometry.PointCloud¶
-
Unflatten a dictionary back into an Open3D point cloud.
- Parameters:
-
data (dict) – Dictionary containing flattened data
obj (object, optional) – Ignored for point clouds
- Returns:
-
Reconstructed point cloud
- Return type:
-
o3d.geometry.PointCloud
- Raises:
-
ValueError – If data key is missing or None