cement.ext.ext_configparser

Cement configparser extension module.

class cement.ext.ext_configparser.ConfigParserConfigHandler(**kw: Any)[source]

Bases: ConfigHandler, RawConfigParser

This class is an implementation of the Config interface. It handles configuration file parsing and the like by sub-classing from the standard ConfigParser library. Please see the ConfigParser documentation for full usage of the class.

Additional arguments and keyword arguments are passed directly to RawConfigParser on initialization.

class Meta[source]

Bases: Meta

Handler meta-data.

label: str = 'configparser'

The string identifier of this handler.

_parse_file(file_path: str) bool[source]

Parse a configuration file at file_path and store it.

Parameters:

file_path (str) – The file system path to the configuration file.

Returns:

True if file was read properly, False otherwise

Return type:

bool

add_section(section: str) None[source]

Adds a block section to the config.

Parameters:

section (str) – The section to add.

get(section: str, key: str, **kwargs: Any) str[source]

Get a config value for a given section, and key.

Parameters:
  • section (str) – The section that the key exists.

  • key (str) – The key of the configuration item.

Keyword Arguments:

kwargs (dict) – Passed on to the the backend config parser (super class).

Returns:

Returns the value of the key in the configuration section.

Return type:

value (unknown)

get_dict() Dict[str, Any][source]

Return a dict of the entire configuration.

Returns:

A dictionary of the entire config.

Return type:

dict

get_section_dict(section: str) Dict[str, Any][source]

Return a dict representation of a section.

Parameters:

section – The section of the configuration.

Returns:

Dictionary reprisentation of the config section.

Return type:

dict

get_sections() List[str][source]

Return a list of configuration sections.

Returns:

List of sections

Return type:

list

has_section(section: str) bool[source]

Test whether the section exists

Parameters:

section (str) – The section to test.

Returns:

True if the section exists, False otherwise.

Return type:

bool

keys(section: str) List[str][source]

Return a list of keys within section.

Parameters:

section (str) – The config section

Returns:

List of keys in the section.

Return type:

list

merge(dict_obj: dict, override: bool = True) None[source]

Merge a dictionary into our config. If override is True then existing config values are overridden by those passed in.

Parameters:

dict_obj (dict) – A dictionary of configuration keys/values to merge into our existing config (self).

Keyword Arguments:

override (bool) – Whether or not to override existing values in the config.

set(section: str, key: str, value: Any) None[source]

Set the value of key in section.

Parameters:
  • section (str) – The section that the key exists.

  • key (str) – The key of the configuration item inside section.

  • value (unknown) – The value to set to key.

Returns: None