From 5fad5473e24541846e9a05905c95ff70fbebef2d Mon Sep 17 00:00:00 2001 From: tommynazareth Date: Tue, 31 Aug 2010 20:12:05 -0400 Subject: [PATCH] Added function 'padded_jsonify' to return JSONP --- flask/__init__.py | 2 +- flask/helpers.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/flask/__init__.py b/flask/__init__.py index ee8508bc..d5161ad0 100644 --- a/flask/__init__.py +++ b/flask/__init__.py @@ -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 diff --git a/flask/helpers.py b/flask/helpers.py index 18eb6d0e..0477bb18 100644 --- a/flask/helpers.py +++ b/flask/helpers.py @@ -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