anyconfig.backend.ini.configparser
¶
A backend module to load and dump INI files.
Format to support: INI or INI like ones
Requirements: The following standard module which should be available always.
ConfigParser in python 2 standard library: https://docs.python.org/2.7/library/configparser.html
configparser in python 3 standard library: https://docs.python.org/3/library/configparser.html
Development Status :: 4 - Beta
Limitations: It cannot process nested configuration dicts correctly due to the limitation of the module and the format ifself.
Special options:
Use ‘ac_parse_value’ boolean keyword option if you want to parse values by custom parser, anyconfig.backend.ini.parse.
Changelog:
Changed in version 0.14.0: Re-organized to allow supporting other parser
Changed in version 0.3:
Introduce ‘ac_parse_value’ keyword option to switch behaviors, same as original configparser and rich backend parsing each parameter values.
- anyconfig.backend.ini.configparser.parse(val_s, sep=', ', quoted_re=re.compile('^(".*"|\\'.*\\')$'))¶
Parse expression.
FIXME: May be too naive implementation.
- Parameters:
val_s (
str
) – A string represents some value to parsesep (
str
) – separator between values
- Return type:
Any
- anyconfig.backend.ini.configparser._to_s(val, sep=', ')¶
Convert any object to string.
- Parameters:
val (
Any
) – An objectsep (
str
) – separator between values
- Return type:
str
- anyconfig.backend.ini.configparser.parsed_items(items, sep=',', **options)¶
Parse an iterable of items.
- Parameters:
items (
Iterable
[tuple
[str
,Any
]]) – List of pairs, [(key, value)], or generator yields pairssep (
str
) – Seprator string
- Return type:
Iterator
[tuple
[str
,Any
]]- Returns:
Generator to yield (key, value) pair of ‘dic’
- anyconfig.backend.ini.configparser._make_parser(**kwargs)¶
Make an instance of configparser.ConfigParser.
- Return type:
tuple
[dict
[str
,Any
],ConfigParser
]
- anyconfig.backend.ini.configparser._load(stream, container, sep=',', dkey='DEFAULT', **kwargs)¶
Load data from
stream
of which file should be in INI format.- Parameters:
stream (
IO
) – File or file-like object provides ini-style confcontainer (
Callable
[...
,dict
[str
,Any
]]) – any callable to make containersep (
str
) – Seprator stringdkey (
str
) – Default section name
- Return type:
dict
[str
,Any
]- Returns:
Dict or dict-like object represents config values
- anyconfig.backend.ini.configparser._dumps_itr(cnf, dkey='DEFAULT')¶
Dump data iterably.
- Parameters:
cnf (
dict
[str
,Any
]) – Configuration data to dump- Return type:
Iterator
[str
]
- anyconfig.backend.ini.configparser._dumps(cnf, **_kwargs)¶
Dump data as a str.
- Parameters:
cnf (
dict
[str
,Any
]) – Configuration data to dump_kwargs – optional keyword parameters to be sanitized :: dict
- Return type:
str
- Returns:
String representation of ‘cnf’ object in INI format
- class anyconfig.backend.ini.configparser.Parser¶
Bases:
Parser
,FromStreamLoaderMixin
,ToStringDumperMixin
Ini config files parser.
-
_cid:
ClassVar
[str
] = 'ini.configparser'¶
-
_type:
ClassVar
[str
] = 'ini'¶
-
_extensions:
tuple
[str
,...
] = ('ini',)¶
-
_load_opts:
tuple
[str
,...
] = ('defaults', 'dict_type', 'allow_no_value', 'filename', 'ac_parse_value', 'strict')¶
-
_dict_opts:
tuple
[str
,...
] = ('dict_type',)¶
- dump_to_string(**_kwargs)¶
Dump data as a str.
- Parameters:
cnf (
dict
[str
,Any
]) – Configuration data to dump_kwargs – optional keyword parameters to be sanitized :: dict
- Return type:
str
- Returns:
String representation of ‘cnf’ object in INI format
- load_from_stream(container, sep=',', dkey='DEFAULT', **kwargs)¶
Load data from
stream
of which file should be in INI format.- Parameters:
stream (
IO
) – File or file-like object provides ini-style confcontainer (
Callable
[...
,dict
[str
,Any
]]) – any callable to make containersep (
str
) – Seprator stringdkey (
str
) – Default section name
- Return type:
dict
[str
,Any
]- Returns:
Dict or dict-like object represents config values
- __annotations__ = {'_allow_primitives': 'typing.ClassVar[bool]', '_cid': 'typing.ClassVar[str]', '_dict_opts': 'tuple[str, ...]', '_dump_opts': 'tuple[str, ...]', '_extensions': 'tuple[str, ...]', '_load_opts': 'tuple[str, ...]', '_open_read_mode': 'typing.ClassVar[str]', '_open_write_mode': 'typing.ClassVar[str]', '_ordered': 'typing.ClassVar[bool]', '_priority': 'typing.ClassVar[int]', '_type': 'typing.ClassVar[str]'}¶
- __module__ = 'anyconfig.backend.ini.configparser'¶
-
_cid: