[svn] commit: r3341 - /branches/trac375/src/lib/datasrc/python/pydatasrc.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Oct 25 08:15:10 UTC 2010
Author: jelte
Date: Mon Oct 25 08:15:09 2010
New Revision: 3341
Log:
minor style cleanups
better error if pydnspp module is not in pythonpath when pydatasrc is loaded
Modified:
branches/trac375/src/lib/datasrc/python/pydatasrc.cc
Modified: branches/trac375/src/lib/datasrc/python/pydatasrc.cc
==============================================================================
--- branches/trac375/src/lib/datasrc/python/pydatasrc.cc (original)
+++ branches/trac375/src/lib/datasrc/python/pydatasrc.cc Mon Oct 25 08:15:09 2010
@@ -291,7 +291,7 @@
NULL, // tp_setattro
NULL, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags
- "TODO",
+ "DNS Data Source structure",
NULL, // tp_traverse
NULL, // tp_clear
NULL, // tp_richcompare
@@ -353,7 +353,7 @@
NULL, // tp_setattro
NULL, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags
- "TODO",
+ "State and data container for a DataSrc transaction",
NULL, // tp_traverse
NULL, // tp_clear
NULL, // tp_richcompare
@@ -423,8 +423,8 @@
Py_TYPE(self)->tp_free(self);
}
-/* conversion functions, also usable by other modules
- * (TODO: move to separate file)
+/*
+ * conversion helper functions
*/
isc::dns::Name
PyName_AsName(PyObject* name_obj)
@@ -532,7 +532,10 @@
// for Rdata we have no getClass and getType, so we need to provide these
PyObject*
-PyRRTTL_CreateRdata(const isc::dns::RRType& rrtype, const isc::dns::RRClass& rrclass, const isc::dns::rdata::Rdata& rdata) {
+PyRRTTL_CreateRdata(const isc::dns::RRType& rrtype,
+ const isc::dns::RRClass& rrclass,
+ const isc::dns::rdata::Rdata& rdata)
+{
PyObject* rdata_class = PyObject_GetAttrString(po_DNS_module, "Rdata");
PyObject* type_obj = PyRRType_FromRRType(rrtype);
PyObject* class_obj = PyRRClass_FromRRClass(rrclass);
@@ -549,7 +552,9 @@
// for Rdata we have no getClass and getType, so we need to provide these
isc::dns::rdata::ConstRdataPtr
-PyRdata_AsRdataPtr(const isc::dns::RRType& rrtype, const isc::dns::RRClass& rrclass, PyObject* rdata_obj)
+PyRdata_AsRdataPtr(const isc::dns::RRType& rrtype,
+ const isc::dns::RRClass& rrclass,
+ PyObject* rdata_obj)
{
PyObject* rdata_obj_str = PyObject_CallMethod(rdata_obj,
const_cast<char*>("to_text"),
@@ -759,12 +764,12 @@
PyObject *name_obj, *class_obj, *type_obj, *result_list_obj, *zone_name_obj;
uint32_t flags;
int args_check = PyArg_ParseTuple(args, "O!O!O!OIO!",
- name_class, &name_obj,
- rrclass_class, &class_obj,
- rrtype_class, &type_obj,
- &result_list_obj,
- &flags,
- name_class, &zone_name_obj);
+ name_class, &name_obj,
+ rrclass_class, &class_obj,
+ rrtype_class, &type_obj,
+ &result_list_obj,
+ &flags,
+ name_class, &zone_name_obj);
Py_DECREF(name_class);
Py_DECREF(rrclass_class);
Py_DECREF(rrtype_class);
@@ -1027,8 +1032,8 @@
&datasrc_transaction_type, &transaction,
&rrset_obj)) {
isc::dns::ConstRRsetPtr rrset_ptr = PyRRset_AsRRsetPtr(rrset_obj);
-
- PyObject* result = Py_BuildValue(0,
+
+ PyObject* result = Py_BuildValue("I",
self->datasrc->delRRset(
*(transaction->datasrc_transaction),
rrset_ptr));
@@ -1065,7 +1070,7 @@
isc::dns::RRsetPtr
callback_iterator(void* arg1, void* arg2)
{
- PyObject* iterator = reinterpret_cast<PyObject*>(arg1);
+ PyObject* iterator = static_cast<PyObject*>(arg1);
PyObject* rrset_obj = PyIter_Next(iterator);
if (rrset_obj) {
if (PyRRset_Check(rrset_obj)) {
@@ -1112,8 +1117,11 @@
&rrset_list, &i));
return (result);
} else if (PyCallable_Check(rrset_list_or_function_obj)) {
- PyObject* iterator = PyObject_CallFunctionObjArgs(rrset_list_or_function_obj, arg1, arg2, NULL);
+ PyObject* iterator = PyObject_CallFunctionObjArgs(
+ rrset_list_or_function_obj,
+ arg1, arg2, NULL);
if (!iterator) {
+ // specific exception should already be set
return (NULL);
}
if (!PyIter_Check(iterator)) {
@@ -1257,10 +1265,6 @@
static int
DataSrcTransaction_new(s_DataSrcTransaction* self, PyObject* args) {
- // TODO: hardcoded to sqlite3 data source right now.
- // We need name->datasource type mapping. possibly
- // have datasource implementation be done as ldopen() loadable
- // modules. discuss.
s_DataSrc* data_source;
PyObject* nameType = PyObject_GetAttrString(po_DNS_module, "Name");
PyObject* po_name;
@@ -1277,6 +1281,10 @@
PyObject *str_enc = PyUnicode_AsEncodedString(str_obj,
"utf-8",
"Error");
+ if (!str_enc) {
+ // Exception raised by codec, pass it on.
+ return (NULL);
+ }
isc::dns::Name rrname(PyBytes_AS_STRING(str_enc));
Py_DECREF(str_obj);
Py_DECREF(str_enc);
@@ -1366,7 +1374,10 @@
// import dns module for converting types
// TODO: if lib not in path this raises 'unreported exception'
po_DNS_module = PyImport_ImportModule("pydnspp");
- //std::cout << dns_mod << std::endl;
+ if (!po_DNS_module) {
+ PyErr_SetString(PyExc_Exception, "pydnspp module not found in PYTHONPATH, needed by pydatasrc");
+ return NULL;
+ }
return (mod);
}
More information about the bind10-changes
mailing list