anyconfig.backend.base.loaders

Abstract and basic loaders.

class anyconfig.backend.base.loaders.LoaderMixin

Bases: object

Mixin class to load data.

Inherited classes must implement the following methods.

Member variables:

  • _load_opts: Backend specific options on load

  • _ordered: True if the parser keep the order of items by default

  • _allow_primitives: True if the parser.load* may return objects of primitive data types other than mapping types such like JSON parser

  • _dict_opts: Backend options to customize dict class to make results

  • _open_read_mode: Backend option to specify read mode passed to open()

classmethod ordered()

Test if the parser keeps the order of the data.

Return type:

bool

classmethod allow_primitives()

Test if the paresr allows to hold primitive data.

Return type:

bool

Returns:

True if the parser.load* may return objects of primitive data types other than mapping types such like JSON parser

classmethod dict_options()

Get the list of dict factory options.

Return type:

tuple[str, ...]

ropen(filepath, **options)

Open files with read only mode.

Return type:

IO

load_from_string(content, container, **options)

Load config from given string ‘content’.

Parameters:
  • content (str) – Config content string

  • container (Callable[..., dict[str, Any]]) – callble to make a container object later

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

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

Dict-like object holding config parameters

load_from_path(filepath, container, **options)

Load config from given file path ‘filepath`.

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

  • container (Callable[..., dict[str, Any]]) – callble to make a container object later

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

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

Dict-like object holding config parameters

load_from_stream(stream, container, **options)

Load config from given file like object ‘stream`.

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

  • container (Callable[..., dict[str, Any]]) – callble to make a container object later

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

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

Dict-like object holding config parameters

loads(content, **options)

Load config from given string ‘content’ after some checks.

Parameters:
  • content (str) – Config file content

  • options – options will be passed to backend specific loading functions. please note that options have to be sanitized w/ anyconfig.utils.filter_options() later to filter out options not in _load_opts.

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

dict or dict-like object holding configurations

load(ioi, *, ac_ignore_missing=False, **options)

Load config from ioi.

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

  • ac_ignore_missing (bool) – Ignore and just return empty result if given ioi object does not exist in actual.

  • options – options will be passed to backend specific loading functions. please note that options have to be sanitized w/ anyconfig.utils.filter_options() later to filter out options not in _load_opts.

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

dict or dict-like object holding configurations

class anyconfig.backend.base.loaders.BinaryLoaderMixin

Bases: LoaderMixin

Mixin class to load binary (byte string) configuration files.

class anyconfig.backend.base.loaders.FromStringLoaderMixin

Bases: LoaderMixin

Abstract parser provides a method below.

  • amethod to load configuration from string content to help implement parser of which backend lacks of such function.

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

load_from_stream(stream, container, **options)

Load config from given stream ‘stream’.

Parameters:
  • stream (IO) – Config file or file-like object

  • container (Callable[..., dict[str, Any]]) – callble to make a container object later

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

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

Dict-like object holding config parameters

load_from_path(filepath, container, **options)

Load config from given file path ‘filepath’.

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

  • container (Callable[..., dict[str, Any]]) – callble to make a container object later

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

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

Dict-like object holding config parameters

class anyconfig.backend.base.loaders.FromStreamLoaderMixin

Bases: LoaderMixin

Abstract parser provides a method below.

  • A method to load configuration from string content to help implement parser of which backend lacks of such function.

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

load_from_string(content, container, **options)

Load config from given string ‘cnf_content’.

Parameters:
  • content (str) – Config content string

  • container (Callable[..., dict[str, Any]]) – callble to make a container object later

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

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

Dict-like object holding config parameters

load_from_path(filepath, container, **options)

Load config from given file path ‘filepath’.

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

  • container (Callable[..., dict[str, Any]]) – callble to make a container object later

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

Return type:

Union[None, int, float, bool, str, dict[str, Any]]

Returns:

Dict-like object holding config parameters