inkstitch/lib/utils/json.py

21 wiersze
551 B
Python
Czysty Zwykły widok Historia

2021-03-12 04:17:19 +00:00
# Authors: see git history
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
2020-04-28 16:34:05 +00:00
from flask.json import JSONEncoder
class InkStitchJSONEncoder(JSONEncoder):
"""JSON encoder class that runs __json__ on an object if available.
The __json__ method should return a JSON-compatible representation of the
object.
"""
def default(self, obj):
try:
return obj.__json__()
except AttributeError:
return JSONEncoder.default(self, obj)