forked from orbit-oss/flask
Merge pull request #1898 from RaHus/per_blueprint_jsoncoding_#1710
Per blueprint jsoncoding #1710
This commit is contained in:
commit
74b3f7e04c
3 changed files with 53 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ import uuid
|
|||
from datetime import date
|
||||
from .globals import current_app, request
|
||||
from ._compat import text_type, PY2
|
||||
from .ctx import has_request_context
|
||||
|
||||
from werkzeug.http import http_date
|
||||
from jinja2 import Markup
|
||||
|
|
@ -91,7 +92,11 @@ class JSONDecoder(_json.JSONDecoder):
|
|||
def _dump_arg_defaults(kwargs):
|
||||
"""Inject default arguments for dump functions."""
|
||||
if current_app:
|
||||
kwargs.setdefault('cls', current_app.json_encoder)
|
||||
bp = current_app.blueprints.get(request.blueprint,
|
||||
None) if has_request_context() else None
|
||||
kwargs.setdefault('cls',
|
||||
bp.json_encoder if bp and bp.json_encoder
|
||||
else current_app.json_encoder)
|
||||
if not current_app.config['JSON_AS_ASCII']:
|
||||
kwargs.setdefault('ensure_ascii', False)
|
||||
kwargs.setdefault('sort_keys', current_app.config['JSON_SORT_KEYS'])
|
||||
|
|
@ -103,7 +108,11 @@ def _dump_arg_defaults(kwargs):
|
|||
def _load_arg_defaults(kwargs):
|
||||
"""Inject default arguments for load functions."""
|
||||
if current_app:
|
||||
kwargs.setdefault('cls', current_app.json_decoder)
|
||||
bp = current_app.blueprints.get(request.blueprint,
|
||||
None) if has_request_context() else None
|
||||
kwargs.setdefault('cls',
|
||||
bp.json_decoder if bp and bp.json_decoder
|
||||
else current_app.json_decoder)
|
||||
else:
|
||||
kwargs.setdefault('cls', JSONDecoder)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue