(self, cfg_dict=None, cfg_text=None, filename=None)
| 153 | return Config(cfg_dict, cfg_text=cfg_text, filename=filename) |
| 154 | |
| 155 | def __init__(self, cfg_dict=None, cfg_text=None, filename=None): |
| 156 | if cfg_dict is None: |
| 157 | cfg_dict = dict() |
| 158 | elif not isinstance(cfg_dict, dict): |
| 159 | raise TypeError('cfg_dict must be a dict, but ' |
| 160 | f'got {type(cfg_dict)}') |
| 161 | for key in cfg_dict: |
| 162 | if key in RESERVED_KEYS: |
| 163 | raise KeyError(f'{key} is reserved for config file') |
| 164 | |
| 165 | super(Config, self).__setattr__('_cfg_dict', ConfigDict(cfg_dict)) |
| 166 | super(Config, self).__setattr__('_filename', filename) |
| 167 | if cfg_text: |
| 168 | text = cfg_text |
| 169 | elif filename: |
| 170 | with open(filename, 'r') as f: |
| 171 | text = f.read() |
| 172 | else: |
| 173 | text = '' |
| 174 | super(Config, self).__setattr__('_text', text) |
| 175 | |
| 176 | @property |
| 177 | def filename(self): |
no test coverage detected