Skip to content
Myr

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

3 files+8 added−33 removed

modified:flask/__init__.py+3 added-3 removed
18 unmodified lines
19from jinja2 import Markup, escape2021from .app import Flask, Request, Response22from .config import Config23from .helpers import url_for, jsonify, json_available, flash, \23from .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_context27from .globals import current_app, g, request, session, _request_ctx_stack, \
8 unmodified lines
36from .signals import signals_available, template_rendered, request_started, \37 request_finished, got_request_exception, request_tearing_down3839# only import json if it's available40if json_available:41 from .helpers import json40from .helpers import json4142# backwards compat, goes away in 1.043from .sessions import SecureCookieSession as Session44json_available = True
modified:flask/helpers.py+4 added-27 removed
21 unmodified lines
22from werkzeug.routing import BuildError23from werkzeug.urls import url_quote24from functools import update_wrapper2526# try to load the best simplejson implementation available. If JSON27# is not installed, we add a failing class.28json_available = True29json = None30try:31 import simplejson as json32except 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.28from itsdangerous import simplejson as json293031from werkzeug.datastructures import Headers32from werkzeug.exceptions import NotFound
9 unmodified lines
42from .globals import session, _request_ctx_stack, _app_ctx_stack, \43 current_app, request444558def _assert_have_json():59 """Helper function that fails if JSON is unavailable."""60 if not json_available:61 raise RuntimeError('simplejson not installed')626346# figure out if simplejson escapes slashes. This behavior was changed47# from one version to another without reason.66if not json_available or '\\/' not in json.dumps('/'):6748if '\\/' not in json.dumps('/'):49 def _tojson_filter(*args, **kwargs):69 if __debug__:70 _assert_have_json()50 return json.dumps(*args, **kwargs).replace('/', '\\/')51else:52 _tojson_filter = json.dumps53
116 unmodified lines
170 information about this, have a look at :ref:`json-security`.171172 .. 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')176177
695 unmodified lines
modified:flask/wrappers.py+1 added-3 removed
12 unmodified lines
13from werkzeug.utils import cached_property1415from .exceptions import JSONBadRequest16from .debughelpers import attach_enctype_error_multidict17from .helpers import json, _assert_have_json17from .helpers import json18from .globals import _request_ctx_stack192021class Request(RequestBase):
72 unmodified lines
94 parsed JSON data. Otherwise this will be `None`.9596 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