From: Mukund Sivaraman Date: Tue, 4 Feb 2014 05:10:12 +0000 (+0530) Subject: [2518] Update common DNS exceptions into a hierarchy X-Git-Tag: bind10-1.2.0beta1-release~48^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ad3f1d33b943410cc4b782be9f07a4083883ea71;p=thirdparty%2Fkea.git [2518] Update common DNS exceptions into a hierarchy --- diff --git a/src/lib/dns/python/name_python.cc b/src/lib/dns/python/name_python.cc index e1ff5fe926..ecdae841c3 100644 --- a/src/lib/dns/python/name_python.cc +++ b/src/lib/dns/python/name_python.cc @@ -545,7 +545,6 @@ PyObject* po_BadLabelType; PyObject* po_BadEscape; PyObject* po_IncompleteName; PyObject* po_InvalidBufferPosition; -PyObject* po_DNSMessageFORMERR; // // Definition of enums diff --git a/src/lib/dns/python/name_python.h b/src/lib/dns/python/name_python.h index 27961387c3..2cce9994cc 100644 --- a/src/lib/dns/python/name_python.h +++ b/src/lib/dns/python/name_python.h @@ -31,7 +31,6 @@ extern PyObject* po_BadLabelType; extern PyObject* po_BadEscape; extern PyObject* po_IncompleteName; extern PyObject* po_InvalidBufferPosition; -extern PyObject* po_DNSMessageFORMERR; // // Declaration of enums diff --git a/src/lib/dns/python/pydnspp.cc b/src/lib/dns/python/pydnspp.cc index 29d770d024..b0bda22c4b 100644 --- a/src/lib/dns/python/pydnspp.cc +++ b/src/lib/dns/python/pydnspp.cc @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -152,8 +153,14 @@ initModulePart_Message(PyObject* mod) { PyErr_NewException("pydnspp.InvalidMessageUDPSize", NULL, NULL); PyObjectContainer(po_InvalidMessageUDPSize).installToModule( mod, "InvalidMessageUDPSize"); + po_DNSMessageFORMERR = + PyErr_NewException("pydnspp.DNSMessageFORMERR", + po_DNSProtocolError, NULL); + PyObjectContainer(po_DNSMessageFORMERR).installToModule( + mod, "DNSMessageFORMERR"); po_DNSMessageBADVERS = - PyErr_NewException("pydnspp.DNSMessageBADVERS", NULL, NULL); + PyErr_NewException("pydnspp.DNSMessageBADVERS", + po_DNSProtocolError, NULL); PyObjectContainer(po_DNSMessageBADVERS).installToModule( mod, "DNSMessageBADVERS"); po_UnknownNSEC3HashAlgorithm = @@ -245,7 +252,7 @@ initModulePart_Name(PyObject* mod) { try { po_NameParserException = PyErr_NewException("pydnspp.NameParserException", - po_IscException, NULL); + po_DNSTextError, NULL); PyObjectContainer(po_NameParserException) .installToModule(mod, "NameParserException"); @@ -277,13 +284,6 @@ initModulePart_Name(PyObject* mod) { PyErr_NewException("pydnspp.InvalidBufferPosition", NULL, NULL); PyObjectContainer(po_InvalidBufferPosition).installToModule( mod, "InvalidBufferPosition"); - - // This one could have gone into the message_python.cc file, but is - // already needed here. - po_DNSMessageFORMERR = PyErr_NewException("pydnspp.DNSMessageFORMERR", - NULL, NULL); - PyObjectContainer(po_DNSMessageFORMERR).installToModule( - mod, "DNSMessageFORMERR"); } catch (const std::exception& ex) { const std::string ex_what = "Unexpected failure in Name initialization: " + @@ -878,12 +878,29 @@ PyInit_pydnspp(void) { po_InvalidOperation = PyErr_NewException("pydnspp.InvalidOperation", po_IscException, NULL); PyObjectContainer(po_InvalidOperation) - .installToModule(mod, "InvalidOperation"); + .installToModule(mod, "InvalidOperation"); po_InvalidParameter = PyErr_NewException("pydnspp.InvalidParameter", po_IscException, NULL); PyObjectContainer(po_InvalidParameter) - .installToModule(mod, "InvalidParameter"); + .installToModule(mod, "InvalidParameter"); + + // Add DNS exceptions + po_DNSException = PyErr_NewException("pydnspp.DNSException", + po_IscException, NULL); + PyObjectContainer(po_DNSException) + .installToModule(mod, "DNSException"); + + po_DNSTextError = PyErr_NewException("pydnspp.DNSTextError", + po_DNSException, NULL); + PyObjectContainer(po_DNSTextError) + .installToModule(mod, "DNSTextError"); + + po_DNSProtocolError = PyErr_NewException("pydnspp.DNSProtocolError", + po_DNSException, NULL); + PyObjectContainer(po_DNSProtocolError) + .installToModule(mod, "DNSProtocolError"); + } catch (const std::exception& ex) { const std::string ex_what = "Unexpected failure in pydnspp initialization: " + diff --git a/src/lib/dns/python/pydnspp_common.cc b/src/lib/dns/python/pydnspp_common.cc index 4250db7601..c95f87765e 100644 --- a/src/lib/dns/python/pydnspp_common.cc +++ b/src/lib/dns/python/pydnspp_common.cc @@ -50,7 +50,11 @@ PyObject* po_IscException; PyObject* po_InvalidOperation; PyObject* po_InvalidParameter; -// For our own isc::dns::Exception +// For DNS exceptions +PyObject* po_DNSException; +PyObject* po_DNSTextError; +PyObject* po_DNSProtocolError; +PyObject* po_DNSMessageFORMERR; PyObject* po_DNSMessageBADVERS; diff --git a/src/lib/dns/python/pydnspp_common.h b/src/lib/dns/python/pydnspp_common.h index 8e498b3f93..b33125e09c 100644 --- a/src/lib/dns/python/pydnspp_common.h +++ b/src/lib/dns/python/pydnspp_common.h @@ -32,6 +32,10 @@ extern PyObject* po_InvalidOperation; extern PyObject* po_InvalidParameter; // For our own isc::dns::Exception +extern PyObject* po_DNSException; +extern PyObject* po_DNSTextError; +extern PyObject* po_DNSProtocolError; +extern PyObject* po_DNSMessageFORMERR; extern PyObject* po_DNSMessageBADVERS; // This function reads 'bytes' from a sequence diff --git a/src/lib/dns/python/rdata_python.cc b/src/lib/dns/python/rdata_python.cc index 20f67c8d7e..df45e9ef9d 100644 --- a/src/lib/dns/python/rdata_python.cc +++ b/src/lib/dns/python/rdata_python.cc @@ -25,6 +25,7 @@ #include "rrclass_python.h" #include "messagerenderer_python.h" #include "name_python.h" +#include "pydnspp_common.h" using namespace isc::dns; using namespace isc::dns::python; diff --git a/src/lib/dns/python/tests/name_python_test.py b/src/lib/dns/python/tests/name_python_test.py index 86b1edc074..8160716896 100644 --- a/src/lib/dns/python/tests/name_python_test.py +++ b/src/lib/dns/python/tests/name_python_test.py @@ -105,6 +105,8 @@ class NameTest(unittest.TestCase): self.assertTrue(isinstance(TooLongName(), NameParserException)) self.assertTrue(isinstance(IncompleteName(), NameParserException)) + self.assertTrue(isinstance(NameParserException(), DNSTextError)) + def test_at(self): self.assertEqual(7, self.name1.at(0)) self.assertEqual(101, self.name1.at(1)) diff --git a/src/lib/dns/python/tests/pydnspp_python_test.py b/src/lib/dns/python/tests/pydnspp_python_test.py index af9db52efc..574fc00e00 100644 --- a/src/lib/dns/python/tests/pydnspp_python_test.py +++ b/src/lib/dns/python/tests/pydnspp_python_test.py @@ -26,5 +26,9 @@ class CommonTest(unittest.TestCase): self.assertTrue(isinstance(InvalidOperation(), IscException)) self.assertTrue(isinstance(InvalidParameter(), IscException)) + self.assertTrue(isinstance(DNSException(), IscException)) + self.assertTrue(isinstance(DNSTextError(), DNSException)) + self.assertTrue(isinstance(DNSProtocolError(), DNSException)) + if __name__ == '__main__': unittest.main()