[svn] commit: r2099 - in /experiments/python-binding/src/lib/dns/python: name_python.cc tests/name_python_test.py
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed Jun 9 13:45:13 UTC 2010
Author: jelte
Date: Wed Jun 9 13:45:13 2010
New Revision: 2099
Log:
add wrapper and tests for the new Name::split(int) function
Modified:
experiments/python-binding/src/lib/dns/python/name_python.cc
experiments/python-binding/src/lib/dns/python/tests/name_python_test.py
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 Jun 9 13:45:13 2010
@@ -473,22 +473,37 @@
Name_split(s_Name* self, PyObject* args)
{
unsigned int first, n;
-
- if (!PyArg_ParseTuple(args, "II", &first, &n))
- return NULL;
-
- s_Name* ret = PyObject_New(s_Name, &name_type);
- if (ret != NULL) {
- ret->name = NULL;
- try {
- ret->name = new Name(self->name->split(first, n));
- } catch(isc::OutOfRange oor) {
- PyErr_SetString(PyExc_IndexError, oor.what());
+ s_Name* ret = NULL;
+
+ if (PyArg_ParseTuple(args, "II", &first, &n)) {
+ ret = PyObject_New(s_Name, &name_type);
+ if (ret != NULL) {
ret->name = NULL;
- }
- if (ret->name == NULL) {
- Py_DECREF(ret);
- return NULL;
+ try {
+ ret->name = new Name(self->name->split(first, n));
+ } catch(isc::OutOfRange oor) {
+ PyErr_SetString(PyExc_IndexError, oor.what());
+ ret->name = NULL;
+ }
+ if (ret->name == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ }
+ } else if (PyArg_ParseTuple(args, "I", &n)) {
+ ret = PyObject_New(s_Name, &name_type);
+ if (ret != NULL) {
+ ret->name = NULL;
+ try {
+ ret->name = new Name(self->name->split(n));
+ } catch(isc::OutOfRange oor) {
+ PyErr_SetString(PyExc_IndexError, oor.what());
+ ret->name = NULL;
+ }
+ if (ret->name == NULL) {
+ Py_DECREF(ret);
+ return NULL;
+ }
}
}
return (PyObject*) ret;
Modified: experiments/python-binding/src/lib/dns/python/tests/name_python_test.py
==============================================================================
--- experiments/python-binding/src/lib/dns/python/tests/name_python_test.py (original)
+++ experiments/python-binding/src/lib/dns/python/tests/name_python_test.py Wed Jun 9 13:45:13 2010
@@ -141,10 +141,14 @@
self.assertEqual("completely.different.", s.to_text())
self.assertRaises(TypeError, self.name1.split, "wrong", 1)
self.assertRaises(TypeError, self.name1.split, 1, "wrong")
- # TODO: this test will fail when new split(int) is added
- self.assertRaises(TypeError, self.name1.split, 1)
self.assertRaises(IndexError, self.name1.split, 123, 1)
self.assertRaises(IndexError, self.name1.split, 1, 123)
+
+ s = self.name1.split(1)
+ self.assertEqual("com.", s.to_text())
+ s = self.name1.split(0)
+ self.assertEqual("example.com.", s.to_text())
+ self.assertRaises(IndexError, self.name1.split, 123)
def test_reverse(self):
self.assertEqual("com.example.", self.name1.reverse().to_text())
More information about the bind10-changes
mailing list