cement.ext.ext_configparser

Cement configparser extension module.

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

Bases: cement.core.config.ConfigHandler, configparser.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: object

Handler meta-data.

label = 'configparser'

The string identifier of this handler.

_parse_file(file_path)[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)[source]

Adds a block section to the config.

Parameters:section (str) – The section to add.
get(section, key)[source]

Return a configuration value based on section.key. Must honor environment variables if they exist to override the config… for example config['myapp']['foo']['bar'] must be overridable by the environment variable MYAPP_FOO_BAR…. Note that MYAPP_ must prefix all vars, therefore config['redis']['foo'] would be overridable by MYAPP_REDIS_FOO … but config['myapp']['foo']['bar'] would not have a double prefix of MYAPP_MYAPP_FOO_BAR.

Parameters:
  • section (str) – The section of the configuration to pull key values from.
  • key (str) – The configuration key to get the value for.
Returns:

The value of the key in section.

Return type:

unknown

get_dict()[source]

Return a dict of the entire configuration.

Returns:A dictionary of the entire config.
Return type:dict
get_section_dict(section)[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()[source]

Return a list of configuration sections.

Returns:List of sections
Return type:list
has_section(section)[source]

Returns whether or not the section exists.

Parameters:section (str) – The section to test for.
Returns:
True if the configuration section exists, False
otherwise.
Return type:bool
keys(section)[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, override=True)[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, key, value)[source]

Set a configuration value based at section.key.

Parameters:
  • section (str) – The section of the configuration to pull key value from.
  • key (str) – The configuration key to set the value at.
  • value – The value to set.
Returns:

None