diff src/tools/config.py @ 1234:9c17bd37e6e5

core: better management of default value in getConfig
author Goffi <goffi@goffi.org>
date Tue, 07 Oct 2014 17:12:41 +0200
parents 7ee9d9db67b9
children 80d2ed788b40
line wrap: on
line diff
--- a/src/tools/config.py	Mon Oct 06 17:25:41 2014 +0200
+++ b/src/tools/config.py	Tue Oct 07 17:12:41 2014 +0200
@@ -73,7 +73,7 @@
     @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 @@
 
     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)