activitypub/activitypub/json.py

18 wiersze
483 B
Python
Czysty Zwykły widok Historia

2018-07-27 02:30:47 +00:00
import json
2018-07-27 13:07:41 +00:00
from .bson import ObjectId
2018-07-27 02:30:47 +00:00
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, ObjectId):
return {"$oid": str(o)}
return super().default(o)
class JSONDecoder(json.JSONDecoder):
def __init__(self, *args, **kwargs):
super().__init__(object_hook=self.object_hook, *args, **kwargs)
def object_hook(self, obj):
if '$oid' not in obj:
return obj
return ObjectId(obj['$oid'])