cement.ext.ext_configparser

The ConfigParser Extension provides configuration handling based on the standard ConfigParser, and is the default configuration handler used by Cement.

Requirements

  • No external dependencies.

Configuration

This extension does not honor any application configuration settings.

Usage

from cement.core.foundation import CementApp

with CementApp() as app:
    app.run()

    # get a config setting
    app.config.get('myapp', 'foo')

    # set a config setting
    app.config.set('myapp', 'foo', 'bar2')

    # etc.
class cement.ext.ext_configparser.ConfigParserConfigHandler(*args, **kw)

Bases: cement.core.config.CementConfigHandler, configparser.RawConfigParser

This class is an implementation of the IConfig 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

Bases: object

Handler meta-data.

interface

The interface that this handler implements.

alias of IConfig

label = 'configparser'

The string identifier of this handler.

ConfigParserConfigHandler._parse_file(file_path)

Parse a configuration file at file_path and store it.

Parameters:file_path – The file system path to the configuration file.
Returns:boolean (True if file was read properly, False otherwise)
ConfigParserConfigHandler.add_section(section)

Adds a block section to the config.

Parameters:section – The section to add.
ConfigParserConfigHandler.get_section_dict(section)

Return a dict representation of a section.

Parameters:section – The section of the configuration. I.e. [block_section]
Returns:Dictionary reprisentation of the config section.
Return type:dict
ConfigParserConfigHandler.get_sections()

Return a list of configuration sections or [blocks].

Returns:List of sections.
Return type:list
ConfigParserConfigHandler.keys(section)

Return a list of keys within ‘section’.

Parameters:section – The config section (I.e. [block_section]).
Returns:List of keys in the section.
Return type:list
ConfigParserConfigHandler.merge(dict_obj, override=True)

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

Parameters:
  • dict_obj – A dictionary of configuration keys/values to merge into our existing config (self).
  • override – Whether or not to override existing values in the config.