diff --git a/kiauh/core/submodules/simple_config_parser/src/simple_config_parser/simple_config_parser.py b/kiauh/core/submodules/simple_config_parser/src/simple_config_parser/simple_config_parser.py index 38cf2d9..409161c 100644 --- a/kiauh/core/submodules/simple_config_parser/src/simple_config_parser/simple_config_parser.py +++ b/kiauh/core/submodules/simple_config_parser/src/simple_config_parser/simple_config_parser.py @@ -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"""