From 76e2e725b28f48a710dbeebfeeefa56cfb23ca59 Mon Sep 17 00:00:00 2001 From: Brendan Quinn Date: Thu, 22 Nov 2012 15:25:10 +0000 Subject: [PATCH] Now uses the django.utils.http version of urlencode which is Unicode-aware. --- geocoders/geonames.py | 3 ++- geocoders/google.py | 3 ++- geocoders/multimap.py | 3 ++- geocoders/nominatim.py | 3 ++- geocoders/placemaker.py | 3 ++- geocoders/yahoo.py | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/geocoders/geonames.py b/geocoders/geonames.py index 4940654..4b8ddb3 100644 --- a/geocoders/geonames.py +++ b/geocoders/geonames.py @@ -1,11 +1,12 @@ from utils import simplejson, geocoder_factory import urllib +from django.utils.http import urlencode # http://www.geonames.org/export/geonames-search.html def geocode(q): data = simplejson.load(urllib.urlopen( - 'http://ws.geonames.org/searchJSON?' + urllib.urlencode({ + 'http://ws.geonames.org/searchJSON?' + urlencode({ 'q': q, 'maxRows': 1, 'lang': 'en', diff --git a/geocoders/google.py b/geocoders/google.py index 4ab21c6..cec66d4 100644 --- a/geocoders/google.py +++ b/geocoders/google.py @@ -1,11 +1,12 @@ import urllib +from django.utils.http import urlencode from utils import simplejson, geocoder_factory # http://code.google.com/apis/maps/documentation/geocoding/index.html def geocode(q, api_key): json = simplejson.load(urllib.urlopen( - 'http://maps.google.com/maps/geo?' + urllib.urlencode({ + 'http://maps.google.com/maps/geo?' + urlencode({ 'q': q, 'output': 'json', 'oe': 'utf8', diff --git a/geocoders/multimap.py b/geocoders/multimap.py index d0400af..3d62995 100644 --- a/geocoders/multimap.py +++ b/geocoders/multimap.py @@ -1,11 +1,12 @@ import urllib +from django.utils.http import urlencode from utils import simplejson, geocoder_factory # http://www.multimap.com/openapidocs/1.2/web_service/ws_geocoding.htm def geocode(q, api_key): base_url = 'http://developer.multimap.com/API/geocode/1.2/%s' % urllib.quote(api_key) - json = simplejson.load(urllib.urlopen(base_url + '?' + urllib.urlencode({ + json = simplejson.load(urllib.urlopen(base_url + '?' + urlencode({ 'qs': q, 'output': 'json' }) diff --git a/geocoders/nominatim.py b/geocoders/nominatim.py index 3767bc9..a5b60d8 100644 --- a/geocoders/nominatim.py +++ b/geocoders/nominatim.py @@ -1,4 +1,5 @@ import urllib +from django.utils.http import urlencode from utils import simplejson, geocoder_factory def geocode(q, email): @@ -10,7 +11,7 @@ def geocode(q, email): """ json = simplejson.load(urllib.urlopen( - 'http://nominatim.openstreetmap.org/search?' + urllib.urlencode({ + 'http://nominatim.openstreetmap.org/search?' + urlencode({ 'q': q, 'format': 'json', 'email': email diff --git a/geocoders/placemaker.py b/geocoders/placemaker.py index e5afffc..fbabbb1 100644 --- a/geocoders/placemaker.py +++ b/geocoders/placemaker.py @@ -1,5 +1,6 @@ from utils import make_nsfind, ET, geocoder_factory import urllib +from django.utils.http import urlencode # http://developer.yahoo.com/geo/placemaker/guide/api_docs.html @@ -13,7 +14,7 @@ def geocode(q, api_key): 'appid': api_key, } et = ET.parse(urllib.urlopen( - 'http://wherein.yahooapis.com/v1/document', urllib.urlencode(args)) + 'http://wherein.yahooapis.com/v1/document', urlencode(args)) ) place = find(et, 'ns:document/ns:placeDetails/ns:place') if place is None: diff --git a/geocoders/yahoo.py b/geocoders/yahoo.py index 21fe62f..14560d0 100644 --- a/geocoders/yahoo.py +++ b/geocoders/yahoo.py @@ -1,12 +1,13 @@ from utils import make_nsfind, ET, geocoder_factory import urllib +from django.utils.http import urlencode # http://developer.yahoo.com/maps/rest/V1/geocode.html def geocode(q, api_key): find = make_nsfind({'ns': 'urn:yahoo:maps'}) args = {'location': q, 'appid': api_key} - url = 'http://local.yahooapis.com/MapsService/V1/geocode?%s' % urllib.urlencode(args) + url = 'http://local.yahooapis.com/MapsService/V1/geocode?%s' % urlencode(args) et = ET.parse(urllib.urlopen(url)) result = find(et, '//ns:Result')