Skip to content
Myr

Cleanup jsonify() function

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

Cleanup some leftover stuff from #1671. PEP8 spacing, args/kwargs don't need to be converted to list/dict, and Sphinx formatting.

authored by Jeff Widman · committed by Jeff Widman · parent f267191 · Browse files · 2 files+7 added−9 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+7 added−9 removed

  • other:+7 added−9 removed

2 files+7 added−9 removed

modified:flask/json.py+6 added-8 removed
209 unmodified lines
210 from :func:`dumps`:211212 1. Single argument: Passed straight through to :func:`dumps`.213 2. Multiple arguments: Converted to an array before being passed to214 :func:`dumps`.214 :func:`dumps`.215 3. Multiple keyword arguments: Converted to a dict before being passed to216 :func:`dumps`.216 :func:`dumps`.217 4. Both args and kwargs: Behavior undefined and will throw an exception.218219 Example usage::220
15 unmodified lines
236237238 .. versionchanged:: 1.0239 Added support for serializing top-level arrays. This introduces a240 security risk in ancient browsers. See :ref:`json_security` for details.240 security risk in ancient browsers. See :ref:`json-security` for details.241242 This function's response will be pretty printed if it was not requested243 with ``X-Requested-With: XMLHttpRequest`` to simplify debugging unless244 the ``JSONIFY_PRETTYPRINT_REGULAR`` config parameter is set to false.
14 unmodified lines
259 if args and kwargs:260 raise TypeError(261 "jsonify() behavior undefined when passed both args and kwargs"262 )263 elif len(args) == 1: # single args are passed directly to dumps()263 elif len(args) == 1: # single args are passed directly to dumps()264 data = args[0]265 elif args: # convert multiple args into an array266 data = list(args)267 else: # convert kwargs to a dict268 data = dict(kwargs)265 else:266 data = args or kwargs267268 # Note that we add '\n' to end of response269 # (see https://github.com/mitsuhiko/flask/pull/1262)270 rv = current_app.response_class(
7 unmodified lines
modified:CHANGES+1 added-1 removed
8 unmodified lines
9(release date to be announced, codename to be selected)1011- Added support to serializing top-level arrays to :func:`flask.jsonify`. This12 introduces a security risk in ancient browsers. See13 :ref:`json_security` for details.13 :ref:`json-security` for details.14- Added before_render_template signal.15- Added `**kwargs` to :meth:`flask.Test.test_client` to support passing16 additional keyword arguments to the constructor of17 :attr:`flask.Flask.test_client_class`.
542 unmodified lines