Merge commit '08640e5b177595f5e84d4bf9194311282b1a91e2' into kiauh-v6-dev

This commit is contained in:
dw-0
2024-06-19 20:06:45 +02:00

View File

@@ -111,7 +111,13 @@ class SimpleConfigParser:
self.in_option_block: bool = False # whether we are in a multiline option block self.in_option_block: bool = False # whether we are in a multiline option block
def read(self, file: Path) -> None: def read(self, file: Path) -> None:
"""Read the given file and store the result in the internal state""" """
Read the given file and store the result in the internal state.
Call this method before using any other methods. Calling this method
multiple times will reset the internal state on each call.
"""
self._reset_state()
try: try:
with open(file, "r") as f: with open(file, "r") as f:
@@ -120,6 +126,16 @@ class SimpleConfigParser:
except OSError: except OSError:
raise raise
def _reset_state(self):
"""Reset the internal state."""
self._config.clear()
self._header.clear()
self._all_sections.clear()
self._all_options.clear()
self.section_name = ""
self.in_option_block = False
def write(self, filename): def write(self, filename):
"""Write the internal state to the given file""" """Write the internal state to the given file"""