forked from orbit-oss/flask
Removed json_available hack
This commit is contained in:
parent
3f82d1b68e
commit
c3d38a21c6
3 changed files with 8 additions and 33 deletions
|
|
@ -20,7 +20,7 @@ from jinja2 import Markup, escape
|
||||||
|
|
||||||
from .app import Flask, Request, Response
|
from .app import Flask, Request, Response
|
||||||
from .config import Config
|
from .config import Config
|
||||||
from .helpers import url_for, jsonify, json_available, flash, \
|
from .helpers import url_for, jsonify, flash, \
|
||||||
send_file, send_from_directory, get_flashed_messages, \
|
send_file, send_from_directory, get_flashed_messages, \
|
||||||
get_template_attribute, make_response, safe_join, \
|
get_template_attribute, make_response, safe_join, \
|
||||||
stream_with_context
|
stream_with_context
|
||||||
|
|
@ -37,8 +37,8 @@ from .signals import signals_available, template_rendered, request_started, \
|
||||||
request_finished, got_request_exception, request_tearing_down
|
request_finished, got_request_exception, request_tearing_down
|
||||||
|
|
||||||
# only import json if it's available
|
# only import json if it's available
|
||||||
if json_available:
|
from .helpers import json
|
||||||
from .helpers import json
|
|
||||||
|
|
||||||
# backwards compat, goes away in 1.0
|
# backwards compat, goes away in 1.0
|
||||||
from .sessions import SecureCookieSession as Session
|
from .sessions import SecureCookieSession as Session
|
||||||
|
json_available = True
|
||||||
|
|
|
||||||
|
|
@ -23,21 +23,9 @@ from werkzeug.routing import BuildError
|
||||||
from werkzeug.urls import url_quote
|
from werkzeug.urls import url_quote
|
||||||
from functools import update_wrapper
|
from functools import update_wrapper
|
||||||
|
|
||||||
# try to load the best simplejson implementation available. If JSON
|
# Use the same json implementation as itsdangerous on which we
|
||||||
# is not installed, we add a failing class.
|
# depend anyways.
|
||||||
json_available = True
|
from itsdangerous import simplejson as json
|
||||||
json = None
|
|
||||||
try:
|
|
||||||
import simplejson as json
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
import json
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
# Google Appengine offers simplejson via django
|
|
||||||
from django.utils import simplejson as json
|
|
||||||
except ImportError:
|
|
||||||
json_available = False
|
|
||||||
|
|
||||||
|
|
||||||
from werkzeug.datastructures import Headers
|
from werkzeug.datastructures import Headers
|
||||||
|
|
@ -55,19 +43,10 @@ from .globals import session, _request_ctx_stack, _app_ctx_stack, \
|
||||||
current_app, request
|
current_app, request
|
||||||
|
|
||||||
|
|
||||||
def _assert_have_json():
|
|
||||||
"""Helper function that fails if JSON is unavailable."""
|
|
||||||
if not json_available:
|
|
||||||
raise RuntimeError('simplejson not installed')
|
|
||||||
|
|
||||||
|
|
||||||
# figure out if simplejson escapes slashes. This behavior was changed
|
# figure out if simplejson escapes slashes. This behavior was changed
|
||||||
# from one version to another without reason.
|
# from one version to another without reason.
|
||||||
if not json_available or '\\/' not in json.dumps('/'):
|
if '\\/' not in json.dumps('/'):
|
||||||
|
|
||||||
def _tojson_filter(*args, **kwargs):
|
def _tojson_filter(*args, **kwargs):
|
||||||
if __debug__:
|
|
||||||
_assert_have_json()
|
|
||||||
return json.dumps(*args, **kwargs).replace('/', '\\/')
|
return json.dumps(*args, **kwargs).replace('/', '\\/')
|
||||||
else:
|
else:
|
||||||
_tojson_filter = json.dumps
|
_tojson_filter = json.dumps
|
||||||
|
|
@ -192,8 +171,6 @@ def jsonify(*args, **kwargs):
|
||||||
|
|
||||||
.. versionadded:: 0.2
|
.. versionadded:: 0.2
|
||||||
"""
|
"""
|
||||||
if __debug__:
|
|
||||||
_assert_have_json()
|
|
||||||
return current_app.response_class(json.dumps(dict(*args, **kwargs),
|
return current_app.response_class(json.dumps(dict(*args, **kwargs),
|
||||||
indent=None if request.is_xhr else 2), mimetype='application/json')
|
indent=None if request.is_xhr else 2), mimetype='application/json')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ from werkzeug.utils import cached_property
|
||||||
|
|
||||||
from .exceptions import JSONBadRequest
|
from .exceptions import JSONBadRequest
|
||||||
from .debughelpers import attach_enctype_error_multidict
|
from .debughelpers import attach_enctype_error_multidict
|
||||||
from .helpers import json, _assert_have_json
|
from .helpers import json
|
||||||
from .globals import _request_ctx_stack
|
from .globals import _request_ctx_stack
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -95,8 +95,6 @@ class Request(RequestBase):
|
||||||
|
|
||||||
This requires Python 2.6 or an installed version of simplejson.
|
This requires Python 2.6 or an installed version of simplejson.
|
||||||
"""
|
"""
|
||||||
if __debug__:
|
|
||||||
_assert_have_json()
|
|
||||||
if self.mimetype == 'application/json':
|
if self.mimetype == 'application/json':
|
||||||
request_charset = self.mimetype_params.get('charset')
|
request_charset = self.mimetype_params.get('charset')
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue