-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsettings.py
60 lines (44 loc) · 1.56 KB
/
settings.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import json
import collections.abc
class Settings(collections.abc.MutableMapping):
def __init__(self, file_name: 'str' = 'settings.json'):
"""
Выполняет инициализацию класса для работы с настройками
:param file_name: путь к файлу с настройками
"""
with open(file_name) as settings_file:
self.__settings = json.load(settings_file)
def __delitem__(self, key):
"""
Удалять из настроек запрещено
:param key:
:return: None
"""
del self.__settings[key]
def __setitem__(self, key, value):
"""
Изменять настройки запрещено
:param key:
:param value:
:return: None
"""
self.__settings[key] = value
def __iter__(self):
"""
Возвращает итератор на настройки
:return: Iterator
"""
return iter(self.__settings)
def __getitem__(self, key):
"""
Возвращает элемент настроек
:param key: Название ключа настроек
:return: Настройка
"""
return self.__settings[key]
def __len__(self):
"""
Возвращает длину словаря с настройками
:return: Длина словаря
"""
return len(self.__settings)