PyObject * AerospikeScan_Foreach(AerospikeScan * self, PyObject * args, PyObject * kwds) { // Python Function Arguments PyObject * py_callback = NULL; PyObject * py_policy = NULL; // Python Function Keyword Arguments static char * kwlist[] = {"callback", "policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "O|O:foreach", kwlist, &py_callback, &py_policy) == false ) { return NULL; } // Aerospike Client Arguments as_error err; as_policy_scan policy; as_policy_scan * policy_p = NULL; // Initialize error as_error_init(&err); // Convert python policy object to as_policy_exists pyobject_to_policy_scan(&err, py_policy, &policy, &policy_p); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } // Create and initialize callback user-data LocalData data; data.callback = py_callback; as_error_init(&data.error); // We are spawning multiple threads PyThreadState * _save = PyEval_SaveThread(); // Invoke operation aerospike_scan_foreach(self->client->as, &err, policy_p, &self->scan, each_result, &data); // We are done using multiple threads PyEval_RestoreThread(_save); CLEANUP: if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyErr_SetObject(PyExc_Exception, py_err); return NULL; } Py_INCREF(Py_None); return Py_None; }
PyObject * AerospikeGeospatial_Dumps(AerospikeGeospatial * self, PyObject * args, PyObject * kwds) { PyObject *initresult = 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; } initresult = AerospikeGeospatial_DoDumps(self->geo_data, &err); if(!initresult) { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Unable to call dumps function"); 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 initresult; }
PyObject * AerospikeGeospatial_Unwrap(AerospikeGeospatial * self, PyObject * args, PyObject * kwds) { // Python function arguments // Python function keyword arguments static char * kwlist[] = {NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, ":unwrap", kwlist) == 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 object"); 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; } Py_INCREF(self->geo_data); return self->geo_data; }
/** ******************************************************************************************************** * Delete the entire map(LDT Remove). * * @param self AerospikeLMap object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns an integer status. 0(Zero) is success value. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************** */ PyObject * AerospikeLMap_Destroy(AerospikeLMap * self, PyObject * args, PyObject * kwds) { PyObject* py_policy = NULL; as_policy_apply apply_policy; as_policy_apply* apply_policy_p = NULL; as_error err; as_error_init(&err); static char * kwlist[] = {"policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "|O:destroy", kwlist, &py_policy) == false ) { return NULL; } if (!self || !self->client->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_apply pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p, &self->client->as->config.policies.apply); if ( err.code != AEROSPIKE_OK ) { as_error_update(&err, err.code, NULL); goto CLEANUP; } aerospike_lmap_destroy(self->client->as, &err, apply_policy_p, &self->key, &self->lmap); CLEANUP: if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL, *py_key = NULL; PyObject *exception_type = raise_exception(&err); error_to_pyobject(&err, &py_err); if(PyObject_HasAttrString(exception_type, "key")) { key_to_pyobject(&err, &self->key, &py_key); PyObject_SetAttrString(exception_type, "key", py_key); Py_DECREF(py_key); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject *py_bins = PyString_FromString((char *)&self->bin_name); PyObject_SetAttrString(exception_type, "bin", py_bins); Py_DECREF(py_bins); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return PyLong_FromLong(0); }
/** ******************************************************************************************************* * This function will checks if latest batch protocol and calls appropriate * function. * * @param self AerospikeClient object * @param py_keys The list of keys * @param py_policy The dictionary of policies * * Returns the record if key exists otherwise NULL. ******************************************************************************************************* */ static PyObject * AerospikeClient_Get_Many_Invoke( AerospikeClient * self, PyObject * py_keys, PyObject * py_policy) { // Python Return Value PyObject * py_recs = NULL; // Aerospike Client Arguments as_error err; as_policy_batch policy; as_policy_batch * batch_policy_p = NULL; bool has_batch_index = false; // Initialize error as_error_init(&err); if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_batch pyobject_to_policy_batch(&err, py_policy, &policy, &batch_policy_p, &self->as->config.policies.batch); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } has_batch_index = aerospike_has_batch_index(self->as); if (has_batch_index && !(self->as->config.policies.batch.use_batch_direct)) { py_recs = batch_get_aerospike_batch_read(&err, self, py_keys, batch_policy_p); } else { py_recs = batch_get_aerospike_batch_get(&err, self, py_keys, batch_policy_p); } CLEANUP: if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); if(PyObject_HasAttrString(exception_type, "key")) { PyObject_SetAttrString(exception_type, "key", py_keys); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject_SetAttrString(exception_type, "bin", Py_None); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return py_recs; }
/** ****************************************************************************************************** * Removes a bin from a record. * * @param self AerospikeClient object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns an integer status. 0(Zero) is success value. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************* */ PyObject * AerospikeClient_RemoveBin(AerospikeClient * self, PyObject * args, PyObject * kwds) { // Python Function Arguments PyObject * py_key = NULL; PyObject * py_policy = NULL; PyObject * py_binList = NULL; PyObject * py_result = NULL; PyObject * py_meta = NULL; as_error err; // Initialize error as_error_init(&err); // Python Function Keyword Arguments static char * kwlist[] = {"key", "list", "meta", "policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO:remove_bin", kwlist, &py_key, &py_binList ,&py_meta, &py_policy) == false ) { return NULL; } if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } if(!PyList_Check(py_binList)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Bins should be a list"); goto CLEANUP; } // Invoke Operation return AerospikeClient_RemoveBin_Invoke(self, py_key, py_binList, py_policy, py_meta, &err); CLEANUP: if ( err.code != AEROSPIKE_OK || !py_result) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); if(PyObject_HasAttrString(exception_type, "key")) { PyObject_SetAttrString(exception_type, "key", py_key); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject_SetAttrString(exception_type, "bin", Py_None); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return NULL; }
static PyObject * AerospikePredicates_GeoContains_Point(PyObject * self, PyObject * args) { PyObject * py_bin = NULL; PyObject * py_lat = NULL; PyObject * py_long = NULL; PyObject * py_geo_object = NULL; PyObject * py_shape = NULL; as_error err; as_error_init(&err); py_geo_object = PyDict_New(); if (PyArg_ParseTuple(args, "OOO:geo_contains_point", &py_bin, &py_lat, &py_long) == false) { goto CLEANUP; } PyObject *py_point = PyString_FromString("Point"); PyDict_SetItemString(py_geo_object, "type", py_point); Py_DECREF(py_point); if (PyString_Check(py_bin) && PyFloat_Check(py_lat) && PyFloat_Check(py_long)) { PyObject * py_list = PyList_New(2); PyList_SetItem(py_list, 0, py_lat); PyList_SetItem(py_list, 1, py_long); PyDict_SetItemString(py_geo_object, "coordinates", py_list); py_shape = AerospikeGeospatial_DoDumps(py_geo_object, &err); if (!py_shape) { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "Unable to call dumps function"); goto CLEANUP; } } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Latitude and longitude should be of double type, bin of string type"); goto CLEANUP; } return Py_BuildValue("iiOOi", AS_PREDICATE_RANGE, AS_INDEX_GEO2DSPHERE, py_bin, py_shape, 1); 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; } Py_INCREF(Py_None); return Py_None; }
/** *********************************************************************** * * Callback method, invoked by aerospike_batch_get_bins * * ********************************************************************* **/ static bool batch_select_cb(const as_batch_read* results, uint32_t n, void* udata) { // Typecast udata back to PyObject PyObject * py_recs = (PyObject *) udata; // Initialize error object as_error err; as_error_init(&err); // Loop over results array for ( uint32_t i =0; i < n; i++ ){ PyObject * rec = NULL; PyObject * p_key = NULL; if(results[i].key->valuep) { switch(((as_val*)(results[i].key->valuep))->type){ case AS_INTEGER: p_key = PyInt_FromLong((long)results[i].key->value.integer.value); break; case AS_STRING: p_key = PyString_FromString((const char *)results[i].key->value.string.value); break; default: break; } } else { Py_INCREF(Py_None); p_key = Py_None; } // Check record status if ( results[i].result == AEROSPIKE_OK ){ record_to_pyobject(&err, &results[i].record, results[i].key, &rec); // Set return value in return Dict if ( PyDict_SetItem( py_recs, p_key, rec ) ){ return false; } Py_DECREF(rec); } else if( results[i].result == AEROSPIKE_ERR_RECORD_NOT_FOUND ){ Py_INCREF(Py_None); if ( PyDict_SetItem( py_recs, p_key, Py_None)){ return false; } } Py_DECREF(p_key); } return true; }
PyObject * AerospikeScan_Results(AerospikeScan * self, PyObject * args, PyObject * kwds) { PyObject * py_policy = NULL; as_policy_scan scan_policy; as_policy_scan * scan_policy_p = NULL; static char * kwlist[] = {"policy", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, "|O:results", kwlist, &py_policy) == false ) { return NULL; } as_error err; as_error_init(&err); if (!self || !self->client->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_scan pyobject_to_policy_scan(&err, py_policy, &scan_policy, &scan_policy_p, &self->client->as->config.policies.scan); if ( err.code != AEROSPIKE_OK ) { as_error_update(&err, err.code, NULL); goto CLEANUP; } PyObject * py_results = NULL; py_results = PyList_New(0); PyThreadState * _save = PyEval_SaveThread(); aerospike_scan_foreach(self->client->as, &err, scan_policy_p, &self->scan, each_result, py_results); PyEval_RestoreThread(_save); 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 NULL; } return py_results; }
static void as_cluster_find_nodes_to_add(as_cluster* cluster, as_vector* /* <as_host> */ friends, as_vector* /* <as_node*> */ nodes_to_add) { as_error err; as_error_init(&err); as_vector addresses; as_vector_inita(&addresses, sizeof(struct sockaddr_in), 5); as_node_info node_info; for (uint32_t i = 0; i < friends->size; i++) { as_host* friend = as_vector_get(friends, i); as_vector_clear(&addresses); as_status status = as_lookup(&err, friend->name, friend->port, &addresses); if (status != AEROSPIKE_OK) { as_log_warn("%s %s", as_error_string(status), err.message); continue; } for (uint32_t i = 0; i < addresses.size; i++) { struct sockaddr_in* addr = as_vector_get(&addresses, i); status = as_lookup_node(cluster, &err, addr, &node_info); if (status == AEROSPIKE_OK) { as_node* node = as_cluster_find_node(cluster->nodes, nodes_to_add, node_info.name); if (node) { // Duplicate node name found. This usually occurs when the server // services list contains both internal and external IP addresses // for the same node. Add new host to list of alias filters // and do not add new node. as_close(node_info.fd); as_address* a = as_node_get_address_full(node); as_log_info("Node %s:%d already exists with nodeid %s and address %s:%d", friend->name, friend->port, node->name, a->name, (int)cf_swap_from_be16(a->addr.sin_port)); node->friends++; as_node_add_address(node, friend, addr); continue; } node = as_node_create(cluster, friend, addr, &node_info); as_address* a = as_node_get_address_full(node); as_log_info("Add node %s %s:%d", node_info.name, a->name, (int)cf_swap_from_be16(a->addr.sin_port)); as_vector_append(nodes_to_add, &node); } else { as_log_warn("Failed to connect to friend %s:%d. %s %s", friend->name, friend->port, as_error_string(status), err.message); } }
/** ******************************************************************************************************* * Closes already opened connection to the database. * * @param self AerospikeClient object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns None. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************* */ PyObject * AerospikeClient_Close(AerospikeClient * self, PyObject * args, PyObject * kwds) { as_error err; // Initialize error as_error_init(&err); if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } aerospike_close(self->as, &err); 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; } self->is_conn_16 = false; /* * Need to free memory allocated to host address string * in AerospikeClient_Type_Init. */ for( int i = 0; i < self->as->config.hosts_size; i++) { free(self->as->config.hosts[i].addr); } aerospike_destroy(self->as); self->as = NULL; Py_INCREF(Py_None); 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 NULL; } return Py_None; }
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); }
/** ******************************************************************************************************** * Get the current item count of the stack. * * @param self AerospikeLStack object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns the size of stack. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************** */ PyObject * AerospikeLStack_Size(AerospikeLStack * self, PyObject * args, PyObject * kwds) { uint32_t size = 0; PyObject* py_policy = NULL; as_policy_apply apply_policy; as_policy_apply* apply_policy_p = NULL; as_error err; as_error_init(&err); static char * kwlist[] = {"policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "|O:size", kwlist, &py_policy) == false ) { return NULL; } if (!self || !self->client || !self->client->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_apply pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p, &self->client->as->config.policies.apply); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } aerospike_lstack_size(self->client->as, &err, apply_policy_p, &self->key, &self->lstack, &size); CLEANUP: if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyErr_SetObject(PyExc_Exception, py_err); Py_DECREF(py_err); return NULL; } return PyLong_FromLong(size); }
/** ******************************************************************************************************* * Closes already opened connection to the database. * * @param self AerospikeClient object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns None. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************* */ PyObject * AerospikeClient_Close(AerospikeClient * self, PyObject * args, PyObject * kwds) { as_error err; char *alias_to_search = NULL; // Initialize error as_error_init(&err); if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } alias_to_search = return_search_string(self->as); PyObject *py_persistent_item = NULL; py_persistent_item = PyDict_GetItemString(py_global_hosts, alias_to_search); if (py_persistent_item) { close_aerospike_object(self->as, &err, alias_to_search, py_persistent_item); } else { aerospike_close(self->as, &err); for (unsigned int i = 0; i < self->as->config.hosts_size; i++) { free((void *) self->as->config.hosts[i].addr); } Py_BEGIN_ALLOW_THREADS aerospike_destroy(self->as); Py_END_ALLOW_THREADS } self->is_conn_16 = false; self->as = NULL; PyMem_Free(alias_to_search); alias_to_search = NULL; Py_INCREF(Py_None); 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 NULL; } return Py_None; }
/** ****************************************************************************************************** * Set a serializer in the aerospike database * * @param self Aerospike object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns integer handle for the serializer being set. ******************************************************************************************************* */ PyObject * AerospikeClient_Set_Serializer(AerospikeClient * self, PyObject * args, PyObject * kwds) { // Python Function Arguments PyObject * py_func = NULL; // Python Function Keyword Arguments static char * kwlist[] = {"function", NULL}; as_error err; // Initialize error as_error_init(&err); // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "O:set_serializer", kwlist, &py_func) == false ) { return NULL; } if (!is_user_serializer_registered) { memset(&user_serializer_call_info, 0, sizeof(user_serializer_call_info)); } if (user_serializer_call_info.callback == py_func) { return PyLong_FromLong(0); } if (!PyCallable_Check(py_func)) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Parameter must be a callable"); goto CLEANUP; } if (user_serializer_call_info.callback != NULL) { Py_DECREF(user_serializer_call_info.callback); } is_user_serializer_registered = 1; user_serializer_call_info.callback = py_func; Py_INCREF(py_func); 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 NULL; } return PyLong_FromLong(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; }
PyObject * AerospikeClient_Unset_Serializers(AerospikeClient * self, PyObject * args, PyObject * kwds) { // Python Function Keyword Arguments static char * kwlist[] = {NULL}; as_error err; // Initialize error as_error_init(&err); // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, ":unset_serializers", kwlist) == false ) { return NULL; } is_user_serializer_registered = 0; is_user_deserializer_registered = 0; memset(&user_deserializer_call_info, 0, sizeof(user_deserializer_call_info)); memset(&user_serializer_call_info, 0, sizeof(user_serializer_call_info)); return PyLong_FromLong(0); }
AerospikeClient * AerospikeClient_New(PyObject * parent, PyObject * args, PyObject * kwds) { AerospikeClient * self = (AerospikeClient *) AerospikeClient_Type.tp_new(&AerospikeClient_Type, args, kwds); if ( AerospikeClient_Type.tp_init((PyObject *) self, args, kwds) == 0 ){ // Initialize connection flag self->is_conn_16 = false; return self; } else { as_error err; as_error_init(&err); as_error_update(&err, AEROSPIKE_ERR_PARAM, "Parameters are incorrect"); 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; } }
static int AerospikeLList_Type_Init(AerospikeLList * self, PyObject * args, PyObject * kwds) { PyObject * py_key = NULL; char* bin_name = NULL; char* module = NULL; static char * kwlist[] = {"key", "bin", "module", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, "Os|s:llist", kwlist, &py_key, &bin_name, &module) == false ) { return -1; } /* * Convert pyobject to as_key type. */ as_error error; as_error_init(&error); pyobject_to_key(&error, py_key, &self->key); if (error.code != AEROSPIKE_OK) { return -1; } int bin_name_len = strlen(bin_name); if ((bin_name_len == 0) || (bin_name_len > AS_BIN_NAME_MAX_LEN)) { return -1; } strcpy(self->bin_name, bin_name); /* * LDT Initialization */ initialize_ldt(&error, &self->llist, self->bin_name, AS_LDT_LLIST, module); if (error.code != AEROSPIKE_OK) { return -1; } return 0; }
static as_status as_scan_command_execute(as_scan_task* task) { as_command_node cn; cn.node = task->node; as_error err; as_error_init(&err); as_status status = as_command_execute(&err, &cn, task->cmd, task->cmd_size, task->policy->timeout, AS_POLICY_RETRY_NONE, as_scan_parse, task); if (status) { // Set main error only once. if (ck_pr_fas_32(task->error_mutex, 1) == 0) { // Don't set error when user aborts query, if (status != AEROSPIKE_ERR_CLIENT_ABORT) { as_error_copy(task->err, &err); } } } return status; }
AerospikeLList * AerospikeLList_New(AerospikeClient * client, PyObject * args, PyObject * kwds) { AerospikeLList * self = (AerospikeLList *) AerospikeLList_Type.tp_new(&AerospikeLList_Type, args, kwds); self->client = client; Py_INCREF(client); if (AerospikeLList_Type.tp_init((PyObject *)self, args, kwds) == 0) { return self; } else { as_error err; as_error_init(&err); as_error_update(&err, AEROSPIKE_ERR_PARAM, "Parameters are incorrect"); PyObject * py_err = NULL; PyObject * py_key = NULL; PyObject *exception_type = raise_exception(&err); error_to_pyobject(&err, &py_err); if(PyObject_HasAttrString(exception_type, "key")) { if(&self->key) { key_to_pyobject(&err, &self->key, &py_key); PyObject_SetAttrString(exception_type, "key", py_key); Py_DECREF(py_key); } else { PyObject_SetAttrString(exception_type, "key", Py_None); } } if(PyObject_HasAttrString(exception_type, "bin")) { if(&self->bin_name) { PyObject *py_bins = PyStr_FromString((char *)&self->bin_name); PyObject_SetAttrString(exception_type, "bin", py_bins); Py_DECREF(py_bins); } else { PyObject_SetAttrString(exception_type, "bin", Py_None); } } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } }
PyObject * AerospikeQuery_Results(AerospikeQuery * self, PyObject * args, PyObject * kwds) { PyObject * py_policy = NULL; static char * kwlist[] = {"policy", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, "|O:foreach", kwlist, &py_policy) == false ) { return NULL; } as_error err; as_error_init(&err); TRACE(); PyObject * py_results = PyList_New(0); TRACE(); PyThreadState * _save = PyEval_SaveThread(); TRACE(); aerospike_query_foreach(self->client->as, &err, NULL, &self->query, each_result, py_results); TRACE(); PyEval_RestoreThread(_save); TRACE(); if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyErr_SetObject(PyExc_Exception, py_err); TRACE(); return NULL; } TRACE(); return py_results; }
PyObject * AerospikeClient_HasGeo(AerospikeClient * self, PyObject * args, PyObject * kwds) { // Initialize error as_error err; as_error_init(&err); if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } if (aerospike_has_geo(self->as)) { Py_INCREF(Py_True); return Py_True; } Py_INCREF(Py_False); return Py_False; 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 NULL; } return NULL; }
/** ******************************************************************************************************* * Sends an info request to all the nodes in a cluster. * * @param self AerospikeClient object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns a server response for the particular request string. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************* */ PyObject * AerospikeClient_Info(AerospikeClient * self, PyObject * args, PyObject * kwds) { PyObject * py_req = NULL; PyObject * py_policy = NULL; PyObject * py_hosts = NULL; PyObject * py_nodes = NULL; PyObject * py_ustr = NULL; foreach_callback_info_udata info_callback_udata; static char * kwlist[] = {"command", "hosts", "policy", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, "O|OO:info", kwlist, &py_req, &py_hosts, &py_policy) == false ) { return NULL; } as_error err; as_error_init(&err); as_policy_info info_policy; as_policy_info* info_policy_p = NULL; py_nodes = PyDict_New(); info_callback_udata.udata_p = py_nodes; info_callback_udata.host_lookup_p = py_hosts; as_error_init(&info_callback_udata.error); if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python policy object to as_policy_info pyobject_to_policy_info(&err, py_policy, &info_policy, &info_policy_p, &self->as->config.policies.info); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } char * req = NULL; if ( PyUnicode_Check(py_req)) { py_ustr = PyUnicode_AsUTF8String(py_req); req = PyStr_AsString(py_ustr); } else if( PyStr_Check(py_req) ) { req = PyStr_AsString(py_req); } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Request must be a string"); goto CLEANUP; } aerospike_info_foreach(self->as, &err, info_policy_p, req, (aerospike_info_foreach_callback)AerospikeClient_Info_each, &info_callback_udata); if (&info_callback_udata.error.code != AEROSPIKE_OK) { as_error_update(&err, err.code, NULL); goto CLEANUP; } CLEANUP: if (py_ustr) { Py_DECREF(py_ustr); } if ( info_callback_udata.error.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&info_callback_udata.error, &py_err); PyObject *exception_type = raise_exception(&info_callback_udata.error); PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); if (py_nodes) { Py_DECREF(py_nodes); } return NULL; } 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); if (py_nodes) { Py_DECREF(py_nodes); } return NULL; } return info_callback_udata.udata_p; }
AerospikeQuery * AerospikeQuery_Apply(AerospikeQuery * self, PyObject * args, PyObject * kwds) { as_error err; // Initialize error as_error_init(&err); int nargs = (int) PyTuple_Size(args); // Aerospike API Arguments char * module = NULL; char * function = NULL; as_arraylist * arglist = NULL; // too few args if ( nargs < 2 ) { // some error } // Python Arguments PyObject * py_module = PyTuple_GetItem(args, 0); PyObject * py_function = PyTuple_GetItem(args, 1); if ( PyString_Check(py_module) ) { module = PyString_AsString(py_module); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "udf module argument must be a string"); goto CLEANUP; } if ( PyString_Check(py_function) ) { function = PyString_AsString(py_function); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "udf function argument must be a string"); goto CLEANUP; } if ( nargs > 2 ) { arglist = as_arraylist_new(nargs, 0); for ( int i = 2; i < nargs; i++ ) { PyObject * py_val = PyTuple_GetItem(args, i); as_val * val = NULL; pyobject_to_val(&err, py_val, &val); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } } } as_query_apply(&self->query, module, function, (as_list *) arglist); CLEANUP: if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyErr_SetObject(PyExc_Exception, py_err); return NULL; } Py_INCREF(self); return self; }
/** ******************************************************************************************************* * Multiple operations on a single record * * @param self AerospikeClient object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns tuple of bins on success if read operation is given. * Otherwise returns 0 on success for other operations. ******************************************************************************************************* */ PyObject * AerospikeClient_Operate(AerospikeClient * self, PyObject * args, PyObject * kwds) { // Initialize error as_error err; as_error_init(&err); // Python Function Arguments PyObject * py_key = NULL; PyObject * py_list = NULL; PyObject * py_policy = NULL; PyObject * py_result = NULL; PyObject * py_meta = NULL; as_key key; as_policy_operate operate_policy; as_policy_operate *operate_policy_p = NULL; // Python Function Keyword Arguments static char * kwlist[] = {"key", "list", "meta", "policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO:operate", kwlist, &py_key, &py_list, &py_meta, &py_policy) == false ) { return NULL; } if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } py_result = AerospikeClient_convert_pythonObj_to_asType(self, &err, py_key, py_policy, &key, &operate_policy, &operate_policy_p); if (!py_result) { goto CLEANUP; } else { Py_DECREF(py_result); } if ( py_list != NULL && PyList_Check(py_list) ) { py_result = AerospikeClient_Operate_Invoke(self, &err, &key, py_list, py_meta, operate_policy_p); } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Operations should be of type list"); goto CLEANUP; } CLEANUP: if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); if(PyObject_HasAttrString(exception_type, "key")) { PyObject_SetAttrString(exception_type, "key", py_key); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return py_result; }
/** ******************************************************************************************************* * Increments a numeric value in a bin. * * @param self AerospikeClient object * @param args The args is a tuple object containing an argument * list passed from Python to a C function * @param kwds Dictionary of keywords * * Returns an integer status. 0(Zero) is success value. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************* */ PyObject * AerospikeClient_Increment(AerospikeClient * self, PyObject * args, PyObject * kwds) { // Initialize error as_error err; as_error_init(&err); // Python Function Arguments PyObject * py_key = NULL; PyObject * py_policy = NULL; PyObject * py_result = NULL; PyObject * py_bin = NULL; PyObject * py_meta = NULL; PyObject * py_offset_value = 0; as_key key; as_policy_operate operate_policy; as_policy_operate *operate_policy_p = NULL; // Python Function Keyword Arguments static char * kwlist[] = {"key", "bin", "offset", "meta", "policy", NULL}; // Python Function Argument Parsing if ( PyArg_ParseTupleAndKeywords(args, kwds, "OOO|OO:increment", kwlist, &py_key, &py_bin, &py_offset_value, &py_meta, &py_policy) == false ) { return NULL; } if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } py_result = AerospikeClient_convert_pythonObj_to_asType(self, &err, py_key, py_policy, &key, &operate_policy, &operate_policy_p); if (!py_result) { goto CLEANUP; } else { Py_DECREF(py_result); } PyObject * py_list = NULL; py_list = create_pylist(py_list, AS_OPERATOR_INCR, py_bin, py_offset_value); py_result = AerospikeClient_Operate_Invoke(self, &err, &key, py_list, py_meta, operate_policy_p); if (py_list) { Py_DECREF(py_list); } if (err.code != AEROSPIKE_OK) { as_error_update(&err, err.code, NULL); goto CLEANUP; } else if (py_result == NULL) { return NULL; } else { Py_DECREF(py_result); } CLEANUP: if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); if(PyObject_HasAttrString(exception_type, "key")) { PyObject_SetAttrString(exception_type, "key", py_key); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject_SetAttrString(exception_type, "bin", py_bin); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return PyLong_FromLong(0); }
/** ******************************************************************************************************* * This function invokes csdk's API to remove particular record. * * @param self AerospikeClient object * @param py_key The key under which to store the record * @param generation The generation value * @param py_policy The optional policy parameters * * Returns 0 on success. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************* */ PyObject * AerospikeClient_Remove_Invoke( AerospikeClient * self, PyObject * py_key, PyObject * py_meta, PyObject * py_policy) { // Aerospike Client Arguments as_error err; as_policy_remove remove_policy; as_policy_remove * remove_policy_p = NULL; as_key key; // Initialisation flags bool key_initialised = false; // Initialize error as_error_init(&err); if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python key object to as_key pyobject_to_key(&err, py_key, &key); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } // Key is initialised successfully key_initialised = true; // Convert python policy object to as_policy_exists if (py_policy) { pyobject_to_policy_remove(&err, py_policy, &remove_policy, &remove_policy_p, &self->as->config.policies.remove); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } else { if ( py_meta && PyDict_Check(py_meta) ) { PyObject * py_gen = PyDict_GetItemString(py_meta, "gen"); if( py_gen != NULL ){ if ( PyInt_Check(py_gen) ) { remove_policy_p->generation = (uint16_t) PyInt_AsLong(py_gen); } else if ( PyLong_Check(py_gen) ) { remove_policy_p->generation = (uint16_t) PyLong_AsLongLong(py_gen); if((uint16_t)-1 == remove_policy_p->generation) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "integer value for gen exceeds sys.maxsize"); goto CLEANUP; } } else { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Generation should be an int or long"); } } } } } // Invoke operation Py_BEGIN_ALLOW_THREADS aerospike_key_remove(self->as, &err, remove_policy_p, &key); Py_END_ALLOW_THREADS if(err.code != AEROSPIKE_OK) { as_error_update(&err, err.code, NULL); } CLEANUP: if (key_initialised == true){ // Destroy the key if it is initialised successfully. as_key_destroy(&key); } if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); if(PyObject_HasAttrString(exception_type, "key")) { PyObject_SetAttrString(exception_type, "key", py_key); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject_SetAttrString(exception_type, "bin", Py_None); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return PyLong_FromLong(0); }
AerospikeQuery * AerospikeQuery_Apply(AerospikeQuery * self, PyObject * args, PyObject * kwds) { // Python function arguments PyObject * py_module = NULL; PyObject * py_function = NULL; PyObject * py_args = NULL; PyObject * py_policy = NULL; PyObject * py_umodule = NULL; PyObject * py_ufunction = NULL; // Python function keyword arguments static char * kwlist[] = {"module", "function", "arguments", "policy", NULL}; if ( PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO:apply", kwlist, &py_module, &py_function, &py_args, &py_policy) == false ){ return NULL; } // Aerospike error object as_error err; // Initialize error object as_error_init(&err); if ( !self || !self->client->as ){ as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid query object"); goto CLEANUP; } if (!self->client->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Aerospike API Arguments char * module = NULL; char * function = NULL; as_arraylist * arglist = NULL; if ( PyUnicode_Check(py_module) ){ py_umodule = PyUnicode_AsUTF8String(py_module); module = PyStr_AsString(py_umodule); } else if ( PyStr_Check(py_module) ) { module = PyStr_AsString(py_module); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "udf module argument must be a string or unicode string"); goto CLEANUP; } if ( PyUnicode_Check(py_function) ){ py_ufunction = PyUnicode_AsUTF8String(py_function); function = PyStr_AsString(py_ufunction); } else if ( PyStr_Check(py_function) ) { function = PyStr_AsString(py_function); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "udf function argument must be a string or unicode string"); goto CLEANUP; } if ( py_args && PyList_Check(py_args) ){ Py_ssize_t size = PyList_Size(py_args); arglist = as_arraylist_new(size, 0); for ( int i = 0; i < size; i++ ) { PyObject * py_val = PyList_GetItem(py_args, (Py_ssize_t)i); as_val * val = NULL; pyobject_to_val(self->client, &err, py_val, &val, &self->static_pool, SERIALIZER_PYTHON); if ( err.code != AEROSPIKE_OK ) { as_error_update(&err, err.code, NULL); goto CLEANUP; } else { as_arraylist_append(arglist, val); } } } as_query_apply(&self->query, module, function, (as_list *) arglist); CLEANUP: if (py_ufunction) { Py_DECREF(py_ufunction); } if (py_umodule) { Py_DECREF(py_umodule); } if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); if(PyObject_HasAttrString(exception_type, "module")) { PyObject_SetAttrString(exception_type, "module", py_module); } if(PyObject_HasAttrString(exception_type, "func")) { PyObject_SetAttrString(exception_type, "func", py_function); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } Py_INCREF(self); return self; }
/** ******************************************************************************************************* * This function applies a registered udf module on a particular record. * * @param self AerospikeClient object * @param py_key The key under which to store the record. * @param py_module The module name. * @param py_function The UDF function to be applied on a record. * @param py_arglist The arguments to the UDF function * @param py_policy The optional policy parameters * * Returns the result of UDF function. ******************************************************************************************************* */ PyObject * AerospikeClient_Apply_Invoke( AerospikeClient * self, PyObject * py_key, PyObject * py_module, PyObject * py_function, PyObject * py_arglist, PyObject * py_policy) { // Python Return Value PyObject * py_result = NULL; // Aerospike Client Arguments as_error err; as_policy_apply apply_policy; as_policy_apply * apply_policy_p = NULL; as_key key; char * module = NULL; char * function = NULL; as_list * arglist = NULL; as_val * result = NULL; PyObject * py_umodule = NULL; PyObject * py_ufunction = NULL; // Initialisation flags bool key_initialised = false; // Initialize error as_error_init(&err); if( !PyList_Check(py_arglist) ) { PyErr_SetString(PyExc_TypeError, "expected UDF method arguments in a 'list'"); return NULL; } if (!self || !self->as) { as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); goto CLEANUP; } if (!self->is_conn_16) { as_error_update(&err, AEROSPIKE_ERR_CLUSTER, "No connection to aerospike cluster"); goto CLEANUP; } // Convert python key object to as_key pyobject_to_key(&err, py_key, &key); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } // Key is initialiased successfully key_initialised = true; // Convert python list to as_list pyobject_to_list(self, &err, py_arglist, &arglist, NULL, -1); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } // Convert python policy object to as_policy_apply pyobject_to_policy_apply(&err, py_policy, &apply_policy, &apply_policy_p, &self->as->config.policies.apply); if ( err.code != AEROSPIKE_OK ) { goto CLEANUP; } if ( PyUnicode_Check(py_module) ) { py_umodule = PyUnicode_AsUTF8String(py_module); module = PyStr_AsString(py_umodule); } else if ( PyStr_Check(py_module) ) { module = PyStr_AsString(py_module); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "udf module argument must be a string or unicode string"); goto CLEANUP; } if ( PyUnicode_Check(py_function) ) { py_ufunction = PyUnicode_AsUTF8String(py_function); function = PyStr_AsString(py_ufunction); } else if ( PyStr_Check(py_function) ) { function = PyStr_AsString(py_function); } else { as_error_update(&err, AEROSPIKE_ERR_CLIENT, "function name must be a string or unicode string"); goto CLEANUP; } // Invoke operation aerospike_key_apply(self->as, &err, apply_policy_p, &key, module, function, arglist, &result); if ( err.code == AEROSPIKE_OK ) { val_to_pyobject(&err, result, &py_result); } else { as_error_update(&err, err.code, NULL); } CLEANUP: if (py_umodule) { Py_DECREF(py_umodule); } if (py_ufunction) { Py_DECREF(py_ufunction); } if (key_initialised == true) { // Destroy the key if it is initialised successfully. as_key_destroy(&key); } as_list_destroy(arglist); as_val_destroy(result); if ( err.code != AEROSPIKE_OK ) { PyObject * py_err = NULL; error_to_pyobject(&err, &py_err); PyObject *exception_type = raise_exception(&err); if(PyObject_HasAttrString(exception_type, "key")) { PyObject_SetAttrString(exception_type, "key", py_key); } if(PyObject_HasAttrString(exception_type, "bin")) { PyObject_SetAttrString(exception_type, "bin", Py_None); } if(PyObject_HasAttrString(exception_type, "module")) { PyObject_SetAttrString(exception_type, "module", py_module); } if(PyObject_HasAttrString(exception_type, "func")) { PyObject_SetAttrString(exception_type, "func", py_function); } PyErr_SetObject(exception_type, py_err); Py_DECREF(py_err); return NULL; } return py_result; }