anyconfig.backend.base.dumpers

Abstract and basic dumpes.

class anyconfig.backend.base.dumpers.DumperMixin

Bases: object

Mixin class to dump data.

Inherited classes must implement the following methods.

Member variables:

  • _dump_opts: Backend specific options on dump

  • _open_write_mode: Backend option to specify write mode passed to open()

wopen(filepath, **options)

Open file filepath with the write mode _open_write_mode.

Return type:

IO

dump_to_string(cnf, **options)

Dump config ‘cnf’ to a string.

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • options – optional keyword parameters to be sanitized :: dict

Return type:

str

Returns:

string represents the configuration

dump_to_path(cnf, filepath, **options)

Dump config ‘cnf’ to a file ‘filepath’.

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • filepath (Union[str, Path]) – Config file path

  • options – optional keyword parameters to be sanitized :: dict

Return type:

None

dump_to_stream(cnf, stream, **options)

Dump config ‘cnf’ to a file-like object ‘stream’.

TODO: How to process socket objects same as file objects ?

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • stream (IO) – Config file or file like object

  • options – optional keyword parameters to be sanitized :: dict

Return type:

None

dumps(cnf, **options)

Dump config ‘cnf’ to a string.

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • options – optional keyword parameters to be sanitized :: dict

Return type:

str

Returns:

string represents the configuration

dump(cnf, ioi, **options)

Dump config ‘cnf’ to output object of which ‘ioi’ referring.

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • ioi (IOInfo) – an ‘anyconfig.cmmon.IOInfo’ namedtuple object provides various info of input object to load data from

  • options – optional keyword parameters to be sanitized :: dict

Raises:

IOError, OSError, AttributeError – When dump failed.

Return type:

None

class anyconfig.backend.base.dumpers.BinaryDumperMixin

Bases: DumperMixin

Mixin class to dump binary (byte string) configuration data.

class anyconfig.backend.base.dumpers.ToStringDumperMixin

Bases: DumperMixin

Abstract config parser provides the followings.

  • a method to dump configuration to a file or file-like object (stream) and a file of given path to help implement parser of which backend lacks of such functions.

Parser classes inherit this class have to override the method dump_to_string() at least.

dump_to_path(cnf, filepath, **options)

Dump config ‘cnf’ to a file ‘filepath’.

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • filepath (Union[str, Path]) – Config file path

  • options – optional keyword parameters to be sanitized :: dict

Return type:

None

dump_to_stream(cnf, stream, **options)

Dump config ‘cnf’ to a file-like object ‘stream’.

TODO: How to process socket objects same as file objects ?

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • stream (IO) – Config file or file like object

  • options – optional keyword parameters to be sanitized :: dict

Return type:

None

class anyconfig.backend.base.dumpers.ToStreamDumperMixin

Bases: DumperMixin

Abstract config parser provides the following methods.

  • to dump configuration to a string content or a file of given path to help implement parser of which backend lacks of such functions.

Parser classes inherit this class have to override the method dump_to_stream() at least.

dump_to_string(cnf, **options)

Dump config ‘cnf’ to a string.

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • options – optional keyword parameters to be sanitized :: dict

Return type:

str

Returns:

Dict-like object holding config parameters

dump_to_path(cnf, filepath, **options)

Dump config ‘cnf’ to a file ‘filepath`.

Parameters:
  • cnf (Union[None, int, float, bool, str, dict[str, Any]]) – Configuration data to dump

  • filepath (Union[str, Path]) – Config file path

  • options – optional keyword parameters to be sanitized :: dict

Return type:

None