You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
707 B
Python

6 years ago
import datetime as dt
from decimal import Decimal
from typing import Any
from molten import JSONRenderer, is_schema, dump_schema
class ExtJSONRender(JSONRenderer):
"""JSON Render with support for ISO 8601 datetime format strings"""
def default(self, ob: Any) -> Any:
"""You may override this when subclassing the JSON renderer in
order to encode non-standard object types.
"""
if is_schema(type(ob)):
return dump_schema(ob)
if isinstance(ob, dt.datetime):
return ob.isoformat()
if isinstance(ob, Decimal):
return float(ob)
raise TypeError(f"cannot encode values of type {type(ob)}") # pragma: no cover