lib.ExtendedConfigParser¶
Classes
ExtendedSectionProxy
: A proxy for a single section from a parser.ExtendedInterpolation
: Dummy interpolation that passes the value through with no changes.ExtendedConfigParser
: ConfigParser implementing interpolation.
-
class
lib.ExtendedConfigParser.
ExtendedSectionProxy
(parser, name)[source]¶ Inheritance
Members
-
_MutableMapping__marker
= <object object>¶
-
_abc_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version
= 43¶
-
_abc_registry
= <_weakrefset.WeakSet object>¶
-
_options
()¶
-
clear
() → None. Remove all items from D.¶
-
get
(option, fallback=None, *, raw=False, vars=None, _impl=None, **kwargs)¶ Get an option value.
Unless fallback is provided, None will be returned if the option is not found.
-
items
() → a set-like object providing a view on D's items¶
-
keys
() → a set-like object providing a view on D's keys¶
-
name
¶
-
parser
¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), remove and return some (key, value) pair¶ as a 2-tuple; but raise KeyError if D is empty.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
() → an object providing a view on D's values¶
-
-
class
lib.ExtendedConfigParser.
ExtendedInterpolation
[source]¶ Inheritance
Members
-
_KEYCRE
= re.compile('\\$\\{(?P<ref>[^}]+)\\}')¶
-
_KEYCRE2
= re.compile('\\$\\[(?P<ref>[^\\]]+)\\}')¶
-
before_read
(parser, section, option, value)¶
-
before_write
(parser, section, option, value)¶
-
-
class
lib.ExtendedConfigParser.
ExtendedConfigParser
(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section='DEFAULT', interpolation=<object object>, converters=<object object>)[source]¶ Inheritance
Members
-
_DEFAULT_INTERPOLATION
= <lib.ExtendedConfigParser.ExtendedInterpolation object>¶
-
BOOLEAN_STATES
= {'true': True, '1': True, 'no': False, 'on': True, 'yes': True, 'off': False, 'false': False, '0': False}¶
-
NONSPACECRE
= re.compile('\\S')¶
-
OPTCRE
= re.compile('\n (?P<option>.*?) # very permissive!\n \\s*(?P<vi>=|:)\\s* # any number of space/tab,\n # followed by any of t, re.VERBOSE)¶
-
OPTCRE_NV
= re.compile('\n (?P<option>.*?) # very permissive!\n \\s*(?: # any number of space/tab,\n (?P<vi>=|:)\\s* # optionally followed , re.VERBOSE)¶
-
SECTCRE
= re.compile('\n \\[ # [\n (?P<header>[^]]+) # very permissive!\n \\] # ]\n ', re.VERBOSE)¶
-
_MutableMapping__marker
= <object object>¶
-
_OPT_NV_TMPL
= '\n (?P<option>.*?) # very permissive!\n \\s*(?: # any number of space/tab,\n (?P<vi>{delim})\\s* # optionally followed by\n # any of the allowed\n # delimiters, followed by any\n # space/tab\n (?P<value>.*))?$ # everything up to eol\n '¶
-
_OPT_TMPL
= '\n (?P<option>.*?) # very permissive!\n \\s*(?P<vi>{delim})\\s* # any number of space/tab,\n # followed by any of the\n # allowed delimiters,\n # followed by any space/tab\n (?P<value>.*)$ # everything up to eol\n '¶
-
_SECT_TMPL
= '\n \\[ # [\n (?P<header>[^]]+) # very permissive!\n \\] # ]\n '¶
-
_abc_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version
= 43¶
-
_abc_registry
= <_weakrefset.WeakSet object>¶
-
_convert_to_boolean
(value)¶ Return a boolean value translating from other types if necessary.
-
_get
(section, conv, option, **kwargs)¶
-
_get_conv
(section, option, conv, *, raw=False, vars=None, fallback=<object object>, **kwargs)¶
-
_handle_error
(exc, fpname, lineno, line)¶
-
_join_multiline_values
()¶
-
_read
(fp, fpname)¶ Parse a sectioned configuration file.
Each section in a configuration file contains a header, indicated by a name in square brackets ([]’), plus key/value options, indicated by ``name` and
value
delimited with a specific substring (`=’ or `:’ by default).Values can span multiple lines, as long as they are indented deeper than the first line of the value. Depending on the parser’s mode, blank lines may be treated as parts of multiline values or ignored.
Configuration files may include comments, prefixed by specific characters (`#’ and `;’ by default). Comments may appear on their own in an otherwise empty line or may be entered in lines holding values or section names.
-
_validate_value_types
(*, section='', option='', value='')¶ Raises a TypeError for non-string values.
The only legal non-string value if we allow valueless options is None, so we need to check if the value is a string if: - we do not allow valueless options, or - we allow valueless options but the value is not None
For compatibility reasons this method is not used in classic set() for RawConfigParsers. It is invoked in every case for mapping protocol access and in ConfigParser.set().
-
_write_section
(fp, section_name, section_items, delimiter)¶ Write a single section to the specified
fp
.
-
add_section
(section)¶ Create a new section in the configuration. Extends RawConfigParser.add_section by validating if the section name is a string.
-
converters
¶
-
defaults
()¶
-
get
(section, option, *, raw=False, vars=None, fallback=<object object>)¶ Get an option value for a given section.
If
vars
is provided, it must be a dictionary. The option is looked up invars
(if provided),section
, and inDEFAULTSECT
in that order. If the key is not found andfallback
is provided, it is used as a fallback value.None
can be provided as afallback
value.If interpolation is enabled and the optional argument
raw
is False, all interpolations are expanded in the return values.Arguments
raw
,vars
, andfallback
are keyword only.The section DEFAULT is special.
-
getboolean
(section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs)¶
-
getfloat
(section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs)¶
-
getint
(section, option, *, raw=False, vars=None, fallback=<object object>, **kwargs)¶
-
has_section
(section)¶ Indicate whether the named section is present in the configuration.
The DEFAULT section is not acknowledged.
-
items
(section=<object object>, raw=False, vars=None)¶ Return a list of (name, value) tuples for each option in a section.
All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional argument
raw
is true. Additional substitutions may be provided using thevars
argument, which must be a dictionary whose contents overrides any pre-existing defaults.The section DEFAULT is special.
-
keys
() → a set-like object providing a view on D's keys¶
-
options
(section)¶ Return a list of option names for the given section name.
-
optionxform
(optionstr)¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding value.¶ If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
()¶ Remove a section from the parser and return it as a (section_name, section_proxy) tuple. If no section is present, raise KeyError.
The section DEFAULT is never returned because it cannot be removed.
-
read
(filenames, encoding=None)¶ Read and parse a filename or a list of filenames.
Files that cannot be opened are silently ignored; this is designed so that you can specify a list of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the list will be read. A single filename may also be given.
Return list of successfully read files.
-
read_dict
(dictionary, source='<dict>')¶ Read configuration from a dictionary.
Keys are section names, values are dictionaries with keys and values that should be present in the section. If the used dictionary type preserves order, sections and their keys will be added in order.
All types held in the dictionary are converted to strings during reading, including section names, option names and keys.
Optional second argument is the
source
specifying the name of the dictionary being read.
-
read_file
(f, source=None)¶ Like read() but the argument must be a file-like object.
The
f
argument must be iterable, returning one line at a time. Optional second argument is thesource
specifying the name of the file being read. If not given, it is taken from f.name. Iff
has noname
attribute, `<???>’ is used.
-
read_string
(string, source='<string>')¶ Read configuration from a given string.
-
readfp
(fp, filename=None)¶ Deprecated, use read_file instead.
-
remove_option
(section, option)¶ Remove an option.
-
remove_section
(section)¶ Remove a file section.
-
sections
()¶ Return a list of section names, excluding [DEFAULT]
-
set
(section, option, value=None)¶ Set an option. Extends RawConfigParser.set by validating type and interpolation syntax on the value.
-
setdefault
(k[, d]) → D.get(k,d), also set D[k]=d if k not in D¶
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
values
() → an object providing a view on D's values¶
-
write
(fp, space_around_delimiters=True)¶ Write an .ini-format representation of the configuration state.
If
space_around_delimiters
is True (the default), delimiters between keys and values are surrounded by spaces.
-
Interpolation
¶
-