typo in exception handling for get, NoSectionError will be caught as well; initialise ConfigParser in __init__, not in class
This commit is contained in:
parent
37954e432c
commit
e6d2b9a7bc
@ -4,13 +4,14 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
class Conf(object):
|
class Conf(object):
|
||||||
_confobj = configparser.ConfigParser(dict(HOME=os.environ.get('HOME')))
|
_confobj = None
|
||||||
_cfgfiles = []
|
_cfgfiles = []
|
||||||
debug = None
|
debug = None
|
||||||
|
|
||||||
def __init__(self, filename=None, debug=None, force_filename=False):
|
def __init__(self, filename=None, debug=None, force_filename=False):
|
||||||
if debug:
|
if debug:
|
||||||
self.set_debug(debug)
|
self.set_debug(debug)
|
||||||
|
self._confobj = configparser.ConfigParser(dict(HOME=os.environ.get('HOME')))
|
||||||
filenames = []
|
filenames = []
|
||||||
if not force_filename:
|
if not force_filename:
|
||||||
# default config files are $HOME/etc/userconfig2.conf and
|
# default config files are $HOME/etc/userconfig2.conf and
|
||||||
@ -44,7 +45,7 @@ class Conf(object):
|
|||||||
return self._confobj.getboolean(section, option)
|
return self._confobj.getboolean(section, option)
|
||||||
else:
|
else:
|
||||||
return self._confobj.get(section, option)
|
return self._confobj.get(section, option)
|
||||||
except (configparser.NoOptionError, configparser.NoOptionError) as e:
|
except (configparser.NoOptionError, configparser.NoSectionError) as e:
|
||||||
raise ValueError(f'Option {option} does not exist in section {section}: {e}')
|
raise ValueError(f'Option {option} does not exist in section {section}: {e}')
|
||||||
|
|
||||||
def set(self, option, value, section='userconfig'):
|
def set(self, option, value, section='userconfig'):
|
||||||
|
Loading…
Reference in New Issue
Block a user