Reuse defaults from ConfigParser.SafeConfigParser

This commit is contained in:
Dmitri Bogomolov 2021-02-12 20:31:59 +02:00
parent 98089681bd
commit cce6d80aaa
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -25,18 +25,18 @@ BMConfigDefaults = {
"receive": 3, "receive": 3,
}, },
"network": { "network": {
"bind": '', "bind": "",
"dandelion": 90, "dandelion": 90,
}, },
"inventory": { "inventory": {
"storage": "sqlite", "storage": "sqlite",
"acceptmismatch": False, "acceptmismatch": "False",
}, },
"knownnodes": { "knownnodes": {
"maxnodes": 20000, "maxnodes": 20000,
}, },
"zlib": { "zlib": {
'maxsize': 1048576 "maxsize": 1048576
} }
} }
@ -51,6 +51,9 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
_temp = {} _temp = {}
def __init__(self):
ConfigParser.SafeConfigParser.__init__(self, defaults=BMConfigDefaults)
def set(self, section, option, value=None): def set(self, section, option, value=None):
if self._optcre is self.OPTCRE or value: if self._optcre is self.OPTCRE or value:
if not isinstance(value, basestring): if not isinstance(value, basestring):
@ -137,19 +140,11 @@ class BMConfigParser(ConfigParser.SafeConfigParser):
ConfigParser.ConfigParser.read(self, filenames) ConfigParser.ConfigParser.read(self, filenames)
for section in self.sections(): for section in self.sections():
for option in self.options(section): for option in self.options(section):
try: if not self.validate(
if not self.validate( section, option,
section, option, ConfigParser.ConfigParser.get(self, section, option)
ConfigParser.ConfigParser.get(self, section, option) ):
): self.remove_option(section, option)
try:
newVal = BMConfigDefaults[section][option]
except KeyError:
continue
ConfigParser.ConfigParser.set(
self, section, option, newVal)
except ConfigParser.InterpolationError:
continue
def save(self): def save(self):
"""Save the runtime config onto the filesystem""" """Save the runtime config onto the filesystem"""