Return use of BMConfigParser._temp dict,

also empty _temp in BMConfigParser._reset().
This commit is contained in:
Dmitri Bogomolov 2022-02-16 22:55:17 +02:00
parent 08099d4409
commit 161a0b2059
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -36,6 +36,15 @@ class BMConfigParser(SafeConfigParser):
raise ValueError("Invalid value %s" % value)
return SafeConfigParser.set(self, section, option, value)
def get(self, section, option, **kwargs):
"""Try returning temporary value before using parent get()"""
try:
return self._temp[section][option]
except KeyError:
pass
return SafeConfigParser.get(
self, section, option, **kwargs)
def setTemp(self, section, option, value=None):
"""Temporary set option to value, not saving."""
try:
@ -91,8 +100,11 @@ class BMConfigParser(SafeConfigParser):
return SafeConfigParser.items(self, section, True, variables)
def _reset(self):
"""Reset current config. There doesn't appear to be a built in
method for this"""
"""
Reset current config.
There doesn't appear to be a built in method for this.
"""
self._temp = {}
sections = self.sections()
for x in sections:
self.remove_section(x)