Skip to content

Commit

Permalink
Removed json_available hack
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Aug 11, 2012
1 parent 3f82d1b commit c3d38a2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
6 changes: 3 additions & 3 deletions flask/__init__.py
Expand Up @@ -20,7 +20,7 @@

from .app import Flask, Request, Response
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, \
get_template_attribute, make_response, safe_join, \
stream_with_context
Expand All @@ -37,8 +37,8 @@
request_finished, got_request_exception, request_tearing_down

# 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
from .sessions import SecureCookieSession as Session
json_available = True
31 changes: 4 additions & 27 deletions flask/helpers.py
Expand Up @@ -23,21 +23,9 @@
from werkzeug.urls import url_quote
from functools import update_wrapper

# try to load the best simplejson implementation available. If JSON
# is not installed, we add a failing class.
json_available = True
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
# Use the same json implementation as itsdangerous on which we
# depend anyways.
from itsdangerous import simplejson as json


from werkzeug.datastructures import Headers
Expand All @@ -55,19 +43,10 @@
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
# 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):
if __debug__:
_assert_have_json()
return json.dumps(*args, **kwargs).replace('/', '\\/')
else:
_tojson_filter = json.dumps
Expand Down Expand Up @@ -192,8 +171,6 @@ def get_current_user():
.. versionadded:: 0.2
"""
if __debug__:
_assert_have_json()
return current_app.response_class(json.dumps(dict(*args, **kwargs),
indent=None if request.is_xhr else 2), mimetype='application/json')

Expand Down
4 changes: 1 addition & 3 deletions flask/wrappers.py
Expand Up @@ -14,7 +14,7 @@

from .exceptions import JSONBadRequest
from .debughelpers import attach_enctype_error_multidict
from .helpers import json, _assert_have_json
from .helpers import json
from .globals import _request_ctx_stack


Expand Down Expand Up @@ -95,8 +95,6 @@ def json(self):
This requires Python 2.6 or an installed version of simplejson.
"""
if __debug__:
_assert_have_json()
if self.mimetype == 'application/json':
request_charset = self.mimetype_params.get('charset')
try:
Expand Down

0 comments on commit c3d38a2

Please sign in to comment.