-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from flask import make_response, current_app | ||
from json import dumps | ||
|
||
from ..core.utilities import PY3 | ||
|
||
|
||
def output_json(data, code, headers=None): | ||
"""Makes a Flask response with a JSON encoded body""" | ||
|
||
settings = current_app.config.get("RESTFUL_JSON", {}) | ||
|
||
# If we're in debug mode, and the indent is not set, we set it to a | ||
# reasonable value here. Note that this won't override any existing value | ||
# that was set. We also set the "sort_keys" value. | ||
if current_app.debug: | ||
settings.setdefault("indent", 4) | ||
settings.setdefault("sort_keys", not PY3) | ||
|
||
# always end the json dumps with a new line | ||
# see https://github.com/mitsuhiko/flask/pull/1262 | ||
dumped = dumps(data, **settings) + "\n" | ||
|
||
resp = make_response(dumped, code) | ||
resp.headers.extend(headers or {}) | ||
return resp | ||
|
||
|
||
DEFAULT_REPRESENTATIONS = [("application/json", output_json)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters