Skip to content

Commit

Permalink
Merge pull request #6 from shadowsun7/master
Browse files Browse the repository at this point in the history
Updated Div's non-pythonic JSONP code
  • Loading branch information
ejamesc committed May 23, 2012
2 parents 8bca4f3 + 2a5d031 commit 037be2e
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions corsapi.py
Expand Up @@ -12,17 +12,20 @@

app = Flask(__name__)

def js_response_helper(dataJson, mime):
def js_response_helper(data_json, mime):
"""Assumes that callback is last arg.
"""
res = ""
url = request.url
if url.find("callback=") != -1:
first_index = url.find("callback=") + 9
res = url[first_index:] + "(" + dataJson + ");"
cb_reg = re.compile('callback=([^&]*)')
cb = cb_reg.search(url)
if cb:
res = cb.expand("\g<1>")
res = res + "(" + data_json + ");"
return Response(res, mimetype='application/javascript')
else:
res = dataJson
return Response(res, mimetype=mime)
res = data_json
return Response(res, mimetype=mime)


# mongoDB connection
Expand Down

0 comments on commit 037be2e

Please sign in to comment.