Limit the mode types accepted
This commit is contained in:
@@ -69,7 +69,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
|
||||
import sys, traceback
|
||||
type_, value_, traceback_ = sys.exc_info()
|
||||
quota_service.increment_failed_geocoder_use()
|
||||
error_msg = 'There was an error trying to obtain isodistances using here maps geocoder: {0}'.format(e)
|
||||
error_msg = 'There was an error trying to obtain isodistances: {0}'.format(e)
|
||||
plpy.notice(traceback.format_tb(traceback_))
|
||||
plpy.error(error_msg)
|
||||
finally:
|
||||
|
||||
@@ -11,6 +11,14 @@ class BadGeocodingParams(Exception):
|
||||
return repr('Bad geocoding params: ' + json.dumps(self.value))
|
||||
|
||||
|
||||
class WrongParams(Exception):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
def __str__(self):
|
||||
return repr('Wrong parameters passed: ' + json.dumps(self.value))
|
||||
|
||||
|
||||
class NoGeocodingParams(Exception):
|
||||
def __str__(self):
|
||||
return repr('No params for geocoding specified')
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from exceptions import WrongParams
|
||||
|
||||
|
||||
class HereMapsRoutingIsoline:
|
||||
'A Here Maps Routing wrapper for python'
|
||||
@@ -9,6 +11,11 @@ class HereMapsRoutingIsoline:
|
||||
STAGING_ROUTING_BASE_URL = 'https://isoline.route.cit.api.here.com'
|
||||
ISOLINE_PATH = '/routing/7.2/calculateisoline.json'
|
||||
|
||||
ACCEPTED_MODES = {
|
||||
"walk": "pedestrian",
|
||||
"car": "car"
|
||||
}
|
||||
|
||||
OPTIONAL_PARAMS = [
|
||||
'departure',
|
||||
'arrival',
|
||||
@@ -81,6 +88,11 @@ class HereMapsRoutingIsoline:
|
||||
return {key: source}
|
||||
|
||||
def __parse_mode_param(self, mode, options):
|
||||
if mode in self.ACCEPTED_MODES:
|
||||
mode_source = self.ACCEPTED_MODES[mode]
|
||||
else:
|
||||
raise WrongParams("{0} is not an accepted mode type".format(mode))
|
||||
|
||||
if 'mode_type' in options:
|
||||
mode_type = options['mode_type']
|
||||
else:
|
||||
@@ -97,7 +109,7 @@ class HereMapsRoutingIsoline:
|
||||
else:
|
||||
mode_feature = None
|
||||
|
||||
mode_param = "{0};{1}".format(mode_type, mode)
|
||||
mode_param = "{0};{1}".format(mode_type, mode_source)
|
||||
if mode_traffic:
|
||||
mode_param = "{0};{1}".format(mode_param, mode_traffic)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user