+class ConfigWrapper(object):
+ def __init__(self, config):
+ self.config = config
+
+ def get(self, section, option, default=None):
+ try:
+ return self.config.get(section, option)
+ except (NoSectionError, NoOptionError):
+ return default
+
+ def set(self, section, option, value):
+ self.config.set(section, option, value)
+
+ def getint(self, section, option, default=0):
+ try:
+ return self.config.getint(section, option)
+ except (NoSectionError, NoOptionError):
+ return default
+ # Do not catch ValueError here, it must be propagated
+
+ def getlist(self, section, option, default=None, sep=None):
+ value = self.get(section, option)
+ if not value:
+ if default is None:
+ return []
+ return default
+ return value.split(sep)
+
+ def getpath(self, section, option, default=os.path.curdir):
+ path = self.get(section, option, default=default)
+ return os.path.expanduser(os.path.expandvars(path))
+
+
+def get_config(config_path=None):