anyconfig.backend.toml

TOML backend:

  • Format to support: TOML, https://github.com/toml-lang/toml
  • Requirements: (python) toml module, https://github.com/uiri/toml
  • Development Status :: 4 - Beta
  • Limitations: None obvious
  • Special options:
    • toml.load{s,} only accept ‘_dict’ keyword option but it’s used already to pass callable to make a container object.

Changelog:

New in version 0.1.0.

class anyconfig.backend.toml.Parser

Bases: anyconfig.backend.base.StringStreamFnParser

TOML parser.

_type = 'toml'
_extensions = ['toml']
_ordered = True
_load_opts = ['_dict']
_dump_opts = ['_dict']
_dict_opts = ['_dict']
_load_from_string_fn(_dict=<class 'dict'>, decoder=None)

Parses string as toml

Args:
s: String to be parsed _dict: (optional) Specifies the class of the returned toml dictionary
Returns:
Parsed toml file represented as a dictionary
Raises:
TypeError: When a non-string is passed TomlDecodeError: Error while decoding toml
_load_from_stream_fn(_dict=<class 'dict'>, decoder=None)

Parses named file or files as toml and returns a dictionary

Args:
f: Path to the file to open, array of files to read into single dict
or a file descriptor

_dict: (optional) Specifies the class of the returned toml dictionary

Returns:
Parsed toml file represented as a dictionary
Raises:
TypeError – When f is invalid type TomlDecodeError: Error while decoding toml IOError / FileNotFoundError – When an array with no valid (existing) (Python 2 / Python 3) file paths is passed
_dump_to_string_fn(encoder=None)

Stringifies input dict as toml

Args:

o: Object to dump into toml

preserve: Boolean parameter. If true, preserve inline tables.

Returns:
String containing the toml corresponding to dict
_dump_to_stream_fn(f)

Writes out dict as toml to a file

Args:
o: Object to dump into toml f: File descriptor where the toml should be stored
Returns:
String containing the toml corresponding to dictionary
Raises:
TypeError: When anything other than file descriptor is passed
__module__ = 'anyconfig.backend.toml'