Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 4d60d30..2698f60

2698f60 refactor: reset state on read method call

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 2698f600e4bef3197d696a798f2c3436dabe836a
This commit is contained in:
dw-0
2024-06-19 20:06:45 +02:00
parent c6cc3fc0f6
commit 08640e5b17

View File

@@ -111,7 +111,13 @@ class SimpleConfigParser:
self.in_option_block: bool = False # whether we are in a multiline option block
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:
with open(file, "r") as f:
@@ -120,6 +126,16 @@ class SimpleConfigParser:
except OSError:
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):
"""Write the internal state to the given file"""