-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathjson.py
More file actions
30 lines (21 loc) · 787 Bytes
/
json.py
File metadata and controls
30 lines (21 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Flask-Security JSON extensions.
:copyright: (c) 2022-2024 by J. Christopher Wagner (jwag).
:license: MIT, see LICENSE for more details.
Pieces of this code liberally copied from flask-mongoengine.
"""
def _use_provider(superclass):
"""Flask 2.2 onwards - customize JSONProvider"""
class FSJsonProvider(superclass):
@staticmethod
def default(obj):
from .babel import is_lazy_string
if is_lazy_string(obj):
return str(obj)
return super(FSJsonProvider, FSJsonProvider).default(obj)
return FSJsonProvider
def setup_json(app, bp=None):
# Called at init_app time.
# Flask >= 2.2
app.json_provider_class = _use_provider(app.json_provider_class)
app.json = app.json_provider_class(app)