[6f9c00]: / settings.py

Download this file

29 lines (21 with data), 747 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
27
28
import ast
import configparser
from collections.abc import Mapping
class Settings(Mapping):
def __init__(self, setting_file='settings.ini'):
config = configparser.ConfigParser()
config.read(setting_file)
self.settings_dict = _parse_values(config)
def __getitem__(self, key):
return self.settings_dict[key]
def __len__(self):
return len(self.settings_dict)
def __iter__(self):
return self.settings_dict.items()
def _parse_values(config):
config_parsed = {}
for section in config.sections():
config_parsed[section] = {}
for key, value in config[section].items():
config_parsed[section][key] = ast.literal_eval(value)
return config_parsed