Add (de-)serialization of set objects in sessions

This commit is contained in:
Guewen Baconnier
2020-05-26 11:39:39 +02:00
parent 2a022ba537
commit 2c5805e858
+4
View File
@@ -19,6 +19,8 @@ class SessionEncoder(json.JSONEncoder):
return {"_type": "datetime_isoformat", "value": obj.isoformat()} return {"_type": "datetime_isoformat", "value": obj.isoformat()}
elif isinstance(obj, date): elif isinstance(obj, date):
return {"_type": "date_isoformat", "value": obj.isoformat()} return {"_type": "date_isoformat", "value": obj.isoformat()}
elif isinstance(obj, set):
return {"_type": "set", "value": tuple(obj)}
return json.JSONEncoder.default(self, obj) return json.JSONEncoder.default(self, obj)
@@ -36,4 +38,6 @@ class SessionDecoder(json.JSONDecoder):
return dateutil.parser.parse(obj["value"]) return dateutil.parser.parse(obj["value"])
elif type_ == "date_isoformat": elif type_ == "date_isoformat":
return dateutil.parser.parse(obj["value"]).date() return dateutil.parser.parse(obj["value"]).date()
elif type_ == "set":
return set(obj["value"])
return obj return obj