Commit b5f72e06 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

statics for known classes too


git-svn-id: svn://bind10.isc.org/svn/bind10/experiments/python-binding@2094 e5f2f494-b856-4b98-b285-d166d9295462
parent 2074ba32
......@@ -61,6 +61,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
// 1. Python method name
......@@ -79,6 +87,11 @@ static PyMethodDef RRClass_methods[] = {
"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 @@ RRClass_richcmp(s_RRClass* self, s_RRClass* other, int op)
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
......
......@@ -23,8 +23,8 @@ from libdns_python import *
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 @@ class RRClassTest(unittest.TestCase):
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()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment