Browse Source

clean up

pull/1711/head
David Lord 9 years ago
parent
commit
992d9be96e
  1. 17
      flask/json.py

17
flask/json.py

@ -195,7 +195,7 @@ def htmlsafe_dumps(obj, **kwargs):
def htmlsafe_dump(obj, fp, **kwargs): def htmlsafe_dump(obj, fp, **kwargs):
"""Like :func:`htmlsafe_dumps` but writes into a file object.""" """Like :func:`htmlsafe_dumps` but writes into a file object."""
fp.write(unicode(htmlsafe_dumps(obj, **kwargs))) fp.write(text_type(htmlsafe_dumps(obj, **kwargs)))
def jsonify(*args, **kwargs): def jsonify(*args, **kwargs):
@ -251,26 +251,21 @@ def jsonify(*args, **kwargs):
indent = None indent = None
separators = (',', ':') separators = (',', ':')
if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] \ if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
and not request.is_xhr:
indent = 2 indent = 2
separators = (', ', ': ') separators = (', ', ': ')
if args and kwargs: if args and kwargs:
raise TypeError( raise TypeError('jsonify() behavior undefined when passed both args and kwargs')
"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] data = args[0]
else: else:
data = args or kwargs data = args or kwargs
# Note that we add '\n' to end of response return current_app.response_class(
# (see https://github.com/mitsuhiko/flask/pull/1262)
rv = current_app.response_class(
(dumps(data, indent=indent, separators=separators), '\n'), (dumps(data, indent=indent, separators=separators), '\n'),
mimetype='application/json') mimetype='application/json'
return rv )
def tojson_filter(obj, **kwargs): def tojson_filter(obj, **kwargs):

Loading…
Cancel
Save