From 552a7d4886f7540a009b8adcaf76cc45aaf8f606 Mon Sep 17 00:00:00 2001 From: Antonio Date: Fri, 16 Mar 2018 16:55:08 +0100 Subject: [PATCH] Fixing Mapbox geocoding validity checks --- NEWS.md | 2 +- .../cartodb_services/mapbox/geocoder.py | 27 ++++++++++++++----- server/lib/python/cartodb_services/setup.py | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1b975bb..631221e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -683,4 +683,4 @@ Nov 27, 2015: * Release Geocoder API BETA 1 * Added the organization public user to the api key check -https://github.com/CartoDB/dataservices-api/releases/tag/0.0.1-beta \ No newline at end of file +https://github.com/CartoDB/dataservices-api/releases/tag/0.0.1-beta diff --git a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py index d6acb98..a8a9de0 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapbox/geocoder.py @@ -64,18 +64,31 @@ class MapboxGeocoder(Traceable): latitude = location[1] return [longitude, latitude] + def _validate_input(self, searchtext, city=None, state_province=None, + country=None): + if searchtext and searchtext.strip(): + return True + elif city: + return True + elif state_province: + return True + + return False + @qps_retry(qps=10) def geocode(self, searchtext, city=None, state_province=None, country=None): - if searchtext and searchtext.strip(): - address = [normalize(searchtext)] - if city: - address.append(normalize(city)) - if state_province: - address.append(normalize(state_province)) - else: + if not self._validate_input(searchtext, city, state_province, country): return [] + address = [] + if searchtext and searchtext.strip(): + address.append(normalize(searchtext)) + if city: + address.append(normalize(city)) + if state_province: + address.append(normalize(state_province)) + country = [country] if country else None try: diff --git a/server/lib/python/cartodb_services/setup.py b/server/lib/python/cartodb_services/setup.py index 844be14..7cc70f8 100644 --- a/server/lib/python/cartodb_services/setup.py +++ b/server/lib/python/cartodb_services/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages setup( name='cartodb_services', - version='0.17.4', + version='0.17.5', description='CartoDB Services API Python Library',