dom_toml.encoder


Dom’s custom encoder for Tom’s Obvious, Minimal Language.

New in version 0.2.0.

Classes:

TomlArraySeparatorEncoder([preserve, …])

TOML Encoder with adjustable array separator.

TomlEncoder([preserve, multiline_strings])

TOML encoder which wraps long lists onto multiple lines and adds a blank line before arrays of tables.

TomlNumpyEncoder([preserve, multiline_strings])

TOML Encoder with support for numpy types.

TomlPathlibEncoder([preserve, multiline_strings])

TOML Encoder with pathlib support.

class TomlArraySeparatorEncoder(preserve=True, multiline_strings=False, separator=',')[source]

Bases: TomlEncoder

TOML Encoder with adjustable array separator.

Parameters
  • preserve (bool) – Default True.

  • allow_multiline

  • separator (str) – Default ','.

New in version 2.0.0.

Methods:

format_inline_array(obj, nest_level)

Format an inline array.

format_inline_array(obj, nest_level)[source]

Format an inline array.

Parameters
Return type

str

class TomlEncoder(preserve=True, multiline_strings=False)[source]

Bases: object

TOML encoder which wraps long lists onto multiple lines and adds a blank line before arrays of tables.

Parameters
  • preserve (bool) – Default True.

  • allow_multiline

  • separator

Changed in version 0.2.0: Moved from __init__.py

Changed in version 2.0.0: Added allow_multiline argument.

Methods:

dumps(table, *, name[, inside_aot])

Serialise the given table.

format_decimal(obj)

Format a decimal value.

format_inline_array(obj, nest_level)

Format an inline array.

format_inline_table(obj)

Format an inline table.

format_key_part(part)

Format part of a key.

format_literal(obj, *[, nest_level])

Format a literal value.

format_string(s, *, allow_multiline)

Format a string.

dumps(table, *, name, inside_aot=False)[source]

Serialise the given table.

Parameters
  • name (str) – The table name.

  • inside_aot (bool) – Default False.

Return type

Iterator[str]

New in version 2.0.0.

format_decimal(obj)[source]

Format a decimal value.

Parameters

obj (Decimal)

Return type

str

New in version 2.0.0.

format_inline_array(obj, nest_level)[source]

Format an inline array.

Parameters
Return type

str

New in version 2.0.0.

format_inline_table(obj)[source]

Format an inline table.

Parameters

obj (dict)

Return type

str

New in version 2.0.0.

format_key_part(part)[source]

Format part of a key.

Parameters

part (str)

Return type

str

New in version 2.0.0.

format_literal(obj, *, nest_level=0)[source]

Format a literal value.

Parameters
  • obj (object)

  • nest_level (int) – Default 0.

Return type

str

New in version 2.0.0.

format_string(s, *, allow_multiline)[source]

Format a string.

Parameters
Return type

str

New in version 2.0.0.

class TomlNumpyEncoder(preserve=True, multiline_strings=False)[source]

Bases: TomlEncoder

TOML Encoder with support for numpy types.

New in version 2.0.0.

Methods:

format_literal(obj, *[, nest_level])

Format a literal value.

format_literal(obj, *, nest_level=0)[source]

Format a literal value.

Parameters
  • obj (object)

  • nest_level (int) – Default 0.

Return type

str

class TomlPathlibEncoder(preserve=True, multiline_strings=False)[source]

Bases: TomlEncoder

TOML Encoder with pathlib support.

New in version 2.0.0.

Methods:

format_literal(obj, *[, nest_level])

Format a literal value.

format_literal(obj, *, nest_level=0)[source]

Format a literal value.

Parameters
  • obj (object)

  • nest_level (int) – Default 0.

Return type

str