fail2ban.client.configparserinc module¶
- class fail2ban.client.configparserinc.SafeConfigParserWithIncludes(share_config=None, *args, **kwargs)¶
Bases:
ConfigParser
Class adds functionality to SafeConfigParser to handle included other configuration files (or may be urls, whatever in the future)
File should have section [includes] and only 2 options implemented are ‘files_before’ and ‘files_after’ where files are listed 1 per line.
Example:
[INCLUDES] before = 1.conf
3.conf
after = 1.conf
It is a simple implementation, so just basic care is taken about recursion. Includes preserve right order, ie new files are inserted to the list of read configs before original, and their includes correspondingly so the list should follow the leaves of the tree.
I wasn’t sure what would be the right way to implement generic (aka c++ template) so we could base at any *configparser class… so I will leave it for the future
- Attributes:
- converters
- share_config
Methods
add_section
(section)Create a new section in the configuration.
clear
()get
(section, option, *[, raw, vars, fallback])Get an option value for a given section.
get_ex
(section, option[, raw, vars])Get an option value for a given section.
getint
(section, option, *[, raw, vars, fallback])has_option
(section, option)Check for the existence of a given option in a given section.
has_section
(section)Indicate whether the named section is present in the configuration.
items
([section, raw, vars])Return a list of (name, value) tuples for each option in a section.
keys
()options
(section[, withDefault])Return a list of option names for the given section name.
pop
(k[,d])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.
read
(filenames[, get_includes])Read and parse a filename or an iterable of filenames.
read_dict
(dictionary[, source])Read configuration from a dictionary.
read_file
(f[, source])Like read() but the argument must be a file-like object.
read_string
(string[, source])Read configuration from a given string.
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])Set an option.
setdefault
(k[,d])update
([E, ]**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
()write
(fp[, space_around_delimiters])Write an .ini-format representation of the configuration state.
defaults
get_defaults
get_sections
getboolean
getfloat
merge_section
optionxform
- CONDITIONAL_RE = re.compile('^(\\w+)(\\?.+)$')¶
- SECTION_NAME = 'INCLUDES'¶
- SECTION_OPTNAME_CRE = re.compile('^([\\w\\-]+)/([^\\s>]+)$')¶
- SECTION_OPTSUBST_CRE = re.compile('%\\(([\\w\\-]+/([^\\)]+))\\)s')¶
- get_defaults()¶
- get_ex(section, option, raw=False, vars={})¶
Get an option value for a given section.
In opposite to get, it differentiate session-related option name like sec/opt.
- get_sections()¶
- merge_section(section, options, pref=None)¶
- options(section, withDefault=True)¶
Return a list of option names for the given section name.
Parameter withDefault controls the include of names from section [DEFAULT]
- read(filenames, get_includes=True)¶
Read and parse a filename or an iterable of filenames.
Files that cannot be opened are silently ignored; this is designed so that you can specify an iterable of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the iterable will be read. A single filename may also be given.
Return list of successfully read files.