From: Mukund Sivaraman Date: Tue, 4 Feb 2014 04:44:31 +0000 (+0530) Subject: [2518] Add Python bindings for NameParserException hierarchy X-Git-Tag: bind10-1.2.0beta1-release~48^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=de4c5e0913d80405f1795293ba28d63a5154eb60;p=thirdparty%2Fkea.git [2518] Add Python bindings for NameParserException hierarchy --- diff --git a/src/lib/dns/python/name_python.cc b/src/lib/dns/python/name_python.cc index 2799db9fde..e1ff5fe926 100644 --- a/src/lib/dns/python/name_python.cc +++ b/src/lib/dns/python/name_python.cc @@ -537,6 +537,7 @@ namespace python { // Initialization and addition of these go in the module init at the // end // +PyObject* po_NameParserException; PyObject* po_EmptyLabel; PyObject* po_TooLongName; PyObject* po_TooLongLabel; diff --git a/src/lib/dns/python/name_python.h b/src/lib/dns/python/name_python.h index d18c0d9385..27961387c3 100644 --- a/src/lib/dns/python/name_python.h +++ b/src/lib/dns/python/name_python.h @@ -23,6 +23,7 @@ class Name; namespace python { +extern PyObject* po_NameParserException; extern PyObject* po_EmptyLabel; extern PyObject* po_TooLongName; extern PyObject* po_TooLongLabel; diff --git a/src/lib/dns/python/pydnspp.cc b/src/lib/dns/python/pydnspp.cc index 30dc09089c..f061783cb2 100644 --- a/src/lib/dns/python/pydnspp.cc +++ b/src/lib/dns/python/pydnspp.cc @@ -243,23 +243,33 @@ initModulePart_Name(PyObject* mod) { // Add the exceptions to the module try { - po_EmptyLabel = PyErr_NewException("pydnspp.EmptyLabel", NULL, NULL); + po_NameParserException = + PyErr_NewException("pydnspp.NameParserException", NULL, NULL); + PyObjectContainer(po_NameParserException) + .installToModule(mod, "NameParserException"); + + po_EmptyLabel = PyErr_NewException("pydnspp.EmptyLabel", + po_NameParserException, NULL); PyObjectContainer(po_EmptyLabel).installToModule(mod, "EmptyLabel"); - po_TooLongName = PyErr_NewException("pydnspp.TooLongName", NULL, NULL); + po_TooLongName = PyErr_NewException("pydnspp.TooLongName", + po_NameParserException, NULL); PyObjectContainer(po_TooLongName).installToModule(mod, "TooLongName"); - po_TooLongLabel = PyErr_NewException("pydnspp.TooLongLabel", NULL, NULL); + po_TooLongLabel = PyErr_NewException("pydnspp.TooLongLabel", + po_NameParserException, NULL); PyObjectContainer(po_TooLongLabel).installToModule(mod, "TooLongLabel"); - po_BadLabelType = PyErr_NewException("pydnspp.BadLabelType", NULL, NULL); + po_BadLabelType = PyErr_NewException("pydnspp.BadLabelType", + po_NameParserException, NULL); PyObjectContainer(po_BadLabelType).installToModule(mod, "BadLabelType"); - po_BadEscape = PyErr_NewException("pydnspp.BadEscape", NULL, NULL); + po_BadEscape = PyErr_NewException("pydnspp.BadEscape", + po_NameParserException, NULL); PyObjectContainer(po_BadEscape).installToModule(mod, "BadEscape"); - po_IncompleteName = PyErr_NewException("pydnspp.IncompleteName", NULL, - NULL); + po_IncompleteName = PyErr_NewException("pydnspp.IncompleteName", + po_NameParserException, NULL); PyObjectContainer(po_IncompleteName).installToModule(mod, "IncompleteName"); po_InvalidBufferPosition = diff --git a/src/lib/dns/python/tests/name_python_test.py b/src/lib/dns/python/tests/name_python_test.py index 8ea2e3520a..051abb9b6b 100644 --- a/src/lib/dns/python/tests/name_python_test.py +++ b/src/lib/dns/python/tests/name_python_test.py @@ -97,6 +97,14 @@ class NameTest(unittest.TestCase): self.assertRaises(DNSMessageFORMERR, Name, b, 0) self.assertRaises(IndexError, Name, b, -1) + def test_exception_hierarchy(self): + self.assertTrue(isinstance(EmptyLabel(), NameParserException)) + self.assertTrue(isinstance(TooLongLabel(), NameParserException)) + self.assertTrue(isinstance(BadLabelType(), NameParserException)) + self.assertTrue(isinstance(BadEscape(), NameParserException)) + self.assertTrue(isinstance(TooLongName(), NameParserException)) + self.assertTrue(isinstance(IncompleteName(), NameParserException)) + def test_at(self): self.assertEqual(7, self.name1.at(0)) self.assertEqual(101, self.name1.at(1))