sampo.schemas.serializable#
Overview#
Parent class for (de-)serialization different data structures. |
|
Parent class for serialization of classes, which can be converted to String representation or given from String |
|
Parent class for (de-)serialization different data structures. |
|
Parent class for serialization of classes, which can be automatically converted to dict with Serializable properties |
Classes#
- class sampo.schemas.serializable.Serializable#
-
Parent class for (de-)serialization different data structures.
- Parameters:
ABC – helper class to create custom abstract classes
S] (Generic[T,) – base class to make Serializable as universal class, using user’s types T, S
- abstract property serializer_extension: str#
- abstract _serialize() T#
Converts all the meaningful information from this instance to a generic representation.
- Returns:
A generic representation
- abstract classmethod _deserialize(representation: T) S#
Creates class instance from a representation. :param representation: Representation produced by _serialize method :return: New class instance
- abstract classmethod load(folder_path: str, file_name: str) S#
Factory method that produces a python object from the serialized version of it. :param folder_path: Path to the folder, where the serialized file is saved :param file_name: File name without extension (the file extension should match with the one returned by serializer_extension method) :return: The constructed python object
- dump(folder_path: str, file_name: str)#
Serializes the object and saves it to file. :param folder_path: Path to the folder where the serialized file should be saved :param file_name: Name of the file without extension (the appended extension could be explored via serializer_extension method) :return None
- classmethod get_full_file_name(folder_path: str, file_name: str)#
Combines path to folder, file name and extension to get full file name :param folder_path: Path to folder :param file_name: File name without extension :return: Full file path, name and extension
- class sampo.schemas.serializable.StrSerializable#
Bases:
Serializable[str,SS],abc.ABC,Generic[SS]Parent class for serialization of classes, which can be converted to String representation or given from String representation
- Parameters:
SS] (Serializable[str,) –
ABC – helper class to create custom abstract classes
Generic[SS] – base class to make StrSerializable as universal class,
using user’s types SS and it’s descendants
- serializer_extension: str = 'dat'#
- abstract _serialize() str#
Converts object to str representation :return: str representation of the object
- abstract classmethod _deserialize(str_representation: str) SS#
Creates class instance from a str representation :param str_representation: Representation produced by _serialize method :return: New class instance
- classmethod load(folder_path: str, file_name: str) SS#
Factory method that produces a python object from the serialized version of it :param folder_path: Path to the folder, where the serialized file is saved :param file_name: File name without extension (the file extension should match with the one returned by serializer_extension method) :return: The constructed python object
- dump(folder_path: str, file_name: str) None#
Serializes object and saves it to file :param folder_path: Path to the folder where the serialized file should be saved :param file_name: Name of the file without extension (the appended extension could be explored via serializer_extension method) :return None
- class sampo.schemas.serializable.JSONSerializable#
Bases:
Serializable[dict[str,Union[dict,Union[list,tuple],str,Union[int,float],bool,None]],JS],abc.ABC,Generic[JS]Parent class for (de-)serialization different data structures.
- Parameters:
ABC – helper class to create custom abstract classes
S] (Generic[T,) – base class to make Serializable as universal class, using user’s types T, S
- serializer_extension: str = 'json'#
Parent class for serialization of classes, which can convert object to JSON format (as serialization result) and get object from JSON format :param Serialize: structure of JSON input variable for descendants of the class :param ABC: helper class to create custom abstract classes :param Generic[JS]: base class to make JSONSerializable as universal class, using user’s types JS and it’s descendants
- abstract _serialize() T#
Converts all the meaningful information from this instance to a generic representation :return: A generic representation
- abstract classmethod _deserialize(representation: T) JS#
Creates class instance from a representation :param representation: Representation produced by _serialize method :return: New class instance
- classmethod load(folder_path: str, file_name: str) JS#
Factory method that produces a python object from the serialized version of it :param folder_path: Path to the folder, where the serialized file is saved :param file_name: File name without extension (the file extension should match with the one returned by serializer_extension method) :return: The constructed python object
- dump(folder_path: str, file_name: str) None#
Serializes object and saves it to file :param folder_path: Path to the folder where the serialized file should be saved :param file_name: Name of the file without extension (the appended extension could be explored via serializer_extension method) :return None
- class sampo.schemas.serializable.AutoJSONSerializable#
Bases:
JSONSerializable[AJS],abc.ABCParent class for serialization of classes, which can be automatically converted to dict with Serializable properties and custom (de-)serializers, marked with custom_serializer and custom_deserializer decorators. :param JSONSerializable[AJS]: :param ABC: helper class to create custom abstract classes
- class property _default_serializers#
- Parameters:
cls – current class (predecessors of parent class AutoJSONSerializable)
- Returns:
dict: dictionary of serialization methods
- class property _default_deserializers#
- Parameters:
cls – current class (predecessors of parent class AutoJSONSerializable)
- Returns:
dictionary of deserialization methods
- class property ignored_fields#
Return list of fields, which not be included to JSON representation (needed for client interface and Draw Schedule system) :return: list of fields
- serializer_extension: str = 'json'#
- _default_serializers_deserializers#
- _serialize() dict[str, dict | list | tuple | str | int | float | bool | None]#
Converts all the meaningful information from this instance to dict representation with values of eligible types only to be converted to JSON data structures:
list or tuple (to array)
str (to string)
int or float (to number)
True or False (to true or false)
None (to null)
dict with values of the listed types (to object)
- Returns:
dict representation of the object
- classmethod _deserialize(dict_representation: dict) AJS#
Creates class instance from a dict representation
- Parameters:
dict_representation – Representation produced by _serialize method
- Returns:
New class instance
Attributes#
- sampo.schemas.serializable.T#
- sampo.schemas.serializable.S#
- sampo.schemas.serializable.SS#
- sampo.schemas.serializable.JS#
- sampo.schemas.serializable.AJS#
- sampo.schemas.serializable.TYPE_HINTS = '_serializable_type_hints'#