-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path__init__.py
More file actions
26 lines (21 loc) · 795 Bytes
/
__init__.py
File metadata and controls
26 lines (21 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import configparser
from collections import abc
from typing import Any
from config.common.files import FileConfigurationSource
def _develop_configparser_values(parser):
values = {}
for section_name in parser.sections():
section_values = {}
for key, value in parser[section_name].items():
section_values[key] = (
_develop_configparser_values(value)
if isinstance(value, abc.Mapping)
else value
)
values[section_name] = section_values
return values
class INIFile(FileConfigurationSource):
def read_source(self) -> dict[str, Any]:
parser = configparser.ConfigParser()
parser.read(self.file_path, encoding="utf8")
return _develop_configparser_values(parser)