cement.core.config
Cement core config module.
- class cement.core.config.ConfigHandler(**kw: Any)[source]
Bases:
ConfigInterface,HandlerConfig handler implementation.
- abstractmethod _parse_file(file_path: str) bool[source]
Parse a configuration file at
file_pathand store it. This function must be provided by the handler implementation (that is sub-classing this).
- parse_file(file_path: str) bool[source]
Ensure we are using the absolute/expanded path to
file_path, and then callself._parse_fileto parse config file settings from it, overwriting existing config settings.Developers sub-classing from here should generally override
_parse_filewhich handles just the parsing of the file and leaving this function to wrap any checks/logging/etc.
- class cement.core.config.ConfigInterface(**kw: Any)[source]
Bases:
InterfaceThis class defines the Config Interface. Handlers that implement this interface must provide the methods and attributes defined below. In general, most implementations should sub-class from the provided
ConfigHandlerbase class as a starting point.- abstractmethod add_section(section: str) None[source]
Add a new section if it doesn’t already exist.
- Parameters:
section – The section label to create.
- Returns:
None
- abstractmethod get(section: str, key: str) Any[source]
Return a configuration value based on
section.key. Must honor environment variables if they exist to override the config… for exampleconfig['myapp']['foo']['bar']must be overridable by the environment variableMYAPP_FOO_BAR…. Note thatMYAPP_must prefix all vars, thereforeconfig['redis']['foo']would be overridable byMYAPP_REDIS_FOO… butconfig['myapp']['foo']['bar']would not have a double prefix ofMYAPP_MYAPP_FOO_BAR.
- abstractmethod get_dict() Dict[str, Any][source]
Return a dict of the entire configuration.
- Returns:
A dictionary of the entire config.
- Return type:
- abstractmethod get_section_dict(section: str) Dict[str, Any][source]
Return a dict of configuration parameters for
section.
- abstractmethod get_sections() List[str][source]
Return a list of configuration sections.
- Returns:
A list of config sections.
- Return type:
- abstractmethod keys(section: str) List[str][source]
Return a list of configuration keys from
section.
- abstractmethod merge(dict_obj: dict, override: bool = True) None[source]
Merges a dict object into the configuration.