|
@@ -65,21 +65,13 @@ namespace {
|
|
|
|
|
|
bool
|
|
|
initModulePart_EDNS(PyObject* mod) {
|
|
|
- // We initialize the static description object with PyType_Ready(),
|
|
|
- // then add it to the module. This is not just a check! (leaving
|
|
|
- // this out results in segmentation faults)
|
|
|
- //
|
|
|
// After the type has been initialized, we initialize any exceptions
|
|
|
// that are defined in the wrapper for this class, and add constants
|
|
|
// to the type, if any
|
|
|
|
|
|
- if (PyType_Ready(&edns_type) < 0) {
|
|
|
+ if (!initClass(edns_type, "EDNS", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&edns_type);
|
|
|
- void* p = &edns_type;
|
|
|
- PyModule_AddObject(mod, "EDNS", static_cast<PyObject*>(p));
|
|
|
-
|
|
|
addClassVariable(edns_type, "SUPPORTED_VERSION",
|
|
|
Py_BuildValue("B", EDNS::SUPPORTED_VERSION));
|
|
|
|
|
@@ -88,14 +80,9 @@ initModulePart_EDNS(PyObject* mod) {
|
|
|
|
|
|
bool
|
|
|
initModulePart_Message(PyObject* mod) {
|
|
|
- if (PyType_Ready(&message_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- void* p = &message_type;
|
|
|
- if (PyModule_AddObject(mod, "Message", static_cast<PyObject*>(p)) < 0) {
|
|
|
+ if (!initClass(message_type, "Message", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&message_type);
|
|
|
|
|
|
try {
|
|
|
//
|
|
@@ -186,32 +173,25 @@ initModulePart_Message(PyObject* mod) {
|
|
|
|
|
|
bool
|
|
|
initModulePart_MessageRenderer(PyObject* mod) {
|
|
|
- if (PyType_Ready(&messagerenderer_type) < 0) {
|
|
|
+ if (!initClass(messagerenderer_type, "MessageRenderer", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&messagerenderer_type);
|
|
|
|
|
|
addClassVariable(messagerenderer_type, "CASE_INSENSITIVE",
|
|
|
Py_BuildValue("I", MessageRenderer::CASE_INSENSITIVE));
|
|
|
addClassVariable(messagerenderer_type, "CASE_SENSITIVE",
|
|
|
Py_BuildValue("I", MessageRenderer::CASE_SENSITIVE));
|
|
|
|
|
|
- PyModule_AddObject(mod, "MessageRenderer",
|
|
|
- reinterpret_cast<PyObject*>(&messagerenderer_type));
|
|
|
|
|
|
return (true);
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
-initModulePart_Name(PyObject* mod) {
|
|
|
-
|
|
|
- //
|
|
|
- // NameComparisonResult
|
|
|
- //
|
|
|
- if (PyType_Ready(&name_comparison_result_type) < 0) {
|
|
|
+initModulePart_NameComparisonResult(PyObject* mod) {
|
|
|
+ if (!initClass(name_comparison_result_type,
|
|
|
+ "NameComparisonResult", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&name_comparison_result_type);
|
|
|
|
|
|
// Add the enums to the module
|
|
|
po_NameRelation = Py_BuildValue("{i:s,i:s,i:s,i:s}",
|
|
@@ -231,17 +211,14 @@ initModulePart_Name(PyObject* mod) {
|
|
|
addClassVariable(name_comparison_result_type, "COMMONANCESTOR",
|
|
|
Py_BuildValue("I", NameComparisonResult::COMMONANCESTOR));
|
|
|
|
|
|
- PyModule_AddObject(mod, "NameComparisonResult",
|
|
|
- reinterpret_cast<PyObject*>(&name_comparison_result_type));
|
|
|
-
|
|
|
- //
|
|
|
- // Name
|
|
|
- //
|
|
|
+ return (true);
|
|
|
+}
|
|
|
|
|
|
- if (PyType_Ready(&name_type) < 0) {
|
|
|
+bool
|
|
|
+initModulePart_Name(PyObject* mod) {
|
|
|
+ if (!initClass(name_type, "Name", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&name_type);
|
|
|
|
|
|
// Add the constants to the module
|
|
|
addClassVariable(name_type, "MAX_WIRE",
|
|
@@ -260,51 +237,56 @@ initModulePart_Name(PyObject* mod) {
|
|
|
addClassVariable(name_type, "ROOT_NAME",
|
|
|
createNameObject(Name::ROOT_NAME()));
|
|
|
|
|
|
- PyModule_AddObject(mod, "Name",
|
|
|
- reinterpret_cast<PyObject*>(&name_type));
|
|
|
-
|
|
|
-
|
|
|
// Add the exceptions to the module
|
|
|
- po_EmptyLabel = PyErr_NewException("pydnspp.EmptyLabel", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "EmptyLabel", po_EmptyLabel);
|
|
|
+ try {
|
|
|
+ po_EmptyLabel = PyErr_NewException("pydnspp.EmptyLabel", NULL, NULL);
|
|
|
+ PyObjectContainer(po_EmptyLabel).installToModule(mod, "EmptyLabel");
|
|
|
|
|
|
- po_TooLongName = PyErr_NewException("pydnspp.TooLongName", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "TooLongName", po_TooLongName);
|
|
|
+ po_TooLongName = PyErr_NewException("pydnspp.TooLongName", NULL, NULL);
|
|
|
+ PyObjectContainer(po_TooLongName).installToModule(mod, "TooLongName");
|
|
|
|
|
|
- po_TooLongLabel = PyErr_NewException("pydnspp.TooLongLabel", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "TooLongLabel", po_TooLongLabel);
|
|
|
+ po_TooLongLabel = PyErr_NewException("pydnspp.TooLongLabel", NULL, NULL);
|
|
|
+ PyObjectContainer(po_TooLongLabel).installToModule(mod, "TooLongLabel");
|
|
|
|
|
|
- po_BadLabelType = PyErr_NewException("pydnspp.BadLabelType", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "BadLabelType", po_BadLabelType);
|
|
|
+ po_BadLabelType = PyErr_NewException("pydnspp.BadLabelType", NULL, NULL);
|
|
|
+ PyObjectContainer(po_BadLabelType).installToModule(mod, "BadLabelType");
|
|
|
|
|
|
- po_BadEscape = PyErr_NewException("pydnspp.BadEscape", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "BadEscape", po_BadEscape);
|
|
|
+ po_BadEscape = PyErr_NewException("pydnspp.BadEscape", NULL, NULL);
|
|
|
+ PyObjectContainer(po_BadEscape).installToModule(mod, "BadEscape");
|
|
|
|
|
|
- po_IncompleteName = PyErr_NewException("pydnspp.IncompleteName", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "IncompleteName", po_IncompleteName);
|
|
|
+ po_IncompleteName = PyErr_NewException("pydnspp.IncompleteName", NULL,
|
|
|
+ NULL);
|
|
|
+ PyObjectContainer(po_IncompleteName).installToModule(mod, "IncompleteName");
|
|
|
|
|
|
- po_InvalidBufferPosition =
|
|
|
- PyErr_NewException("pydnspp.InvalidBufferPosition", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "InvalidBufferPosition", po_InvalidBufferPosition);
|
|
|
+ po_InvalidBufferPosition =
|
|
|
+ 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);
|
|
|
- PyModule_AddObject(mod, "DNSMessageFORMERR", po_DNSMessageFORMERR);
|
|
|
+ // 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: " +
|
|
|
+ std::string(ex.what());
|
|
|
+ PyErr_SetString(po_IscException, ex_what.c_str());
|
|
|
+ return (false);
|
|
|
+ } catch (...) {
|
|
|
+ PyErr_SetString(PyExc_SystemError,
|
|
|
+ "Unexpected failure in Name initialization");
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
|
|
|
return (true);
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_Opcode(PyObject* mod) {
|
|
|
- if (PyType_Ready(&opcode_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- Py_INCREF(&opcode_type);
|
|
|
- void* p = &opcode_type;
|
|
|
- if (PyModule_AddObject(mod, "Opcode", static_cast<PyObject*>(p)) != 0) {
|
|
|
- Py_DECREF(&opcode_type);
|
|
|
+ if (!initClass(opcode_type, "Opcode", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
|
|
@@ -346,25 +328,12 @@ initModulePart_Opcode(PyObject* mod) {
|
|
|
|
|
|
bool
|
|
|
initModulePart_Question(PyObject* mod) {
|
|
|
- if (PyType_Ready(&question_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- Py_INCREF(&question_type);
|
|
|
- PyModule_AddObject(mod, "Question",
|
|
|
- reinterpret_cast<PyObject*>(&question_type));
|
|
|
-
|
|
|
- return (true);
|
|
|
+ return (initClass(question_type, "Question", mod));
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_Rcode(PyObject* mod) {
|
|
|
- if (PyType_Ready(&rcode_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- Py_INCREF(&rcode_type);
|
|
|
- void* p = &rcode_type;
|
|
|
- if (PyModule_AddObject(mod, "Rcode", static_cast<PyObject*>(p)) != 0) {
|
|
|
- Py_DECREF(&rcode_type);
|
|
|
+ if (!initClass(rcode_type, "Rcode", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
|
|
@@ -408,126 +377,168 @@ initModulePart_Rcode(PyObject* mod) {
|
|
|
|
|
|
bool
|
|
|
initModulePart_Rdata(PyObject* mod) {
|
|
|
- if (PyType_Ready(&rdata_type) < 0) {
|
|
|
+ if (!initClass(rdata_type, "Rdata", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&rdata_type);
|
|
|
- PyModule_AddObject(mod, "Rdata",
|
|
|
- reinterpret_cast<PyObject*>(&rdata_type));
|
|
|
|
|
|
// Add the exceptions to the class
|
|
|
- po_InvalidRdataLength = PyErr_NewException("pydnspp.InvalidRdataLength",
|
|
|
- NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "InvalidRdataLength", po_InvalidRdataLength);
|
|
|
-
|
|
|
- po_InvalidRdataText = PyErr_NewException("pydnspp.InvalidRdataText",
|
|
|
- NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "InvalidRdataText", po_InvalidRdataText);
|
|
|
-
|
|
|
- po_CharStringTooLong = PyErr_NewException("pydnspp.CharStringTooLong",
|
|
|
- NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "CharStringTooLong", po_CharStringTooLong);
|
|
|
-
|
|
|
+ try {
|
|
|
+ po_InvalidRdataLength =
|
|
|
+ PyErr_NewException("pydnspp.InvalidRdataLength", NULL, NULL);
|
|
|
+ PyObjectContainer(po_InvalidRdataLength).installToModule(
|
|
|
+ mod, "InvalidRdataLength");
|
|
|
+
|
|
|
+ po_InvalidRdataText = PyErr_NewException("pydnspp.InvalidRdataText",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_InvalidRdataText).installToModule(
|
|
|
+ mod, "InvalidRdataText");
|
|
|
+
|
|
|
+ po_CharStringTooLong = PyErr_NewException("pydnspp.CharStringTooLong",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_CharStringTooLong).installToModule(
|
|
|
+ mod, "CharStringTooLong");
|
|
|
+ } catch (const std::exception& ex) {
|
|
|
+ const std::string ex_what =
|
|
|
+ "Unexpected failure in Rdata initialization: " +
|
|
|
+ std::string(ex.what());
|
|
|
+ PyErr_SetString(po_IscException, ex_what.c_str());
|
|
|
+ return (false);
|
|
|
+ } catch (...) {
|
|
|
+ PyErr_SetString(PyExc_SystemError,
|
|
|
+ "Unexpected failure in Rdata initialization");
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
|
|
|
return (true);
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_RRClass(PyObject* mod) {
|
|
|
- po_InvalidRRClass = PyErr_NewException("pydnspp.InvalidRRClass",
|
|
|
- NULL, NULL);
|
|
|
- Py_INCREF(po_InvalidRRClass);
|
|
|
- PyModule_AddObject(mod, "InvalidRRClass", po_InvalidRRClass);
|
|
|
- po_IncompleteRRClass = PyErr_NewException("pydnspp.IncompleteRRClass",
|
|
|
- NULL, NULL);
|
|
|
- Py_INCREF(po_IncompleteRRClass);
|
|
|
- PyModule_AddObject(mod, "IncompleteRRClass", po_IncompleteRRClass);
|
|
|
+ if (!initClass(rrclass_type, "RRClass", mod)) {
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
|
|
|
- if (PyType_Ready(&rrclass_type) < 0) {
|
|
|
+ try {
|
|
|
+ po_InvalidRRClass = PyErr_NewException("pydnspp.InvalidRRClass",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_InvalidRRClass).installToModule(
|
|
|
+ mod, "InvalidRRClass");
|
|
|
+
|
|
|
+ po_IncompleteRRClass = PyErr_NewException("pydnspp.IncompleteRRClass",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_IncompleteRRClass).installToModule(
|
|
|
+ mod, "IncompleteRRClass");
|
|
|
+ } catch (const std::exception& ex) {
|
|
|
+ const std::string ex_what =
|
|
|
+ "Unexpected failure in RRClass initialization: " +
|
|
|
+ std::string(ex.what());
|
|
|
+ PyErr_SetString(po_IscException, ex_what.c_str());
|
|
|
+ return (false);
|
|
|
+ } catch (...) {
|
|
|
+ PyErr_SetString(PyExc_SystemError,
|
|
|
+ "Unexpected failure in RRClass initialization");
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&rrclass_type);
|
|
|
- PyModule_AddObject(mod, "RRClass",
|
|
|
- reinterpret_cast<PyObject*>(&rrclass_type));
|
|
|
|
|
|
return (true);
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_RRset(PyObject* mod) {
|
|
|
- po_EmptyRRset = PyErr_NewException("pydnspp.EmptyRRset", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "EmptyRRset", po_EmptyRRset);
|
|
|
+ if (!initClass(rrset_type, "RRset", mod)) {
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
|
|
|
- // NameComparisonResult
|
|
|
- if (PyType_Ready(&rrset_type) < 0) {
|
|
|
+ try {
|
|
|
+ po_EmptyRRset = PyErr_NewException("pydnspp.EmptyRRset", NULL, NULL);
|
|
|
+ PyObjectContainer(po_EmptyRRset).installToModule(mod, "EmptyRRset");
|
|
|
+ } catch (const std::exception& ex) {
|
|
|
+ const std::string ex_what =
|
|
|
+ "Unexpected failure in RRset initialization: " +
|
|
|
+ std::string(ex.what());
|
|
|
+ PyErr_SetString(po_IscException, ex_what.c_str());
|
|
|
+ return (false);
|
|
|
+ } catch (...) {
|
|
|
+ PyErr_SetString(PyExc_SystemError,
|
|
|
+ "Unexpected failure in RRset initialization");
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&rrset_type);
|
|
|
- PyModule_AddObject(mod, "RRset",
|
|
|
- reinterpret_cast<PyObject*>(&rrset_type));
|
|
|
|
|
|
return (true);
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_RRTTL(PyObject* mod) {
|
|
|
- po_InvalidRRTTL = PyErr_NewException("pydnspp.InvalidRRTTL", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "InvalidRRTTL", po_InvalidRRTTL);
|
|
|
- po_IncompleteRRTTL = PyErr_NewException("pydnspp.IncompleteRRTTL",
|
|
|
- NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "IncompleteRRTTL", po_IncompleteRRTTL);
|
|
|
+ if (!initClass(rrttl_type, "RRTTL", mod)) {
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ po_InvalidRRTTL = PyErr_NewException("pydnspp.InvalidRRTTL",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_InvalidRRTTL).installToModule(mod,
|
|
|
+ "InvalidRRTTL");
|
|
|
|
|
|
- if (PyType_Ready(&rrttl_type) < 0) {
|
|
|
+ po_IncompleteRRTTL = PyErr_NewException("pydnspp.IncompleteRRTTL",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_IncompleteRRTTL).installToModule(
|
|
|
+ mod, "IncompleteRRTTL");
|
|
|
+ } catch (const std::exception& ex) {
|
|
|
+ const std::string ex_what =
|
|
|
+ "Unexpected failure in RRTTL initialization: " +
|
|
|
+ std::string(ex.what());
|
|
|
+ PyErr_SetString(po_IscException, ex_what.c_str());
|
|
|
+ return (false);
|
|
|
+ } catch (...) {
|
|
|
+ PyErr_SetString(PyExc_SystemError,
|
|
|
+ "Unexpected failure in RRTTL initialization");
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&rrttl_type);
|
|
|
- PyModule_AddObject(mod, "RRTTL",
|
|
|
- reinterpret_cast<PyObject*>(&rrttl_type));
|
|
|
|
|
|
return (true);
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_RRType(PyObject* mod) {
|
|
|
- // Add the exceptions to the module
|
|
|
- po_InvalidRRType = PyErr_NewException("pydnspp.InvalidRRType", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "InvalidRRType", po_InvalidRRType);
|
|
|
- po_IncompleteRRType = PyErr_NewException("pydnspp.IncompleteRRType",
|
|
|
- NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "IncompleteRRType", po_IncompleteRRType);
|
|
|
+ if (!initClass(rrtype_type, "RRType", mod)) {
|
|
|
+ return (false);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ po_InvalidRRType = PyErr_NewException("pydnspp.InvalidRRType",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_InvalidRRType).installToModule(mod,
|
|
|
+ "InvalidRRType");
|
|
|
|
|
|
- if (PyType_Ready(&rrtype_type) < 0) {
|
|
|
+ po_IncompleteRRType = PyErr_NewException("pydnspp.IncompleteRRType",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_IncompleteRRType).installToModule(
|
|
|
+ mod, "IncompleteRRType");
|
|
|
+ } catch (const std::exception& ex) {
|
|
|
+ const std::string ex_what =
|
|
|
+ "Unexpected failure in RRType initialization: " +
|
|
|
+ std::string(ex.what());
|
|
|
+ PyErr_SetString(po_IscException, ex_what.c_str());
|
|
|
+ return (false);
|
|
|
+ } catch (...) {
|
|
|
+ PyErr_SetString(PyExc_SystemError,
|
|
|
+ "Unexpected failure in RRType initialization");
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&rrtype_type);
|
|
|
- PyModule_AddObject(mod, "RRType",
|
|
|
- reinterpret_cast<PyObject*>(&rrtype_type));
|
|
|
|
|
|
return (true);
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_Serial(PyObject* mod) {
|
|
|
- if (PyType_Ready(&serial_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- Py_INCREF(&serial_type);
|
|
|
- PyModule_AddObject(mod, "Serial",
|
|
|
- reinterpret_cast<PyObject*>(&serial_type));
|
|
|
-
|
|
|
- return (true);
|
|
|
+ return (initClass(serial_type, "Serial", mod));
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_TSIGError(PyObject* mod) {
|
|
|
- if (PyType_Ready(&tsigerror_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- void* p = &tsigerror_type;
|
|
|
- if (PyModule_AddObject(mod, "TSIGError", static_cast<PyObject*>(p)) < 0) {
|
|
|
+ if (!initClass(tsigerror_type, "TSIGError", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&tsigerror_type);
|
|
|
|
|
|
try {
|
|
|
// Constant class variables
|
|
@@ -595,14 +606,9 @@ initModulePart_TSIGError(PyObject* mod) {
|
|
|
|
|
|
bool
|
|
|
initModulePart_TSIGKey(PyObject* mod) {
|
|
|
- if (PyType_Ready(&tsigkey_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- void* p = &tsigkey_type;
|
|
|
- if (PyModule_AddObject(mod, "TSIGKey", static_cast<PyObject*>(p)) != 0) {
|
|
|
+ if (!initClass(tsigkey_type, "TSIGKey", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&tsigkey_type);
|
|
|
|
|
|
try {
|
|
|
// Constant class variables
|
|
@@ -635,14 +641,7 @@ initModulePart_TSIGKey(PyObject* mod) {
|
|
|
|
|
|
bool
|
|
|
initModulePart_TSIGKeyRing(PyObject* mod) {
|
|
|
- if (PyType_Ready(&tsigkeyring_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- Py_INCREF(&tsigkeyring_type);
|
|
|
- void* p = &tsigkeyring_type;
|
|
|
- if (PyModule_AddObject(mod, "TSIGKeyRing",
|
|
|
- static_cast<PyObject*>(p)) != 0) {
|
|
|
- Py_DECREF(&tsigkeyring_type);
|
|
|
+ if (!initClass(tsigkeyring_type, "TSIGKeyRing", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
|
|
@@ -658,15 +657,9 @@ initModulePart_TSIGKeyRing(PyObject* mod) {
|
|
|
|
|
|
bool
|
|
|
initModulePart_TSIGContext(PyObject* mod) {
|
|
|
- if (PyType_Ready(&tsigcontext_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- void* p = &tsigcontext_type;
|
|
|
- if (PyModule_AddObject(mod, "TSIGContext",
|
|
|
- static_cast<PyObject*>(p)) < 0) {
|
|
|
+ if (!initClass(tsigcontext_type, "TSIGContext", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&tsigcontext_type);
|
|
|
|
|
|
try {
|
|
|
// Class specific exceptions
|
|
@@ -707,28 +700,14 @@ initModulePart_TSIGContext(PyObject* mod) {
|
|
|
|
|
|
bool
|
|
|
initModulePart_TSIG(PyObject* mod) {
|
|
|
- if (PyType_Ready(&tsig_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- void* p = &tsig_type;
|
|
|
- if (PyModule_AddObject(mod, "TSIG", static_cast<PyObject*>(p)) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- Py_INCREF(&tsig_type);
|
|
|
-
|
|
|
- return (true);
|
|
|
+ return (initClass(tsig_type, "TSIG", mod));
|
|
|
}
|
|
|
|
|
|
bool
|
|
|
initModulePart_TSIGRecord(PyObject* mod) {
|
|
|
- if (PyType_Ready(&tsigrecord_type) < 0) {
|
|
|
- return (false);
|
|
|
- }
|
|
|
- void* p = &tsigrecord_type;
|
|
|
- if (PyModule_AddObject(mod, "TSIGRecord", static_cast<PyObject*>(p)) < 0) {
|
|
|
+ if (!initClass(tsigrecord_type, "TSIGRecord", mod)) {
|
|
|
return (false);
|
|
|
}
|
|
|
- Py_INCREF(&tsigrecord_type);
|
|
|
|
|
|
try {
|
|
|
// Constant class variables
|
|
@@ -773,16 +752,38 @@ PyInit_pydnspp(void) {
|
|
|
return (NULL);
|
|
|
}
|
|
|
|
|
|
- // Add the exceptions to the class
|
|
|
- po_IscException = PyErr_NewException("pydnspp.IscException", NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "IscException", po_IscException);
|
|
|
-
|
|
|
- po_InvalidParameter = PyErr_NewException("pydnspp.InvalidParameter",
|
|
|
- NULL, NULL);
|
|
|
- PyModule_AddObject(mod, "InvalidParameter", po_InvalidParameter);
|
|
|
+ try {
|
|
|
+ // Add the exceptions to the class
|
|
|
+ po_IscException = PyErr_NewException("pydnspp.IscException", NULL, NULL);
|
|
|
+ PyObjectContainer(po_IscException).installToModule(mod, "IscException");
|
|
|
+
|
|
|
+ po_InvalidOperation = PyErr_NewException("pydnspp.InvalidOperation",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_InvalidOperation).installToModule(
|
|
|
+ mod, "InvalidOperation");
|
|
|
+
|
|
|
+ po_InvalidParameter = PyErr_NewException("pydnspp.InvalidParameter",
|
|
|
+ NULL, NULL);
|
|
|
+ PyObjectContainer(po_InvalidParameter).installToModule(
|
|
|
+ mod, "InvalidParameter");
|
|
|
+ } catch (const std::exception& ex) {
|
|
|
+ const std::string ex_what =
|
|
|
+ "Unexpected failure in pydnspp initialization: " +
|
|
|
+ std::string(ex.what());
|
|
|
+ PyErr_SetString(po_IscException, ex_what.c_str());
|
|
|
+ return (NULL);
|
|
|
+ } catch (...) {
|
|
|
+ PyErr_SetString(PyExc_SystemError,
|
|
|
+ "Unexpected failure in pydnspp initialization");
|
|
|
+ return (NULL);
|
|
|
+ }
|
|
|
|
|
|
// for each part included above, we call its specific initializer
|
|
|
|
|
|
+ if (!initModulePart_NameComparisonResult(mod)) {
|
|
|
+ return (NULL);
|
|
|
+ }
|
|
|
+
|
|
|
if (!initModulePart_Name(mod)) {
|
|
|
return (NULL);
|
|
|
}
|