From 05e5948d3f2a24713fd607c9c452d0f054f36f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=92=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=B8=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 18 Feb 2016 00:16:44 +0300 Subject: [PATCH] settings inherit from dict --- src/settings.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/settings.py b/src/settings.py index ef68c4c..90d8ccc 100644 --- a/src/settings.py +++ b/src/settings.py @@ -3,20 +3,21 @@ import json import os -class Settings(object): +class Settings(dict): def __init__(self): self.path = Settings.get_default_path() + 'toxygen.json' if os.path.exists(self.path): with open(self.path) as fl: data = fl.read() - self.data = json.loads(data) + super(self.__class__, self).__init__(json.loads(data)) else: - self.create_default_settings() + super(self.__class__, self).__init__(Settings.get_default_settings()) self.save() - def create_default_settings(self): - self.data = { + @staticmethod + def get_default_settings(): + return { "theme": "default", "ipv6_enabled": True, "udp_enabled": True, @@ -37,14 +38,8 @@ class Settings(object): "typing_notifications": True } - def __get__(self, attr): - return self.data[attr] - - def __set__(self, attr, value): - self.data[attr] = value - def save(self): - text = json.dumps(self.data) + text = json.dumps(self) with open(self.path, 'w') as fl: fl.write(text)