Skip to content

Deserialised¤

Deserialised dataclass ¤

Deserialised(value: Any, comment: str = '')

Represents the opposite of the serialised element in an equipment register.

Parameters:

Name Type Description Default
value Any

The value of the deserialised object.

required
comment str

A comment to associate with the (de)serialised object.

''

comment class-attribute instance-attribute ¤

comment: str = ''

A comment associated with the (de)serialised object.

value instance-attribute ¤

value: Any

The value of the deserialised object. For example, an Archive object from GTC.

from_xml classmethod ¤

from_xml(element: Element[str]) -> Deserialised

Convert a serialised XML element into a Deserialised instance.

Parameters:

Name Type Description Default
element Element[str]

A serialised XML element from an equipment register.

required

Returns:

Type Description
Deserialised

The Deserialised instance.

Source code in src/msl/equipment/schema.py
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
@classmethod
def from_xml(cls, element: Element[str]) -> Deserialised:
    """Convert a [serialised][type_serialised] XML element into a [Deserialised][msl.equipment.schema.Deserialised] instance.

    Args:
        element: A [serialised][type_serialised] XML element from an equipment register.

    Returns:
        The [Deserialised][msl.equipment.schema.Deserialised] instance.
    """  # noqa: E501
    e = element[0]
    comment = element.attrib.get("comment", "")

    # GTC is not required for msl-equipment, so we import it here
    if e.tag.endswith("gtcArchive"):
        from GTC.xml_format import (  # type: ignore[import-untyped]  # pyright: ignore[reportMissingTypeStubs]  # noqa: PLC0415
            xml_to_archive,  # pyright: ignore[reportUnknownVariableType]
        )

        return cls(value=xml_to_archive(e), comment=comment)

    if e.tag.endswith("gtcArchiveJSON"):
        from GTC import (  # type: ignore[import-untyped]  # pyright: ignore[reportMissingTypeStubs]  # noqa: PLC0415
            pr,  # pyright: ignore[reportUnknownVariableType]
        )

        return cls(value=pr.loads_json(e.text), comment=comment)  # pyright: ignore[reportUnknownMemberType]

    # Use the Element object rather than raising an exception that the deserializer has not been implemented yet
    return cls(value=e, comment=comment)

to_xml ¤

to_xml() -> Element[str]

Convert the Deserialised class into a serialised XML element.

Returns:

Type Description
Element[str]

The serialised XML element.

Source code in src/msl/equipment/schema.py
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
def to_xml(self) -> Element[str]:
    """Convert the [Deserialised][msl.equipment.schema.Deserialised] class into a [serialised][type_serialised] XML element.

    Returns:
        The [serialised][type_serialised] XML element.
    """  # noqa: E501
    attrib = {"comment": self.comment} if self.comment else {}
    e = Element("serialised", attrib=attrib)

    if isinstance(self.value, Element):
        e.append(self.value)  # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType]
        return e

    # Currently, only a GTC Archive is supported so we don't need to check how to serialise it
    # GTC is not required for msl-equipment, so we import it here
    from GTC.persistence import (  # type: ignore[import-untyped]  # pyright: ignore[reportMissingTypeStubs]  # noqa: PLC0415
        Archive,  # pyright: ignore[reportUnknownVariableType]
    )
    from GTC.xml_format import (  # pyright: ignore[reportMissingTypeStubs]  # noqa: PLC0415
        archive_to_xml,  # pyright: ignore[reportUnknownVariableType]
    )

    e.append(archive_to_xml(Archive.copy(self.value)))  # pyright: ignore[reportUnknownArgumentType, reportUnknownMemberType]
    return e