anyconfig.backend.ini
¶
INI backend:
- 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.3:
Introduce ‘ac_parse_value’ keyword option to switch behaviors, same as original configparser and rich backend parsing each parameter values.
-
anyconfig.backend.ini.
_parse
(val_s, sep=', ')¶ FIXME: May be too naive implementation.
Parameters: - val_s – A string represents some value to parse
- sep – separator between values
>>> _parse(r'"foo string"') 'foo string' >>> _parse("a, b, c") ['a', 'b', 'c'] >>> _parse("aaa") 'aaa'
-
anyconfig.backend.ini.
_to_s
(val, sep=', ')¶ Convert any to string.
Parameters: - val – An object
- sep – separator between values
>>> _to_s([1, 2, 3]) '1, 2, 3' >>> _to_s("aaa") 'aaa'
-
anyconfig.backend.ini.
_parsed_items
(items, sep=', ', **options)¶ Parameters: - items – List of pairs, [(key, value)], or generator yields pairs
- sep – Seprator string
Returns: Generator to yield (key, value) pair of dic
-
anyconfig.backend.ini.
_make_parser
(**kwargs)¶ Returns: (keyword args to be used, parser object)
-
anyconfig.backend.ini.
_load
(stream, container, sep=', ', dkey='DEFAULT', **kwargs)¶ Parameters: - stream – File or file-like object provides ini-style conf
- container – any callable to make container
- sep – Seprator string
- dkey – Default section name
Returns: Dict or dict-like object represents config values
-
anyconfig.backend.ini.
_dumps_itr
(cnf, dkey='DEFAULT')¶ Parameters: cnf – Configuration data to dump
-
anyconfig.backend.ini.
_dumps
(cnf, **kwargs)¶ Parameters: - cnf – Configuration data to dump
- kwargs – optional keyword parameters to be sanitized :: dict
Returns: String representation of cnf object in INI format
-
class
anyconfig.backend.ini.
Parser
¶ Bases:
anyconfig.backend.base.Parser
,anyconfig.backend.base.FromStreamLoaderMixin
,anyconfig.backend.base.ToStringDumperMixin
Ini config files parser.
-
_type
= 'ini'¶
-
_extensions
= ['ini']¶
-
_load_opts
= ['defaults', 'dict_type', 'allow_no_value', 'filename', 'ac_parse_value']¶
-
_dict_opts
= ['dict_type']¶
-
dump_to_string
(**kwargs)¶ Parameters: - cnf – Configuration data to dump
- kwargs – optional keyword parameters to be sanitized :: dict
Returns: String representation of cnf object in INI format
-
__module__
= 'anyconfig.backend.ini'¶
-
load_from_stream
(container, sep=', ', dkey='DEFAULT', **kwargs)¶ Parameters: - stream – File or file-like object provides ini-style conf
- container – any callable to make container
- sep – Seprator string
- dkey – Default section name
Returns: Dict or dict-like object represents config values
-