betty.serde.format module - Betty 0.4.0a1 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.serde.format module

Provide serialization formats.

class betty.serde.format.Format

  Bases: `object`

  Defines a (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.serde.dump.Void]) → str

    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.serde.dump.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]

    Deserialize data.

    Parameters:

      dump (`str`)

    Return type:

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

class betty.serde.format.FormatRepository

  Bases: `object`

  Exposes the available (de)serialization formats.

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

    All file extensions supported by the formats in this repository.

  format_for(extension: str) → betty.serde.format.Format

    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.

class betty.serde.format.FormatStr

  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])
    Parameters:

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

  localize(localizer: betty.locale.Localizer) → str

    Localize `self` to a human-readable string.

    Parameters:

      localizer (`betty.locale.Localizer`)

    Return type:

      `str`

class betty.serde.format.Json

  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.serde.dump.Void]) → str

    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.serde.dump.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]

    Deserialize data.

    Parameters:

      dump (`str`)

    Return type:

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

class betty.serde.format.Yaml

  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.serde.dump.Void]) → str

    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.serde.dump.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]

    Deserialize data.

    Parameters:

      dump (`str`)

    Return type:

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