Skip to content

Commit

Permalink
Cleanup jsonify() function
Browse files Browse the repository at this point in the history
Cleanup some leftover stuff from pallets#1671. PEP8 spacing, args/kwargs don't need to be converted to list/dict, and Sphinx formatting.
  • Loading branch information
jeffwidman committed Jan 26, 2016
1 parent f267191 commit 0edf0a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Version 1.0

- Added support to serializing top-level arrays to :func:`flask.jsonify`. This
introduces a security risk in ancient browsers. See
:ref:`json_security` for details.
:ref:`json-security` for details.
- Added before_render_template signal.
- Added `**kwargs` to :meth:`flask.Test.test_client` to support passing
additional keyword arguments to the constructor of
Expand Down
14 changes: 6 additions & 8 deletions flask/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def jsonify(*args, **kwargs):
1. Single argument: Passed straight through to :func:`dumps`.
2. Multiple arguments: Converted to an array before being passed to
:func:`dumps`.
:func:`dumps`.
3. Multiple keyword arguments: Converted to a dict before being passed to
:func:`dumps`.
:func:`dumps`.
4. Both args and kwargs: Behavior undefined and will throw an exception.
Example usage::
Expand All @@ -237,7 +237,7 @@ def get_current_user():
.. versionchanged:: 1.0
Added support for serializing top-level arrays. This introduces a
security risk in ancient browsers. See :ref:`json_security` for details.
security risk in ancient browsers. See :ref:`json-security` for details.
This function's response will be pretty printed if it was not requested
with ``X-Requested-With: XMLHttpRequest`` to simplify debugging unless
Expand All @@ -260,12 +260,10 @@ def get_current_user():
raise TypeError(
"jsonify() behavior undefined when passed both args and kwargs"
)
elif len(args) == 1: # single args are passed directly to dumps()
elif len(args) == 1: # single args are passed directly to dumps()
data = args[0]
elif args: # convert multiple args into an array
data = list(args)
else: # convert kwargs to a dict
data = dict(kwargs)
else:
data = args or kwargs

# Note that we add '\n' to end of response
# (see https://github.com/mitsuhiko/flask/pull/1262)
Expand Down

0 comments on commit 0edf0a0

Please sign in to comment.