From 0ae5fd12d72883c890b09780e3912ba7185177f5 Mon Sep 17 00:00:00 2001 From: BluBb_mADe Date: Tue, 4 Jun 2019 18:38:50 +0200 Subject: [PATCH] moved AttrDict cast into static method --- sharex_server.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sharex_server.py b/sharex_server.py index fda9d6f..6cbdbfa 100644 --- a/sharex_server.py +++ b/sharex_server.py @@ -23,17 +23,17 @@ class AttrDict(dict): def __getattr__(self, item): return self.setdefault(item, AttrDict()) - -def cast_to_ad(d): - if not isinstance(d, AttrDict): - d = AttrDict(d) - for k, v in dict(d.items()).items(): - if " " in k: - del d[k] - d[k.replace(" ", "_")] = v - if isinstance(v, dict): - d[k] = cast_to_ad(v) - return d + @staticmethod + def from_dict_recur(d): + if not isinstance(d, AttrDict): + d = AttrDict(d) + for k, v in dict(d.items()).items(): + if " " in k: + del d[k] + d[k.replace(" ", "_")] = v + if isinstance(v, dict): + d[k] = AttrDict.from_dict_recur(v) + return d def sizeof_fmt(num, suffix='B'): @@ -155,7 +155,7 @@ if __name__ == '__main__': file_db = defaultdict(dict) confname = sys.argv[1] if sys.argv[1:] and os.path.isfile(sys.argv[1]) else 'config.yaml' with open(confname) as cf: - conf = cast_to_ad(yaml.load(cf)) + conf = AttrDict.from_dict_recur(yaml.load(cf)) if conf.url_hash_len > 31: raise ValueError('url_hash_len can\'t be bigger than 31') if not set(conf.max_filesize.replace(' ', ''))\