[svn] commit: r2257 - in /experiments/python-binding/src/lib/dns/python: rdata_python.cc rrtype_python.cc tests/rdata_python_test.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jun 24 07:52:45 UTC 2010
Author: jelte
Date: Thu Jun 24 07:52:45 2010
New Revision: 2257
Log:
use c++ style casts. Most of them are reinterpret_casts because of the way we used the strucutres in c-style as well, will change in next commit
Modified:
experiments/python-binding/src/lib/dns/python/rdata_python.cc
experiments/python-binding/src/lib/dns/python/rrtype_python.cc
experiments/python-binding/src/lib/dns/python/tests/rdata_python_test.py
Modified: experiments/python-binding/src/lib/dns/python/rdata_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/rdata_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/rdata_python.cc Thu Jun 24 07:52:45 2010
@@ -60,6 +60,7 @@
// is a PyObject*, for the str() function in python.
static PyObject* Rdata_str(PyObject* self);
static PyObject* Rdata_toWire(s_Rdata* self, PyObject* args);
+static PyObject* RData_richcmp(s_Rdata* self, s_Rdata* other, int op);
// This list contains the actual set of functions we have in
// python. Each entry has
@@ -108,7 +109,7 @@
"a set of common interfaces to manipulate concrete RDATA objects.",
NULL, // tp_traverse
NULL, // tp_clear
- NULL, // tp_richcompare
+ (richcmpfunc)RData_richcmp, // tp_richcompare
0, // tp_weaklistoffset
NULL, // tp_iter
NULL, // tp_iternext
@@ -202,6 +203,49 @@
return NULL;
}
+
+
+static PyObject*
+RData_richcmp(s_Rdata* self, s_Rdata* other, int op) {
+ bool c;
+
+ // Check for null and if the types match. If different type,
+ // simply return False
+ if (!other || (self->ob_type != other->ob_type)) {
+ Py_RETURN_FALSE;
+ }
+
+ switch (op) {
+ case Py_LT:
+ c = self->rdata->compare(*other->rdata) < 0;
+ break;
+ case Py_LE:
+ c = self->rdata->compare(*other->rdata) < 0 ||
+ self->rdata->compare(*other->rdata) == 0;
+ break;
+ case Py_EQ:
+ c = self->rdata->compare(*other->rdata) == 0;
+ break;
+ case Py_NE:
+ c = self->rdata->compare(*other->rdata) != 0;
+ break;
+ case Py_GT:
+ c = self->rdata->compare(*other->rdata) > 0;
+ break;
+ case Py_GE:
+ c = self->rdata->compare(*other->rdata) > 0 ||
+ self->rdata->compare(*other->rdata) == 0;
+ break;
+ default:
+ PyErr_SetString(PyExc_IndexError,
+ "Unhandled rich comparison operator");
+ return NULL;
+ }
+ if (c)
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
// end of Rdata
Modified: experiments/python-binding/src/lib/dns/python/rrtype_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/rrtype_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/rrtype_python.cc Thu Jun 24 07:52:45 2010
@@ -57,52 +57,29 @@
RRType_toText(s_RRType* self);
// This is a second version of toText, we need one where the argument
// is a PyObject*, for the str() function in python.
-static PyObject*
-RRType_str(PyObject* self);
-static PyObject*
-RRType_toWire(s_RRType* self, PyObject* args);
-static PyObject*
-RRType_getCode(s_RRType* self);
-static PyObject*
-RRType_richcmp(s_RRType* self, s_RRType* other, int op);
-static PyObject*
-RRType_NSEC3PARAM(s_RRType *self);
-static PyObject*
-RRType_DNAME(s_RRType *self);
-static PyObject*
-RRType_PTR(s_RRType *self);
-static PyObject*
-RRType_MX(s_RRType *self);
-static PyObject*
-RRType_DNSKEY(s_RRType *self);
-static PyObject*
-RRType_TXT(s_RRType *self);
-static PyObject*
-RRType_RRSIG(s_RRType *self);
-static PyObject*
-RRType_NSEC(s_RRType *self);
-static PyObject*
-RRType_AAAA(s_RRType *self);
-static PyObject*
-RRType_DS(s_RRType *self);
-static PyObject*
-RRType_OPT(s_RRType *self);
-static PyObject*
-RRType_A(s_RRType *self);
-static PyObject*
-RRType_NS(s_RRType *self);
-static PyObject*
-RRType_CNAME(s_RRType *self);
-static PyObject*
-RRType_SOA(s_RRType *self);
-static PyObject*
-RRType_NSEC3(s_RRType *self);
-static PyObject*
-RRType_IXFR(s_RRType *self);
-static PyObject*
-RRType_AXFR(s_RRType *self);
-static PyObject*
-RRType_ANY(s_RRType *self);
+static PyObject* RRType_str(PyObject* self);
+static PyObject* RRType_toWire(s_RRType* self, PyObject* args);
+static PyObject* RRType_getCode(s_RRType* self);
+static PyObject* RRType_richcmp(s_RRType* self, s_RRType* other, int op);
+static PyObject* RRType_NSEC3PARAM(s_RRType *self);
+static PyObject* RRType_DNAME(s_RRType *self);
+static PyObject* RRType_PTR(s_RRType *self);
+static PyObject* RRType_MX(s_RRType *self);
+static PyObject* RRType_DNSKEY(s_RRType *self);
+static PyObject* RRType_TXT(s_RRType *self);
+static PyObject* RRType_RRSIG(s_RRType *self);
+static PyObject* RRType_NSEC(s_RRType *self);
+static PyObject* RRType_AAAA(s_RRType *self);
+static PyObject* RRType_DS(s_RRType *self);
+static PyObject* RRType_OPT(s_RRType *self);
+static PyObject* RRType_A(s_RRType *self);
+static PyObject* RRType_NS(s_RRType *self);
+static PyObject* RRType_CNAME(s_RRType *self);
+static PyObject* RRType_SOA(s_RRType *self);
+static PyObject* RRType_NSEC3(s_RRType *self);
+static PyObject* RRType_IXFR(s_RRType *self);
+static PyObject* RRType_AXFR(s_RRType *self);
+static PyObject* RRType_ANY(s_RRType *self);
// This list contains the actual set of functions we have in
// python. Each entry has
@@ -356,11 +333,12 @@
// Common function for RRType_A/NS/etc.
//
static PyObject* RRType_createStatic(RRType stc) {
- s_RRType* ret = PyObject_New(s_RRType, &rrclass_type);
+ s_RRType* ret = PyObject_New(s_RRType, &rrtype_type);
if (ret != NULL) {
ret->rrtype = new RRType(stc);
}
- return static_cast<PyObject*>(ret);
+ //return static_cast<PyObject*>(ret);
+ return (ret);
}
static PyObject*
Modified: experiments/python-binding/src/lib/dns/python/tests/rdata_python_test.py
==============================================================================
--- experiments/python-binding/src/lib/dns/python/tests/rdata_python_test.py (original)
+++ experiments/python-binding/src/lib/dns/python/tests/rdata_python_test.py Thu Jun 24 07:52:45 2010
@@ -57,5 +57,14 @@
self.assertEqual("\"asdfasdfasdf\"", self.rdata3.to_text())
self.assertEqual("\"foo\"", self.rdata4.to_text())
+ def test_richcmp(self):
+ self.assertTrue(self.rdata1 < self.rdata2);
+ self.assertTrue(self.rdata1 <= self.rdata2);
+ self.assertFalse(self.rdata1 > self.rdata2);
+ self.assertFalse(self.rdata1 >= self.rdata2);
+ self.assertTrue(self.rdata3 != self.rdata4)
+ other_rdata = Rdata(RRType("TXT"), RRClass("IN"), "foo")
+ self.assertTrue(self.rdata4 == other_rdata)
+
if __name__ == '__main__':
unittest.main()
More information about the bind10-changes
mailing list