Add support for applying mutability on all sections of an INI configuration

This commit is contained in:
2026-03-15 23:37:05 +01:00
parent e8e5bddf51
commit da2e102343
4 changed files with 45 additions and 7 deletions
+11 -5
View File
@@ -57,10 +57,10 @@ class INIConfiguration(Configuration):
configuration = cls()
for section_name, content in parse_ini(data, comment_prefixes=comment_prefixes, quotation_marks=quotation_marks, ignore_errors=ignore_errors).items():
group = INIConfigurationSection(section_name)
section = INIConfigurationSection(section_name)
for key, value in content.items():
group[key] = value
configuration[section_name] = group
section[key] = value
configuration[section_name] = section
if default is not None:
for section in default._config:
@@ -70,6 +70,10 @@ class INIConfiguration(Configuration):
if propk not in dict(configuration[section]).keys():
configuration[section][propk] = propv
for section in configuration._config.values():
if isinstance(section, INIConfigurationSection):
set_mutability(section, mutable)
set_mutability(configuration, mutable)
return configuration
@@ -88,14 +92,16 @@ class INIConfiguration(Configuration):
return serialize_ini(self._config, separator)
class INIConfigurationSection(INIConfiguration):
def __init__(self, name: str):
def __init__(self, name: str, mutable: bool = True):
'''
A class representing a group in an INI configuration.
:param name: The name of the group.
:type name: str
:param mutable: The mutability of the section
:type mutable: bool
'''
super().__init__()
super().__init__(mutable = mutable)
self._name = name
@property