[svn] commit: r1813 - in /experiments/python-binding/src/lib/dns/python: ./ tests/

BIND 10 source code commits bind10-changes at lists.isc.org
Wed May 12 11:24:55 UTC 2010


Author: jelte
Date: Wed May 12 11:24:54 2010
New Revision: 1813

Log:
Added Message and Question wrappers
Updated messageenderer, rrset, and name wrappers

Added:
    experiments/python-binding/src/lib/dns/python/TODO
    experiments/python-binding/src/lib/dns/python/message_python.cc
    experiments/python-binding/src/lib/dns/python/question_python.cc
    experiments/python-binding/src/lib/dns/python/tests/message_python_test.py
    experiments/python-binding/src/lib/dns/python/tests/question_python_test.py
Modified:
    experiments/python-binding/src/lib/dns/python/libdns_python.cc
    experiments/python-binding/src/lib/dns/python/messagerenderer_python.cc
    experiments/python-binding/src/lib/dns/python/name_python.cc
    experiments/python-binding/src/lib/dns/python/rrset_python.cc
    experiments/python-binding/src/lib/dns/python/tests/libdns_python_test.in

Modified: experiments/python-binding/src/lib/dns/python/libdns_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/libdns_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/libdns_python.cc Wed May 12 11:24:54 2010
@@ -12,6 +12,7 @@
 // 
 #define PY_SSIZE_T_CLEAN
 #include <Python.h>
+#include <structmember.h>
 
 #include "config.h"
 
@@ -33,6 +34,8 @@
 #include "rrttl_python.cc"
 #include "rdata_python.cc"
 #include "rrset_python.cc"
+#include "question_python.cc"
+#include "message_python.cc"
 
 //
 // Definition of the module
@@ -87,6 +90,14 @@
         return NULL;
     }
 
+    if (!initModulePart_Question(mod)) {
+        return NULL;
+    }
+
+    if (!initModulePart_Message(mod)) {
+        return NULL;
+    }
+
     return mod;
 }
 

Modified: experiments/python-binding/src/lib/dns/python/messagerenderer_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/messagerenderer_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/messagerenderer_python.cc Wed May 12 11:24:54 2010
@@ -132,10 +132,11 @@
 static PyObject*
 MessageRenderer_isTruncated(s_MessageRenderer* self)
 {
-    if (self->messagerenderer->isTruncated())
+    if (self->messagerenderer->isTruncated()) {
         Py_RETURN_TRUE;
-    else
+    } else {
         Py_RETURN_FALSE;
+    }
 }
 
 static PyObject*

Modified: experiments/python-binding/src/lib/dns/python/name_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/name_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/name_python.cc Wed May 12 11:24:54 2010
@@ -461,6 +461,7 @@
     }
     return (PyObject*) ret;
 }
+#include <iostream>
 
 static PyObject* 
 Name_richcmp(s_Name* n1, s_Name* n2, int op)
@@ -489,10 +490,11 @@
     default:
         assert(0);              // XXX: should trigger an exception
     }
-    if (c)
+    if (c) {
         Py_RETURN_TRUE;
-    else
+    } else {
         Py_RETURN_FALSE;
+    }
 }
 
 static PyObject*

Modified: experiments/python-binding/src/lib/dns/python/rrset_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/rrset_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/rrset_python.cc Wed May 12 11:24:54 2010
@@ -67,7 +67,8 @@
 static PyObject* RRset_toText(s_RRset* self);
 static PyObject* RRset_toWire(s_RRset* self, PyObject* args);
 static PyObject* RRset_addRdata(s_RRset* self, PyObject* args);
-// TODO: iterator
+static PyObject* RRset_getRdata(s_RRset* self);
+// TODO: iterator?
 
 static PyMethodDef RRset_methods[] = {
     { "get_rdata_count", (PyCFunction)RRset_getRdataCount, METH_NOARGS, "Return the number of rdata fields" },
@@ -80,6 +81,7 @@
     { "to_text", (PyCFunction)RRset_toText, METH_NOARGS, "Return" },
     { "to_wire", (PyCFunction)RRset_toWire, METH_VARARGS, "Return" },
     { "add_rdata", (PyCFunction)RRset_addRdata, METH_VARARGS, "Return" },
+    { "get_rdata", (PyCFunction)RRset_getRdata, METH_NOARGS, "Returns a List containing all Rdata elements" },
     { NULL, NULL, 0, NULL }
 };
 
@@ -330,6 +332,31 @@
         return NULL;
     }
 }
+
+static PyObject*
+RRset_getRdata(s_RRset* self)
+{
+    PyObject* list = PyList_New(0);
+
+    RdataIteratorPtr it = self->rrset->getRdataIterator();
+
+    for (it->first(); !it->isLast(); it->next()) {
+        s_Rdata *rds = (s_Rdata*)rdata_type.tp_alloc(&rdata_type, 0);
+        if (rds != NULL) {
+            // hmz them iterators/shared_ptrs and private constructors
+            // make this a bit weird, so we create a new one with
+            // the data available
+            const Rdata *rd = &it->getCurrent();
+            rds->rdata = createRdata(self->rrset->getType(), self->rrset->getClass(), *rd);
+            PyList_Append(list, (PyObject*) rds);
+        } else {
+            return NULL;
+        }
+    }
+    
+    return list;
+}
+
 // end of RRset
 
 

Modified: experiments/python-binding/src/lib/dns/python/tests/libdns_python_test.in
==============================================================================
--- experiments/python-binding/src/lib/dns/python/tests/libdns_python_test.in (original)
+++ experiments/python-binding/src/lib/dns/python/tests/libdns_python_test.in Wed May 12 11:24:54 2010
@@ -8,7 +8,14 @@
 PYTHONPATH=@abs_top_srcdir@/src/lib/python:@abs_top_srcdir@/src/lib/dns/python/.libs
 export PYTHONPATH
 
+TESTDATA_PATH=@abs_top_srcdir@/src/lib/dns/tests/testdata
+export TESTDATA_PATH
+
 cd ${BIND10_PATH}
 ${PYTHON_EXEC} -O ${CONFIG_PATH}/rrtype_python_test.py $*
 
 ${PYTHON_EXEC} -O ${CONFIG_PATH}/rrset_python_test.py $*
+
+${PYTHON_EXEC} -O ${CONFIG_PATH}/question_python_test.py $*
+
+${PYTHON_EXEC} -O ${CONFIG_PATH}/message_python_test.py $*




More information about the bind10-changes mailing list