Skip to content
Myr

Merge remote branch 'njl/master'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Conflicts: docs/quickstart.rst

authored by Ron DuPlain · committed by Ron DuPlain · parents d626787, 68f9363 · Browse files · 2 files+36 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+36 added−0 removed

  • other:+36 added−0 removed

2 files+36 added−0 removed

modified:flask/testsuite/helpers.py+14 added
59 unmodified lines
60 return flask.jsonify(**d)61 @app.route('/dict')62 def return_dict():63 return flask.jsonify(d)64 @app.route("/padded")65 def return_padded_json():66 return flask.jsonify(d, padded=True)67 @app.route("/padded_custom")68 def return_padded_json_custom_callback():69 return flask.jsonify(d, padded='my_func_name')70 c = app.test_client()71 for url in '/kw', '/dict':72 rv = c.get(url)73 self.assert_equal(rv.mimetype, 'application/json')74 self.assert_equal(flask.json.loads(rv.data), d)75 for get_arg in 'callback=funcName', 'jsonp=funcName':76 rv = c.get('/padded?' + get_arg)77 self.assert_( rv.data.startswith("funcName(") )78 self.assert_( rv.data.endswith(")") )79 rv_json = rv.data.split('(')[1].split(')')[0]80 self.assert_equal(flask.json.loads(rv_json), d)81 rv = c.get('/padded_custom?my_func_name=funcName')82 self.assert_( rv.data.startswith("funcName(") )8384 def test_json_attr(self):85 app = flask.Flask(__name__)86 @app.route('/add', methods=['POST'])
314 unmodified lines
modified:flask/helpers.py+22 added
115 unmodified lines
116 security reasons only objects are supported toplevel. For more117 information about this, have a look at :ref:`json-security`.118119 .. versionadded:: 0.2120121 .. versionadded:: 0.9122 If the ``padded`` argument is true, the JSON object will be padded123 for JSONP calls and the response mimetype will be changed to 124 ``application/javascript``. By default, the request arguments ``callback``125 and ``jsonp`` will be used as the name for the callback function.126 This will work with jQuery and most other JavaScript libraries127 by default.128129 If the ``padded`` argument is a string, jsonify will look for130 the request argument with the same name and use that value as the131 callback-function name.132 """133 if __debug__:134 _assert_have_json()135 if 'padded' in kwargs:136 if isinstance(kwargs['padded'], str):137 callback = request.args.get(kwargs['padded']) or 'jsonp'138 else:139 callback = request.args.get('callback') or \140 request.args.get('jsonp') or 'jsonp'141 del kwargs['padded']142 json_str = json.dumps(dict(*args, **kwargs), indent=None)143 content = str(callback) + "(" + json_str + ")"144 return current_app.response_class(content, mimetype='application/javascript')145 return current_app.response_class(json.dumps(dict(*args, **kwargs),146 indent=None if request.is_xhr else 2), mimetype='application/json')147148
587 unmodified lines