Removed json_available hack
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent 3f82d1b · Browse files · 3 files·+8 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+8 added−33 removed
- other:+8 added−33 removed
Provenance
- Commit
c3d38a2- Tree
9cac7ad- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
3f82d1b
3 files changed+8 added−33 removed
modified:flask/__init__.py+3 added-3 removed
18 unmodified lines19 from jinja2 import Markup, escape20 21 from .app import Flask, Request, Response22 from .config import Config23-from .helpers import url_for, jsonify, json_available, flash, \23+from .helpers import url_for, jsonify, flash, \24 send_file, send_from_directory, get_flashed_messages, \25 get_template_attribute, make_response, safe_join, \26 stream_with_context27 from .globals import current_app, g, request, session, _request_ctx_stack, \8 unmodified lines36 from .signals import signals_available, template_rendered, request_started, \37 request_finished, got_request_exception, request_tearing_down38 39 # only import json if it's available40-if json_available:41- from .helpers import json40+from .helpers import json41 42 # backwards compat, goes away in 1.043 from .sessions import SecureCookieSession as Session44+json_available = Truemodified:flask/helpers.py+4 added-27 removed
21 unmodified lines22 from werkzeug.routing import BuildError23 from werkzeug.urls import url_quote24 from functools import update_wrapper25 26-# try to load the best simplejson implementation available. If JSON27-# is not installed, we add a failing class.28-json_available = True29-json = None30-try:31- import simplejson as json32-except ImportError:33- try:34- import json35- except ImportError:36- try:37- # Google Appengine offers simplejson via django38- from django.utils import simplejson as json39- except ImportError:40- json_available = False26+# Use the same json implementation as itsdangerous on which we27+# depend anyways.28+from itsdangerous import simplejson as json29 30 31 from werkzeug.datastructures import Headers32 from werkzeug.exceptions import NotFound9 unmodified lines42 from .globals import session, _request_ctx_stack, _app_ctx_stack, \43 current_app, request44 45 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-46 # figure out if simplejson escapes slashes. This behavior was changed47 # from one version to another without reason.66-if not json_available or '\\/' not in json.dumps('/'):67-48+if '\\/' not in json.dumps('/'):49 def _tojson_filter(*args, **kwargs):69- if __debug__:70- _assert_have_json()50 return json.dumps(*args, **kwargs).replace('/', '\\/')51 else:52 _tojson_filter = json.dumps53 116 unmodified lines170 information about this, have a look at :ref:`json-security`.171 172 .. versionadded:: 0.2173 """195- if __debug__:196- _assert_have_json()174 return current_app.response_class(json.dumps(dict(*args, **kwargs),175 indent=None if request.is_xhr else 2), mimetype='application/json')176 177 695 unmodified linesmodified:flask/wrappers.py+1 added-3 removed
12 unmodified lines13 from werkzeug.utils import cached_property14 15 from .exceptions import JSONBadRequest16 from .debughelpers import attach_enctype_error_multidict17-from .helpers import json, _assert_have_json17+from .helpers import json18 from .globals import _request_ctx_stack19 20 21 class Request(RequestBase):72 unmodified lines94 parsed JSON data. Otherwise this will be `None`.95 96 This requires Python 2.6 or an installed version of simplejson.97 """98- if __debug__:99- _assert_have_json()98 if self.mimetype == 'application/json':99 request_charset = self.mimetype_params.get('charset')100 try:101 if request_charset is not None:45 unmodified lines