def get(self, layer, z, x, y): tile = { 'zoom': z, 'x': x, 'y': y, 'format': "pbf", } layer_config = self.metadata[layer] # Check if layer exists in db if not layer_config: return response.failure({ 'errors': { 'message': "The layer doesn't exist" } }, 400) # Get the env for the tile. if not (tile and self.mvt.tileIsValid(tile)): return response.failure({ 'errors': { 'message': "invalid tile path: %s" % (self.path) } }, 400) env = self.mvt.tileToEnvelope(tile) # Find table/function name. body = request.args.to_dict() table = layer if layer_config['layer_type'] == "function" and layer_config['args'] is not None: args = "" for index, arg in enumerate(layer_config['args']): if not arg in body: return response.failure({ 'errors': { 'message': "Not all arguments available. " } }) if index < len(layer_config['args']) - 1: args += body[arg] + "," else: args += body[arg] table = '''(SELECT * FROM {layer}({args}))'''.format( layer=layer, args=args) # Create the table object to pass in sql template string tbl = { 'env': self.mvt.envelopeToBoundsSQL(env), 'geomColumn': layer_config['geom'], 'attrColumns': layer_config['columns'], 'srid': layer_config['srid'], 'table': table } # Create the sql string vtSql = self.mvt.toSQL(tbl) # Execute sql and send pbf back pbf = db.fetch_one(vtSql) result_bytes = io.BytesIO(pbf) return send_file(result_bytes, mimetype='application/vnd.mapbox-vector-tile')
def delete(self, user_id=None): if user_id is None: error_data = { 'errors': { 'message': "The parameter 'user_id' is required" } } return response.failure(error_data, 400) result = users.delete_one({'_id': ObjectId(user_id)}) if result.deleted_count == 0: error_data = {'errors': {'message': "The user doesn't exist"}} return response.failure(error_data, 404) else: return response.success({'_id': user_id})
def handler(event, context): # print("event={}".format(json.dumps(event))) # print("request_id={}".format(context.aws_request_id)) for record in event["Records"]: payload = base64.b64decode(record["kinesis"]["data"]) partition_key = record["kinesis"]["partitionKey"] output = { "request_id": context.aws_request_id, "sandbox_id": str(sandbox_id), "partition_key": partition_key } try: output["payload"] = json.loads(payload) status = 200 except json.JSONDecodeError: output["payload"] = payload.decode("utf-8") status = 500 print(json.dumps(output)) if status == 200: response = success("success") else: response = failure("failure") return response
def check_args_complete(body, query_values): body_keys = list(body.keys()) if sorted(body_keys) != sorted(query_values): return response.failure( {'errors': { 'message': "Not all arguments available. " }}) else: return body
def put(self, user_id=None): if user_id is None: error_data = { 'errors': { 'message': "The parameter 'user_id' is required" } } return response.failure(error_data, 400) poseted_data = request.get_json() errors = validators.UserPutSchema().validate(poseted_data) if bool(errors): error_data = {'errors': errors} return response.failure(error_data, 400) update_user = {} if 'name' in poseted_data: update_user['name'] = poseted_data['name'] if 'age' in poseted_data: update_user['age'] = poseted_data['age'] if 'gender' in poseted_data: update_user['gender'] = poseted_data['gender'] if 'email' in poseted_data: update_user['email'] = poseted_data['email'] if not bool(update_user): error_data = {'errors': {'message': "Nothing to update"}} return response.failure(error_data, 400) result = users.update_one({'_id': ObjectId(user_id)}, {'$set': update_user}) if result.modified_count == 0: error_data = {'errors': {'message': "The user doesn't exist"}} return response.failure(error_data, 404) else: return response.success({'_id': user_id})
def post(self): poseted_data = request.get_json() errors = validators.UserPostSchema().validate(poseted_data) if bool(errors): error_data = {'errors': errors} return response.failure(error_data, 400) new_user = {} new_user['name'] = poseted_data['name'] if 'age' in poseted_data: new_user['age'] = poseted_data['age'] if 'gender' in poseted_data: new_user['gender'] = poseted_data['gender'] new_user['email'] = poseted_data['email'] if user_exists(new_user['email']): error_data = {'errors': {'message': 'The user already exists'}} return response.failure(error_data, 400) result = users.insert_one(new_user) new_user['_id'] = str(result.inserted_id) return response.success(new_user)
def test_return_failure(self): data = {'errors': {'message': 'ERROR'}} r, status_code = response.failure(data, 400) assert r == {'status': 'failure', 'data': data} assert status_code == 400