confighelper: implement method to read a dictionary

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-03-02 10:45:08 -05:00
parent 790d77756e
commit 4a6732f13a
No known key found for this signature in database
GPG Key ID: 7027245FBBDDF59A
1 changed files with 11 additions and 0 deletions

View File

@ -371,6 +371,17 @@ class ConfigHelper:
return template.create_template(val.strip(), is_async)
return val
def read_supplemental_dict(self, obj: Dict[str, Any]) -> ConfigHelper:
if not obj:
raise ConfigError(f"Cannot ready Empty Dict")
try:
sup_cfg = configparser.ConfigParser(interpolation=None)
sup_cfg.read_dict(obj)
except Exception:
raise ConfigError("Error Reading Object")
sections = sup_cfg.sections()
return ConfigHelper(self.server, sup_cfg, sections[0], sections)
def read_supplemental_config(self, file_name: str) -> ConfigHelper:
cfg_file_path = os.path.normpath(os.path.expanduser(file_name))
if not os.path.isfile(cfg_file_path):