You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
648 B
26 lines
648 B
4 years ago
|
from typing import Any, Mapping, MutableMapping
|
||
4 years ago
|
|
||
4 years ago
|
_config: MutableMapping[str, Any] = {}
|
||
4 years ago
|
|
||
4 years ago
|
def change(new):
|
||
|
_config.clear()
|
||
|
_config.update(new)
|
||
4 years ago
|
|
||
4 years ago
|
def get(*keys: str, default: Any = None, cursor: Mapping = None):
|
||
|
''' Get configuration value. If multple keys are specified, traverse the
|
||
|
configuration to retrieve the value. If no value was found, return
|
||
|
None. '''
|
||
4 years ago
|
|
||
4 years ago
|
if not cursor:
|
||
|
cursor = _config
|
||
4 years ago
|
|
||
4 years ago
|
first = keys[0]
|
||
|
rest = keys[1:]
|
||
4 years ago
|
|
||
4 years ago
|
value = cursor.get(first)
|
||
4 years ago
|
|
||
4 years ago
|
return (get(rest, default=default, cursor=value)
|
||
|
if value is not None and rest else value)
|
||
4 years ago
|
|
||
|
def reference():
|
||
|
return _config
|