pyspinw.serialisation#
Serialisation mixin
See notes document 004 for details.
Functions
|
Deserialise a Fraction |
Deserialise the pre-json representation of a fraction or builtin |
|
|
Decorator for functions that take json dicts with given keys as the |
|
Header for files |
|
Load a pySpinW object from a file |
|
Deserialisation method numpy data in SPW json |
|
Serialisation for numpy data in the SPW json |
|
Deserialise an RGB color |
|
Serialise an RGB color |
|
Save a pySpinW object |
|
Serialise a Fraction |
Serialise a union type of fraction or builtin number to pre-json |
|
|
Deserialise a 3D vector |
|
Serialise a 3D vector |
Classes
|
Group of objects for deserialisation |
|
Context object (see notes document 004) for deserialisation |
|
Return type for deserialisation requests from deserialisation context |
Classes that are serialisable to SPW files should use implement this interface |
|
Context object (see notes document 004) for serialisation |
|
A group of objects held for serialisation |
Exceptions
Exceptions thrown by the [de]serialisation process |
- class pyspinw.serialisation.SPWDeserialisationContexGroup(name: str, context_data: dict)#
Bases:
objectGroup of objects for deserialisation
- put(id, instance)#
Add a resolved instance to the context
- request_by_id(id) SPWDeserialisationRequestResponse#
Ask for an object from this context-group using its serialisation id
It will return an object that contains either the deserialised object, or json that needs to be deserialised (along with appropriate metadata)
- request_by_json(json) SPWDeserialisationRequestResponse#
Ask for an object from this context-group using a json object
It will return an object that contains either the deserialised object, or json that needs to be deserialised (along with appropriate metadata)
- class pyspinw.serialisation.SPWDeserialisationContext(context_data: dict)#
Bases:
objectContext object (see notes document 004) for deserialisation
- class pyspinw.serialisation.SPWDeserialisationRequestResponse(value, id: int, deserialised: bool)#
Bases:
objectReturn type for deserialisation requests from deserialisation context
Contains a value which can be a deserialised object or json. Has a flag for is whether or not it is the deserialised object
- class pyspinw.serialisation.SPWSerialisable#
Bases:
objectClasses that are serialisable to SPW files should use implement this interface
- classmethod deserialise(json_string: str)#
Deserialise an object of this type from a JSON string
- save(filename: str | Path, description: str = '', add_extension: bool = True)#
Save this object to a file
- serialisation_name = '<not-implemented>'#
- serialise(description: str = '') str#
Serialise an object of this type to a JSON string
- class pyspinw.serialisation.SPWSerialisationContext#
Bases:
objectContext object (see notes document 004) for serialisation
- serialise()#
Serialise the data in this context to JSON
- class pyspinw.serialisation.SPWSerialisationContextGroup(name: str)#
Bases:
objectA group of objects held for serialisation
- has(key)#
Does this serialisation context have the object specified by ‘key’
- put(key, serialisation_data)#
Put a new serialised object into this context
- reference(key)#
Return a reference to an object in this group
- serialise()#
Get the serialisation data for this group
- exception pyspinw.serialisation.SPWSerialisationError#
Bases:
ExceptionExceptions thrown by the [de]serialisation process
- pyspinw.serialisation.deserialise_fraction(json: dict) Fraction#
Deserialise a Fraction
- pyspinw.serialisation.deserialise_fraction_or_builtin(json: dict) int | float | Fraction#
Deserialise the pre-json representation of a fraction or builtin
- pyspinw.serialisation.expects_keys(keystring: str, parameter_index=0)#
Decorator for functions that take json dicts with given keys as the
parameter_indexplace parameter
- pyspinw.serialisation.header(description: str)#
Header for files
- pyspinw.serialisation.load(filename: str | Path)#
Load a pySpinW object from a file
- pyspinw.serialisation.numpy_deserialise(json: dict) ndarray#
Deserialisation method numpy data in SPW json
- pyspinw.serialisation.numpy_serialise(data: ndarray) dict#
Serialisation for numpy data in the SPW json
- pyspinw.serialisation.rgb_deserialise(json)#
Deserialise an RGB color
- pyspinw.serialisation.rgb_serialise(rgb: tuple[float, float, float])#
Serialise an RGB color
- pyspinw.serialisation.save(object: SPWSerialisable, filename: str | Path, description: str = '', add_extension: bool = True)#
Save a pySpinW object
- pyspinw.serialisation.serialise_fraction(fraction: Fraction) dict#
Serialise a Fraction
- pyspinw.serialisation.serialise_fraction_or_builtin(value: int | float | Fraction)#
Serialise a union type of fraction or builtin number to pre-json
- pyspinw.serialisation.vec3_deserialise(json)#
Deserialise a 3D vector
- pyspinw.serialisation.vec3_serialise(x, y, z)#
Serialise a 3D vector