From 59d3994859ae04887c5f9d6c288c2d046f4fb3c7 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 11 Oct 2014 16:26:43 +0200 Subject: [PATCH] core (config): added the Exception default value which raise an exception instead of returning the default in getConfig --- src/tools/config.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tools/config.py b/src/tools/config.py index 589667f6..fde983fd 100644 --- a/src/tools/config.py +++ b/src/tools/config.py @@ -73,15 +73,19 @@ def getConfig(config, section, name, default=None): @param config (SafeConfigParser): the configuration instance @param section (str): section of the config file (None or '' for DEFAULT) @param name (str): name of the option - @param default: value to use if not found + @param default: value to use if not found, or Exception to raise an exception @return: str, list or dict + @raise: NoOptionError if option is not present and default is Exception + NoSectionError if section doesn't exists and default is Exception """ if not section: section = DEFAULTSECT try: value = config.get(section, name) - except (NoOptionError, NoSectionError): + except (NoOptionError, NoSectionError) as e: + if default is Exception: + raise e return default if name.endswith('_path') or name.endswith('_dir'):