def validateRequest(request,type): # validate the key devStoreKey = utils.validateDevKey(request.get('key')) if devStoreKey is None: utils.recordDeveloperRequest(None,utils.GETSTOPS,request.query_string,request.remote_addr,'illegal developer key specified'); return None return devStoreKey
def validateRequest(request): # validate the key devStoreKey = utils.validateDevKey(request.get('key')) if devStoreKey is None: utils.recordDeveloperRequest(None,utils.GETSTOPS,request.query_string,request.remote_addr,'illegal developer key specified'); return None routeID = request.get('routeID') if routeID is None or routeID is '': utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'a routeID must be included'); return None return devStoreKey
def validateRequest(request): # validate the key devStoreKey = utils.validateDevKey(request.get('key')) if devStoreKey is None: utils.recordDeveloperRequest(None,utils.GETARRIVALS,request.query_string,request.remote_addr,'illegal developer key specified'); return None stopID = request.get('stopID') routeID = request.get('routeID') vehicleID = request.get('vehicleID') # give up if someone asked for stop 0, which seems to be popular for some reason logging.debug('validating stopID %s' % stopID); if stopID == '' or stopID is '0' or stopID is '0000': return None # a stopID or routeID is required if stopID is None and routeID is None: utils.recordDeveloperRequest(devStoreKey,utils.GETARRIVALS,request.query_string,request.remote_addr,'either a stopID or a routeID must be included'); return None # the routeID requires either a vehicleID or stopID if routeID is not None: if vehicleID is None and stopID is None: utils.recordDeveloperRequest(devStoreKey,utils.GETARRIVALS,request.query_string,request.remote_addr,'if routeID is specified, either a vehicleID or stopID is required'); return None # the vehicleID requires a routeID if vehicleID is not None: if routeID is None: utils.recordDeveloperRequest(devStoreKey,utils.GETVEHICLE,request.query_string,request.remote_addr,'if a vehicleID is specified, you must include a routeID'); return False # we've noticed some flagrant abuses of the API where the format # of the request parameters are just bogus. check those here if len(stopID) > 4: return None #logging.debug("successfully validated command parameters") return devStoreKey
def validateRequest(request,type): # validate the key devStoreKey = utils.validateDevKey(request.get('key')) if devStoreKey is None: logging.debug('... illegal developer key %s' % request.get('key')) utils.recordDeveloperRequest(None,utils.GETSTOPS,request.query_string,request.remote_addr,'illegal developer key specified'); return None if type == utils.GETSTOPS: routeID = request.get('routeID') destination = request.get('destination').upper() # a routeID is required if routeID is None or routeID is '': utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'a routeID must be included'); return None elif destination is not None and routeID is '': utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'if a destination is specified, a routeID must be included'); return None elif type == utils.GETSTOPLOCATION: stopID = utils.conformStopID(request.get('stopID')) if stopID == '' or stopID == '0' or stopID == '00': return None elif type == utils.GETNEARBYSTOPS: lat = request.get('lat') lon = request.get('lon') radius = request.get('radius') # lat/long is required if lat is None or lon is None: utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'both latitude and longitude values must be specified'); return None elif radius is not None and radius is not '' and radius > '5000': logging.error('unable to validate getnearbystops call. illegal radius value of %s' % radius) utils.recordDeveloperRequest(devStoreKey,type,request.query_string,request.remote_addr,'radius must be less than 5,000'); return None return devStoreKey