From cce6d80aaa5ac8496739e6ca8de3600ddfcd02b2 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Fri, 12 Feb 2021 20:31:59 +0200 Subject: [PATCH] Reuse defaults from ConfigParser.SafeConfigParser --- src/bmconfigparser.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index cd826bb4..1cc67577 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -25,18 +25,18 @@ BMConfigDefaults = { "receive": 3, }, "network": { - "bind": '', + "bind": "", "dandelion": 90, }, "inventory": { "storage": "sqlite", - "acceptmismatch": False, + "acceptmismatch": "False", }, "knownnodes": { "maxnodes": 20000, }, "zlib": { - 'maxsize': 1048576 + "maxsize": 1048576 } } @@ -51,6 +51,9 @@ class BMConfigParser(ConfigParser.SafeConfigParser): _temp = {} + def __init__(self): + ConfigParser.SafeConfigParser.__init__(self, defaults=BMConfigDefaults) + def set(self, section, option, value=None): if self._optcre is self.OPTCRE or value: if not isinstance(value, basestring): @@ -137,19 +140,11 @@ class BMConfigParser(ConfigParser.SafeConfigParser): ConfigParser.ConfigParser.read(self, filenames) for section in self.sections(): for option in self.options(section): - try: - if not self.validate( - section, option, - ConfigParser.ConfigParser.get(self, section, option) - ): - try: - newVal = BMConfigDefaults[section][option] - except KeyError: - continue - ConfigParser.ConfigParser.set( - self, section, option, newVal) - except ConfigParser.InterpolationError: - continue + if not self.validate( + section, option, + ConfigParser.ConfigParser.get(self, section, option) + ): + self.remove_option(section, option) def save(self): """Save the runtime config onto the filesystem"""