Extracted JsonClass into own file

master
Felix Stupp 4 years ago
parent 52a18e7ee9
commit 172217471d
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -0,0 +1,16 @@
class JsonClass:
@classmethod
def getClassKey(cls, jsonKey):
for key, val in cls.TRANS.items():
if val == jsonKey or (key == jsonKey and val == True):
return key
return None
@classmethod
def getJsonKey(cls, classKey):
val = cls.TRANS.get(classKey, None)
return classKey if val == True else val
@classmethod
def fromJson(cls, dataDict):
return cls(**{cls.getClassKey(key): val for key, val in dataDict.items() if cls.getClassKey(key) is not None and val is not None})
def toJson(self):
return {self.__class__.getJsonKey(key): val for key, val in self.__dict__.items() if self.__class__.getJsonKey(key) is not None and val is not None}

@ -4,27 +4,7 @@ import atexit
import http.client
import json
class JsonClass:
TRANS_EXP = {
"same_key": True,
"class_key": "json_key",
"ignore_class_key": None,
}
@classmethod
def getClassKey(cls, jsonKey):
for key, val in cls.TRANS.items():
if val == jsonKey or (key == jsonKey and val == True):
return key
return None
@classmethod
def getJsonKey(cls, classKey):
val = cls.TRANS.get(classKey, None)
return classKey if val == True else val
@classmethod
def fromJson(cls, dataDict):
return cls(**{cls.getClassKey(key): val for key, val in dataDict.items() if cls.getClassKey(key) is not None and val is not None})
def toJson(self):
return {self.__class__.getJsonKey(key): val for key, val in self.__dict__.items() if self.__class__.getJsonKey(key) is not None and val is not None}
from .JsonClass import JsonClass
# Class Invalid
class TtRssCounters:

Loading…
Cancel
Save