blob: 57fc9b0e430b92b09d9c556511d900beae4a908b (
about) (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import configparser, os, typing
class Config(object):
def __init__(self, location: str):
self.location = location
self._config = {} # type: typing.Dict[str, str]
self.load()
def load(self):
if os.path.isfile(self.location):
with open(self.location) as config_file:
parser = configparser.ConfigParser()
parser.read_string(config_file.read())
self._config = dict(parser["bot"].items())
def __getitem__(self, key: str) -> typing.Any:
return self._config[key]
def get(self, key: str, default: typing.Any=None) -> typing.Any:
return self._config.get(key, default)
def __contains__(self, key: str) -> bool:
return key in self._config
|