kopia lustrzana https://github.com/inkstitch/inkstitch
fix flask json deprecation
rodzic
7d57a22f01
commit
36f0946e2d
|
@ -14,7 +14,7 @@ import requests
|
||||||
from flask import Flask, g
|
from flask import Flask, g
|
||||||
from werkzeug.serving import make_server
|
from werkzeug.serving import make_server
|
||||||
|
|
||||||
from ..utils.json import InkStitchJSONEncoder
|
from ..utils.json import InkStitchJSONProvider
|
||||||
from .install import install
|
from .install import install
|
||||||
from .simulator import simulator
|
from .simulator import simulator
|
||||||
from .stitch_plan import stitch_plan
|
from .stitch_plan import stitch_plan
|
||||||
|
@ -41,7 +41,7 @@ class APIServer(Thread):
|
||||||
cli.show_server_banner = lambda *x: None
|
cli.show_server_banner = lambda *x: None
|
||||||
|
|
||||||
self.app = Flask(__name__)
|
self.app = Flask(__name__)
|
||||||
self.app.json_encoder = InkStitchJSONEncoder
|
self.app.json = InkStitchJSONProvider(self.app)
|
||||||
|
|
||||||
self.app.register_blueprint(simulator, url_prefix="/simulator")
|
self.app.register_blueprint(simulator, url_prefix="/simulator")
|
||||||
self.app.register_blueprint(stitch_plan, url_prefix="/stitch_plan")
|
self.app.register_blueprint(stitch_plan, url_prefix="/stitch_plan")
|
||||||
|
|
|
@ -3,10 +3,15 @@
|
||||||
# Copyright (c) 2010 Authors
|
# Copyright (c) 2010 Authors
|
||||||
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
||||||
|
|
||||||
from flask.json import JSONEncoder
|
from flask.json.provider import DefaultJSONProvider
|
||||||
|
from ..exceptions import InkstitchException
|
||||||
|
|
||||||
|
|
||||||
class InkStitchJSONEncoder(JSONEncoder):
|
class InkstitchJSONException(InkstitchException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class InkStitchJSONProvider(DefaultJSONProvider):
|
||||||
"""JSON encoder class that runs __json__ on an object if available.
|
"""JSON encoder class that runs __json__ on an object if available.
|
||||||
|
|
||||||
The __json__ method should return a JSON-compatible representation of the
|
The __json__ method should return a JSON-compatible representation of the
|
||||||
|
@ -17,4 +22,5 @@ class InkStitchJSONEncoder(JSONEncoder):
|
||||||
try:
|
try:
|
||||||
return obj.__json__()
|
return obj.__json__()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return JSONEncoder.default(self, obj)
|
raise InkstitchJSONException(
|
||||||
|
f"Object of type {obj.__class__.__name__} cannot be serialized to JSON because it does not implement __json__()")
|
||||||
|
|
|
@ -22,7 +22,7 @@ colormath @ git+https://github.com/gtaylor/python-colormath.git@4a076831fd5136f6
|
||||||
|
|
||||||
stringcase
|
stringcase
|
||||||
tinycss2
|
tinycss2
|
||||||
flask
|
flask>=2.2.0
|
||||||
fonttools
|
fonttools
|
||||||
trimesh>=3.15.2
|
trimesh>=3.15.2
|
||||||
scipy
|
scipy
|
||||||
|
|
Ładowanie…
Reference in New Issue