From 71da17fa45efce51196f0313e0739dd278506387 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Thu, 10 Dec 2020 11:35:26 -0500 Subject: [PATCH] Enhance Config Variable Validation --- fHDHR/config/__init__.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/fHDHR/config/__init__.py b/fHDHR/config/__init__.py index 3891d66..38e52c0 100644 --- a/fHDHR/config/__init__.py +++ b/fHDHR/config/__init__.py @@ -215,6 +215,22 @@ class Config(): self.dict[each_section.lower()][each_key.lower()] = each_val def write(self, section, key, value): + + if not value: + value = None + if value.lower() in ["none"]: + value = None + elif value.lower() in ["false"]: + value = False + elif value.lower() in ["true"]: + value = True + elif isint(value): + value = int(value) + elif isfloat(value): + value = float(value) + elif isinstance(value, list): + ",".join(value) + if section == self.dict["main"]["dictpopname"]: self.dict["origin"][key] = value else: @@ -226,7 +242,7 @@ class Config(): if not config_handler.has_section(section): config_handler.add_section(section) - config_handler.set(section, key, value) + config_handler.set(section, key, str(value)) with open(self.config_file, 'w') as config_file: config_handler.write(config_file)