Skip to content

Instantly share code, notes, and snippets.

@perrygeo
Created February 13, 2012 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perrygeo/1821494 to your computer and use it in GitHub Desktop.
Save perrygeo/1821494 to your computer and use it in GitHub Desktop.
tilestache dynamic callback patch
From 8a0bcc6425e0e1865f09a10faec3a224d91a8ccc Mon Sep 17 00:00:00 2001
From: Matthew Perry <mperry@ecotrust.org>
Date: Mon, 13 Feb 2012 15:28:06 -0800
Subject: [PATCH] Allow dynamic callbacks for jsonp
---
TileStache/__init__.py | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/TileStache/__init__.py b/TileStache/__init__.py
index 267507a..73d7c5f 100644
--- a/TileStache/__init__.py
+++ b/TileStache/__init__.py
@@ -13,7 +13,10 @@ __version__ = 'N.N.N'
import re
from sys import stdout
-from cgi import parse_qs
+try:
+ from urlparse import parse_qs
+except ImportError:
+ from cgi import parse_qs
from StringIO import StringIO
from os.path import dirname, join as pathjoin, realpath
from datetime import datetime, timedelta
@@ -240,6 +243,10 @@ def requestHandler(config, path_info, query_string):
layer = requestLayer(config, path_info)
query = parse_qs(query_string or '')
+ try:
+ callback = query['callback'][0]
+ except KeyError:
+ callback = None
coord, extension = splitPathInfo(path_info)[1:]
@@ -259,6 +266,9 @@ def requestHandler(config, path_info, query_string):
mimetype, content = 'text/plain', out.getvalue()
+ if callback and 'json' in mimetype:
+ content = "%s(%s)" % (callback, content)
+
return mimetype, content
def cgiHandler(environ, config='./tilestache.cfg', debug=False):
--
1.7.4.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment