core: better management of default value in getConfig

This commit is contained in:
Goffi 2014-10-07 17:12:41 +02:00
commit 6b20989ecc

View file

@ -73,7 +73,7 @@ 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 (str): eventually default to this value, if not None
@param default: value to use if not found
@return: str, list or dict
"""
if not section:
@ -81,10 +81,8 @@ def getConfig(config, section, name, default=None):
try:
value = config.get(section, name)
except (NoOptionError, NoSectionError) as e:
if default is None:
raise e
value = default
except (NoOptionError, NoSectionError):
return default
if name.endswith('_path') or name.endswith('_dir'):
value = os.path.expanduser(value)