[svn] commit: r2094 - in /experiments/python-binding/src/lib/dns/python: rrclass_python.cc tests/rrclass_python_test.py

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Jun 8 12:43:42 UTC 2010


Author: jelte
Date: Tue Jun  8 12:43:41 2010
New Revision: 2094

Log:
statics for known classes too

Modified:
    experiments/python-binding/src/lib/dns/python/rrclass_python.cc
    experiments/python-binding/src/lib/dns/python/tests/rrclass_python_test.py

Modified: experiments/python-binding/src/lib/dns/python/rrclass_python.cc
==============================================================================
--- experiments/python-binding/src/lib/dns/python/rrclass_python.cc (original)
+++ experiments/python-binding/src/lib/dns/python/rrclass_python.cc Tue Jun  8 12:43:41 2010
@@ -60,6 +60,14 @@
 static PyObject* RRClass_toWire(s_RRClass* self, PyObject* args);
 static PyObject* RRClass_getCode(s_RRClass* self);
 static PyObject* RRClass_richcmp(s_RRClass* self, s_RRClass* other, int op);
+
+// Static function for direct class creation
+static PyObject* RRClass_IN(s_RRClass *self);
+static PyObject* RRClass_CH(s_RRClass *self);
+static PyObject* RRClass_HS(s_RRClass *self);
+static PyObject* RRClass_NONE(s_RRClass *self);
+static PyObject* RRClass_ANY(s_RRClass *self);
+
 
 // This list contains the actual set of functions we have in
 // python. Each entry has
@@ -79,6 +87,11 @@
       "returned" },
     { "get_code", (PyCFunction)RRClass_getCode, METH_NOARGS,
       "Returns the class code as an integer" },
+    { "IN", (PyCFunction)RRClass_IN, METH_NOARGS | METH_STATIC, "Creates an IN RRClass" },
+    { "CH", (PyCFunction)RRClass_CH, METH_NOARGS | METH_STATIC, "Creates a CH RRClass" },
+    { "HS", (PyCFunction)RRClass_HS, METH_NOARGS | METH_STATIC, "Creates an HS RRClass" },
+    { "NONE", (PyCFunction)RRClass_NONE, METH_NOARGS | METH_STATIC, "Creates a NONE RRClass" },
+    { "ANY", (PyCFunction)RRClass_ANY, METH_NOARGS | METH_STATIC, "Creates an ANY RRClass" },
     { NULL, NULL, 0, NULL }
 };
 
@@ -289,6 +302,71 @@
     else
         Py_RETURN_FALSE;
 }
+
+static PyObject* RRClass_IN(s_RRClass *self UNUSED_PARAM)
+{
+    s_RRClass* ret = PyObject_New(s_RRClass, &rrclass_type);
+    if (ret != NULL) {
+        ret->rrclass = new RRClass(RRClass::IN());
+        if (ret->rrclass == NULL) {
+            Py_DECREF(ret);
+            return NULL;
+        }
+    }
+    return (PyObject*) ret;
+}
+
+static PyObject* RRClass_CH(s_RRClass *self UNUSED_PARAM)
+{
+    s_RRClass* ret = PyObject_New(s_RRClass, &rrclass_type);
+    if (ret != NULL) {
+        ret->rrclass = new RRClass(RRClass::CH());
+        if (ret->rrclass == NULL) {
+            Py_DECREF(ret);
+            return NULL;
+        }
+    }
+    return (PyObject*) ret;
+}
+
+static PyObject* RRClass_HS(s_RRClass *self UNUSED_PARAM)
+{
+    s_RRClass* ret = PyObject_New(s_RRClass, &rrclass_type);
+    if (ret != NULL) {
+        ret->rrclass = new RRClass(RRClass::HS());
+        if (ret->rrclass == NULL) {
+            Py_DECREF(ret);
+            return NULL;
+        }
+    }
+    return (PyObject*) ret;
+}
+
+static PyObject* RRClass_NONE(s_RRClass *self UNUSED_PARAM)
+{
+    s_RRClass* ret = PyObject_New(s_RRClass, &rrclass_type);
+    if (ret != NULL) {
+        ret->rrclass = new RRClass(RRClass::NONE());
+        if (ret->rrclass == NULL) {
+            Py_DECREF(ret);
+            return NULL;
+        }
+    }
+    return (PyObject*) ret;
+}
+
+static PyObject* RRClass_ANY(s_RRClass *self UNUSED_PARAM)
+{
+    s_RRClass* ret = PyObject_New(s_RRClass, &rrclass_type);
+    if (ret != NULL) {
+        ret->rrclass = new RRClass(RRClass::ANY());
+        if (ret->rrclass == NULL) {
+            Py_DECREF(ret);
+            return NULL;
+        }
+    }
+    return (PyObject*) ret;
+}
 // end of RRClass
 
 

Modified: experiments/python-binding/src/lib/dns/python/tests/rrclass_python_test.py
==============================================================================
--- experiments/python-binding/src/lib/dns/python/tests/rrclass_python_test.py (original)
+++ experiments/python-binding/src/lib/dns/python/tests/rrclass_python_test.py Tue Jun  8 12:43:41 2010
@@ -23,8 +23,8 @@
 
 class RRClassTest(unittest.TestCase):
     def setUp(self):
-        self.c1 = RRClass("IN")
-        self.c2 = RRClass("CH")
+        self.c1 = RRClass.IN()
+        self.c2 = RRClass.CH()
 
     def test_init(self):
         self.assertRaises(InvalidRRClass, RRClass, "wrong")
@@ -64,5 +64,12 @@
         self.assertFalse(self.c1 > self.c2)
         self.assertFalse(self.c1 >= self.c2)
 
+    def test_statics(self):
+        self.assertEqual(RRClass.IN(), RRClass("IN"))
+        self.assertEqual(RRClass.CH(), RRClass("CH"))
+        self.assertEqual(RRClass.HS(), RRClass("HS"))
+        self.assertEqual(254, RRClass.NONE().get_code())
+        self.assertEqual(255, RRClass.ANY().get_code())
+
 if __name__ == '__main__':
     unittest.main()




More information about the bind10-changes mailing list