anyconfig.backend.python.loader

A backend module to load python code conntains data.

  • Format to support: Python code

  • Requirements: None (built-in)

  • Development Status :: 3 - Alpha

  • Limitations:

    • This module will load data as it is. In other words, some options like ac_dict and ac_ordered do not affetct at all.

    • Some primitive data expressions support only

    • It might have some vulnerabilities for DoS and aribitary code execution (ACE) attacks

  • Special options:

    • allow_exec: bool [False]: Allow execution of the input python code on load input files. It may cause vulnerabilities for aribitary code execution (ACE) attacks. So you should set True only if you sure inputs are safe from reliable sources.

Changelog:

Added in version 0.14.0:

  • Added builtin data loader from python code

anyconfig.backend.python.loader.load_from_temp_file(content, **opts)

Dump content to tempoary file and load from it.

Parameters:

content (str) – A str to load data from

Return type:

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

class anyconfig.backend.python.loader.Loader

Bases: LoaderMixin

Loader for python code files.

_allow_primitives: ClassVar[bool] = True
_load_opts: tuple[str, ...] = ('allow_exec',)
loads(content, **options)

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

Parameters:
  • content (str) – Config file content

  • options – It will be ignored at all except for ‘allow_exec’ opion to allow execution of the code

Return type:

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

Returns:

dict or dict-like object holding input data or primitives

load(ioi, **options)

Load config from ioi.

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

  • 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

__annotations__ = {'_allow_primitives': 'typing.ClassVar[bool]', '_dict_opts': 'tuple[str, ...]', '_load_opts': 'tuple[str, ...]', '_open_read_mode': 'typing.ClassVar[str]', '_ordered': 'typing.ClassVar[bool]'}
__module__ = 'anyconfig.backend.python.loader'