Added function 'padded_jsonify' to return JSONP

This commit is contained in:
tommynazareth 2010-08-31 20:12:05 -04:00
parent 6e3dd9b3ce
commit 5fad5473e2
2 changed files with 6 additions and 1 deletions

View file

@ -17,7 +17,7 @@ from jinja2 import Markup, escape
from .app import Flask, Request, Response
from .config import Config
from .helpers import url_for, jsonify, json_available, flash, \
from .helpers import url_for, jsonify, padded_jsonify, json_available, flash, \
send_file, send_from_directory, get_flashed_messages, \
get_template_attribute, make_response
from .globals import current_app, g, request, session, _request_ctx_stack

View file

@ -99,6 +99,11 @@ def jsonify(*args, **kwargs):
return current_app.response_class(json.dumps(dict(*args, **kwargs),
indent=None if request.is_xhr else 2), mimetype='application/json')
def padded_jsonify(*args, **kwargs):
if __debug__:
_assert_have_json()
content = str(callback) + '(' + json.dumps(dict(*args, **kwargs)) + ')'
return current_app.response_class(content, mimetype='application/json')
def make_response(*args):
"""Sometimes it is necessary to set additional headers in a view. Because