-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.py
53 lines (45 loc) · 1.49 KB
/
config.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
from lemon.exception import LemonConfigKeyError
class LemonConfig:
def __init__(self, default_config: dict = None, config: dict = None) -> None:
"""
:param default_config: default app config
:param config: app config
"""
self._default_config = default_config or {}
self._config = config or {}
def set_config(self, config: dict):
"""
:param config: app config
"""
self._config = config or {}
def __getattr__(self, key: str):
if key.startswith('_'):
return self.__getattribute__(key)
return self.__getitem__(key)
def __getitem__(self, key: str):
try:
return self._config[key]
except KeyError:
try:
return self._default_config[key]
except KeyError:
raise LemonConfigKeyError
GLOBAL_CONFIG = {
# SERVER
'LEMON_SERVER_HOST': '127.0.0.1',
'LEMON_SERVER_PORT': '9999',
'LEMON_DEBUG': False,
# ROUTER
'LEMON_ROUTER_SLASH_SENSITIVE': False,
# CORS
'LEMON_CORS_ENABLE': False,
'LEMON_CORS_ALLOW_METHODS': ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH'],
'LEMON_CORS_ALLOW_HEADERS': [],
'LEMON_CORS_ORIGIN_ALLOW_ALL': False,
'LEMON_CORS_EXPOSE_HEADERS': [],
'LEMON_CORS_ALLOW_CREDENTIALS': False,
'LEMON_CORS_ORIGIN_WHITELIST': [],
'LEMON_CORS_ORIGIN_REGEX_WHITELIST': [],
'LEMON_CORS_MAX_AGE': 86400,
}
settings = LemonConfig(default_config=GLOBAL_CONFIG)