]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2518] Update common DNS exceptions into a hierarchy
authorMukund Sivaraman <muks@isc.org>
Tue, 4 Feb 2014 05:10:12 +0000 (10:40 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 4 Feb 2014 05:16:51 +0000 (10:46 +0530)
src/lib/dns/python/name_python.cc
src/lib/dns/python/name_python.h
src/lib/dns/python/pydnspp.cc
src/lib/dns/python/pydnspp_common.cc
src/lib/dns/python/pydnspp_common.h
src/lib/dns/python/rdata_python.cc
src/lib/dns/python/tests/name_python_test.py
src/lib/dns/python/tests/pydnspp_python_test.py

index e1ff5fe92679e242ba561fd9ea3d4eeb441c529d..ecdae841c3f9e7c60d152e6f45f91814dd32c6a8 100644 (file)
@@ -545,7 +545,6 @@ PyObject* po_BadLabelType;
 PyObject* po_BadEscape;
 PyObject* po_IncompleteName;
 PyObject* po_InvalidBufferPosition;
-PyObject* po_DNSMessageFORMERR;
 
 //
 // Definition of enums
index 27961387c3e55618c06933dbf3e595dd911ea316..2cce9994cc73280009818f68db2cd35b480efc2e 100644 (file)
@@ -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
index 29d770d024b034eb674e9ed2d9ed0fd652a08f04..b0bda22c4bc20dd66399c73980c5dde39aac1633 100644 (file)
@@ -28,6 +28,7 @@
 #include <Python.h>
 #include <structmember.h>
 
+#include <dns/exceptions.h>
 #include <dns/message.h>
 #include <dns/opcode.h>
 #include <dns/tsig.h>
@@ -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: " +
index 4250db7601499cb35edb14e8362309ed3812429a..c95f87765e0fa6230129f831ab68129c0a5f0167 100644 (file)
@@ -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;
 
 
index 8e498b3f936049431c25f1d448baf19d171d10d1..b33125e09c6f02a59a4e590a0c260d8eec3800ca 100644 (file)
@@ -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
index 20f67c8d7e8d2662a9d566990cdf7df6dd151980..df45e9ef9d2840a282d5f7f2291ec0a41dfafdea 100644 (file)
@@ -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;
index 86b1edc0746f52b67ba7fa98947e8f3d93d8b99d..816071689621c26e72ff8e41255755bc631989b1 100644 (file)
@@ -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))
index af9db52efc72d233d0dfb63e6eb510842880556a..574fc00e009e65ce43df0af546290bd4a4429b14 100644 (file)
@@ -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()