betty.serde.format module

Provide serialization formats.

class betty.serde.format.Format[source]

Bases: ABC

Defines a (de)serialization format.

abstract dump(dump: bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | type[betty.typing.Void]) str[source]

Serialize data.

Parameters:

dump (typing.Union[bool, int, float, str, None, typing.Sequence[typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]], typing.Mapping[str, typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]], type[betty.typing.Void]])

Return type:

str

abstract property extensions: set[str]

The file extensions this format can (de)serialize.

Extensions MUST NOT include a leading dot.

abstract property label: Localizable

The format’s human-readable label.

abstract load(dump: str) bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump][source]

Deserialize data.

Parameters:

dump (str)

Return type:

typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]

exception betty.serde.format.FormatError[source]

Bases: AssertionFailed

Raised when data that is being deserialized is provided in an unknown (undeserializable) format.

Parameters:

message (betty.locale.localizable.Localizable)

final class betty.serde.format.FormatRepository[source]

Bases: object

Exposes the available (de)serialization formats.

__init__()[source]
property extensions: tuple[str, ...]

All file extensions supported by the formats in this repository.

format_for(extension: str) betty.serde.format.Format[source]

Get the (de)serialization format for the given file extension.

The extension MUST NOT include a leading dot.

Parameters:

extension (str)

Return type:

betty.serde.format.Format

property formats: tuple[Format, ...]

All formats in this repository.

final class betty.serde.format.FormatStr[source]

Bases: Localizable

Localize and format a sequence of (de)serialization formats.

Parameters:

serde_formats (typing.Sequence[betty.serde.format.Format])

__init__(serde_formats: Sequence[betty.serde.format.Format])[source]
Parameters:

serde_formats (typing.Sequence[betty.serde.format.Format])

localize(localizer: betty.locale.Localizer) str[source]

Localize self to a human-readable string.

Parameters:

localizer (betty.locale.Localizer)

Return type:

str

final class betty.serde.format.Json[source]

Bases: Format

Defines the JSON (de)serialization format.

dump(dump: bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | type[betty.typing.Void]) str[source]

Serialize data.

Parameters:

dump (typing.Union[bool, int, float, str, None, typing.Sequence[typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]], typing.Mapping[str, typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]], type[betty.typing.Void]])

Return type:

str

property extensions: set[str]

The file extensions this format can (de)serialize.

Extensions MUST NOT include a leading dot.

property label: Localizable

The format’s human-readable label.

load(dump: str) bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump][source]

Deserialize data.

Parameters:

dump (str)

Return type:

typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]

final class betty.serde.format.Yaml[source]

Bases: Format

Defines the YAML (de)serialization format.

dump(dump: bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | type[betty.typing.Void]) str[source]

Serialize data.

Parameters:

dump (typing.Union[bool, int, float, str, None, typing.Sequence[typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]], typing.Mapping[str, typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]], type[betty.typing.Void]])

Return type:

str

property extensions: set[str]

The file extensions this format can (de)serialize.

Extensions MUST NOT include a leading dot.

property label: Localizable

The format’s human-readable label.

load(dump: str) bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump][source]

Deserialize data.

Parameters:

dump (str)

Return type:

typing.Union[bool, int, float, str, None, typing.Sequence[Dump], typing.Mapping[str, Dump]]