(self, cfg_dict=None, cfg_text=None, filename=None)
| 201 | return cfg |
| 202 | |
| 203 | def __init__(self, cfg_dict=None, cfg_text=None, filename=None): |
| 204 | if cfg_dict is None: |
| 205 | cfg_dict = dict() |
| 206 | elif not isinstance(cfg_dict, dict): |
| 207 | raise TypeError('cfg_dict must be a dict, but ' |
| 208 | f'got {type(cfg_dict)}') |
| 209 | for key in cfg_dict: |
| 210 | if key in RESERVED_KEYS: |
| 211 | raise KeyError(f'{key} is reserved for config file') |
| 212 | |
| 213 | if isinstance(filename, Path): |
| 214 | filename = str(filename) |
| 215 | |
| 216 | super(Config, self).__setattr__('_cfg_dict', ConfigDict(cfg_dict)) |
| 217 | super(Config, self).__setattr__('_filename', filename) |
| 218 | if cfg_text: |
| 219 | text = cfg_text |
| 220 | elif filename: |
| 221 | with open(filename, 'r', encoding='utf-8') as f: |
| 222 | text = f.read() |
| 223 | else: |
| 224 | text = '' |
| 225 | super(Config, self).__setattr__('_text', text) |
| 226 | |
| 227 | @property |
| 228 | def filename(self): |
nothing calls this directly
no test coverage detected