Skip to content

Commit c3d38a2

Browse files
committed
Removed json_available hack
1 parent 3f82d1b commit c3d38a2

File tree

3 files changed

+8
-33
lines changed

3 files changed

+8
-33
lines changed

flask/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from .app import Flask, Request, Response
2222
from .config import Config
23-
from .helpers import url_for, jsonify, json_available, flash, \
23+
from .helpers import url_for, jsonify, flash, \
2424
send_file, send_from_directory, get_flashed_messages, \
2525
get_template_attribute, make_response, safe_join, \
2626
stream_with_context
@@ -37,8 +37,8 @@
3737
request_finished, got_request_exception, request_tearing_down
3838

3939
# only import json if it's available
40-
if json_available:
41-
from .helpers import json
40+
from .helpers import json
4241

4342
# backwards compat, goes away in 1.0
4443
from .sessions import SecureCookieSession as Session
44+
json_available = True

flask/helpers.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,9 @@
2323
from werkzeug.urls import url_quote
2424
from functools import update_wrapper
2525

26-
# try to load the best simplejson implementation available. If JSON
27-
# is not installed, we add a failing class.
28-
json_available = True
29-
json = None
30-
try:
31-
import simplejson as json
32-
except ImportError:
33-
try:
34-
import json
35-
except ImportError:
36-
try:
37-
# Google Appengine offers simplejson via django
38-
from django.utils import simplejson as json
39-
except ImportError:
40-
json_available = False
26+
# Use the same json implementation as itsdangerous on which we
27+
# depend anyways.
28+
from itsdangerous import simplejson as json
4129

4230

4331
from werkzeug.datastructures import Headers
@@ -55,19 +43,10 @@
5543
current_app, request
5644

5745

58-
def _assert_have_json():
59-
"""Helper function that fails if JSON is unavailable."""
60-
if not json_available:
61-
raise RuntimeError('simplejson not installed')
62-
63-
6446
# figure out if simplejson escapes slashes. This behavior was changed
6547
# from one version to another without reason.
66-
if not json_available or '\\/' not in json.dumps('/'):
67-
48+
if '\\/' not in json.dumps('/'):
6849
def _tojson_filter(*args, **kwargs):
69-
if __debug__:
70-
_assert_have_json()
7150
return json.dumps(*args, **kwargs).replace('/', '\\/')
7251
else:
7352
_tojson_filter = json.dumps
@@ -192,8 +171,6 @@ def get_current_user():
192171
193172
.. versionadded:: 0.2
194173
"""
195-
if __debug__:
196-
_assert_have_json()
197174
return current_app.response_class(json.dumps(dict(*args, **kwargs),
198175
indent=None if request.is_xhr else 2), mimetype='application/json')
199176

flask/wrappers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from .exceptions import JSONBadRequest
1616
from .debughelpers import attach_enctype_error_multidict
17-
from .helpers import json, _assert_have_json
17+
from .helpers import json
1818
from .globals import _request_ctx_stack
1919

2020

@@ -95,8 +95,6 @@ def json(self):
9595
9696
This requires Python 2.6 or an installed version of simplejson.
9797
"""
98-
if __debug__:
99-
_assert_have_json()
10098
if self.mimetype == 'application/json':
10199
request_charset = self.mimetype_params.get('charset')
102100
try:

0 commit comments

Comments
 (0)