An ebook/comic library service and web client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

26 lines
571 B

"""
Utility classes for Atheneum
"""
from datetime import date
from typing import Any
import rfc3339
from flask.json import JSONEncoder
class CustomJSONEncoder(JSONEncoder):
"""
Ensure that datetime values are serialized correctly
"""
def default(self, o: Any) -> Any: # pylint: disable=E0202
try:
if isinstance(o, date):
return rfc3339.format(o)
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
return JSONEncoder.default(self, o)