[base-storage] Priorité
This commit is contained in:
parent
4511e4cdf7
commit
7a34e57a2d
@ -14,12 +14,12 @@ class Encoder(json.JSONEncoder):
|
|||||||
self.custom.update({type_: (encode, decode)})
|
self.custom.update({type_: (encode, decode)})
|
||||||
|
|
||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
|
if isinstance(obj, tuple(self.custom.keys())):
|
||||||
|
return {data_type: f'{type(obj)}', content: self.custom[type(obj)][0](obj)}
|
||||||
if isinstance(obj, (datetime.datetime)):
|
if isinstance(obj, (datetime.datetime)):
|
||||||
return {data_type: 'datetime.datetime', 'iso': obj.isoformat()}
|
return {data_type: 'datetime.datetime', 'iso': obj.isoformat()}
|
||||||
if isinstance(obj, (datetime.timedelta)):
|
if isinstance(obj, (datetime.timedelta)):
|
||||||
return {data_type: 'datetime.timedelta', 'totalseconds': obj.total_seconds()}
|
return {data_type: 'datetime.timedelta', 'totalseconds': obj.total_seconds()}
|
||||||
if isinstance(obj, tuple(self.custom.keys())):
|
|
||||||
return {data_type: f'{type(obj)}', content: self.custom[type(obj)][0](obj)}
|
|
||||||
return json.JSONEncoder.default(self, obj)
|
return json.JSONEncoder.default(self, obj)
|
||||||
|
|
||||||
def hook(self, dct):
|
def hook(self, dct):
|
||||||
|
Loading…
Reference in New Issue
Block a user