1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-15 08:40:34 +03:00

Added optional exception handler

This commit is contained in:
A_D 2020-12-24 12:51:03 +02:00 committed by Athanasius
parent 42a0c058ea
commit a6f3d4a382

View File

@ -229,7 +229,7 @@ class AbstractConfig(abc.ABC):
raise NotImplementedError
@abstractmethod
def delete(self, key: str) -> None:
def delete(self, key: str, *, suppress=False) -> None:
"""
Delete the given key from the config.
@ -466,8 +466,14 @@ class WinConfig(AbstractConfig):
# Its complaining about the list, it works, tested on windows, ignored.
winreg.SetValueEx(self.__reg_handle, key, REG_RESERVED_ALWAYS_ZERO, reg_type, val) # type: ignore
def delete(self, key: str) -> None:
winreg.DeleteValue(self.__reg_handle, key)
def delete(self, key: str, *, suppress=False) -> None:
try:
winreg.DeleteValue(self.__reg_handle, key)
except OSError:
if suppress:
return
raise
def save(self) -> None:
"""Save the configuration."""
@ -606,7 +612,7 @@ class MacConfig(AbstractConfig):
"""
self._settings[key] = val
def delete(self, key: str) -> None:
def delete(self, key: str, *, suppress=False) -> None:
"""
Delete the given key from the config.
@ -779,7 +785,7 @@ class LinuxConfig(AbstractConfig):
self.config.set(self.SECTION, key, to_set)
def delete(self, key: str) -> None:
def delete(self, key: str, *, suppress=False) -> None:
if self.config is None:
raise ValueError('attempt to use a closed config')