diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-04-29 11:05:09 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2014-03-12 17:28:59 -0600 |
commit | d33715066aab8bace17bb575a1787af40f86e67a (patch) | |
tree | 2b315dbdd7839a93b344a68cc1e4c23e4902ccb8 /scanner/floatapp/jsonp.py | |
parent | Add semi-colon. (diff) | |
download | PhotoFloat-d33715066aab8bace17bb575a1787af40f86e67a.tar.xz PhotoFloat-d33715066aab8bace17bb575a1787af40f86e67a.zip |
Restructuring
Import flask app as well as new makefile and entirely new directory
structure.
Diffstat (limited to 'scanner/floatapp/jsonp.py')
-rw-r--r-- | scanner/floatapp/jsonp.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/scanner/floatapp/jsonp.py b/scanner/floatapp/jsonp.py new file mode 100644 index 0000000..cac8ad1 --- /dev/null +++ b/scanner/floatapp/jsonp.py @@ -0,0 +1,18 @@ +import json +from functools import wraps +from flask import redirect, request, current_app +import re + +jsonp_validator = re.compile("^[a-zA-Z0-9_\-.]{1,128}$") + +def jsonp(f): + """Wraps JSONified output for JSONP""" + @wraps(f) + def decorated_function(*args, **kwargs): + callback = request.args.get('callback', False) + if callback and jsonp_validator.match(callback): + content = str(callback) + '(' + str(f(*args,**kwargs).data) + ')' + return current_app.response_class(content, mimetype='application/javascript') + else: + return f(*args, **kwargs) + return decorated_function |