Ejemplo n.º 1
0
PyObject * AerospikeGeospatial_Loads(AerospikeGeospatial * self, PyObject * args, PyObject * kwds)
{

	// Python function arguments
	PyObject * py_geodata = NULL;
	// Python function keyword arguments
	static char * kwlist[] = {"geodata", NULL};

	if ( PyArg_ParseTupleAndKeywords(args, kwds, "O:loads", kwlist, &py_geodata) == false ){
		return NULL;
	}

	// Aerospike error object
	as_error err;
	// Initialize error object
	as_error_init(&err);

	if (!self) {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid geospatial data");
		goto CLEANUP;
	}

    PyObject* initresult = NULL;
    if (PyString_Check(py_geodata))
    {  
        initresult = AerospikeGeospatial_DoLoads(py_geodata, &err);
        if(!initresult) {
			as_error_update(&err, AEROSPIKE_ERR_CLIENT, "String is not GeoJSON serializable");
			goto CLEANUP;
        } else {
            store_geodata(self, &err, initresult);
        }
    } else {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "Argument should be a GeoJSON string");
		goto CLEANUP;
    }

CLEANUP:

	// If an error occurred, tell Python.
	if ( err.code != AEROSPIKE_OK ) {
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return NULL;
	}

	return PyLong_FromLong(0);
}
Ejemplo n.º 2
0
static int AerospikeGeospatial_Type_Init(AerospikeGeospatial * self, PyObject * args, PyObject * kwds)
{
	PyObject *py_geodata = NULL;
	PyObject* initresult = NULL;

	as_error err;
	as_error_init(&err);

	static char * kwlist[] = {"geo_data", NULL};

	if (PyArg_ParseTupleAndKeywords(args, kwds, "O:GeoJSON", kwlist,
		&py_geodata) == false) {
		as_error_update(&err, AEROSPIKE_ERR_PARAM, "GeoJSON() expects exactly 1 parameter");
		goto CLEANUP;
	}

	if (PyString_Check(py_geodata)) {
		initresult = AerospikeGeospatial_DoLoads(py_geodata, &err);
		if (!initresult) {
			as_error_update(&err, AEROSPIKE_ERR_CLIENT, "String is not GeoJSON serializable");
			goto CLEANUP;
		}
		store_geodata(self, &err, initresult);
	} else {
		store_geodata(self, &err, py_geodata);
	}

CLEANUP:

	if (err.code != AEROSPIKE_OK) {
		PyObject * py_err = NULL;
		error_to_pyobject(&err, &py_err);
		PyObject *exception_type = raise_exception(&err);
		PyErr_SetObject(exception_type, py_err);
		Py_DECREF(py_err);
		return -1;
	}

	Py_INCREF(self->geo_data);
	if (initresult) {
		Py_DECREF(initresult);
	}
	return 0;
}