|
@@ -412,62 +412,50 @@ Message_getRRCount(s_Message* self, PyObject* args) {
|
|
}
|
|
}
|
|
|
|
|
|
// TODO use direct iterators for these? (or simply lists for now?)
|
|
// TODO use direct iterators for these? (or simply lists for now?)
|
|
|
|
+template <typename ItemType, typename CreatorParamType>
|
|
|
|
+class SectionInserter {
|
|
|
|
+ typedef PyObject* (*creator_t)(const CreatorParamType&);
|
|
|
|
+public:
|
|
|
|
+ SectionInserter(PyObject* pylist, creator_t creator) :
|
|
|
|
+ pylist_(pylist), creator_(creator)
|
|
|
|
+ {}
|
|
|
|
+ void operator()(ItemType item) {
|
|
|
|
+ if (PyList_Append(pylist_, PyObjectContainer(creator_(*item)).get())
|
|
|
|
+ == -1) {
|
|
|
|
+ isc_throw(PyCPPWrapperException, "PyList_Append failed, "
|
|
|
|
+ "probably due to short memory");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+private:
|
|
|
|
+ PyObject* pylist_;
|
|
|
|
+ creator_t creator_;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+typedef SectionInserter<ConstQuestionPtr, Question> QuestionInserter;
|
|
|
|
+typedef SectionInserter<ConstRRsetPtr, RRset> RRsetInserter;
|
|
|
|
+
|
|
PyObject*
|
|
PyObject*
|
|
Message_getQuestion(s_Message* self) {
|
|
Message_getQuestion(s_Message* self) {
|
|
- QuestionIterator qi, qi_end;
|
|
|
|
try {
|
|
try {
|
|
- qi = self->cppobj->beginQuestion();
|
|
|
|
- qi_end = self->cppobj->endQuestion();
|
|
|
|
|
|
+ PyObjectContainer list_container(PyList_New(0));
|
|
|
|
+ for_each(self->cppobj->beginQuestion(),
|
|
|
|
+ self->cppobj->endQuestion(),
|
|
|
|
+ QuestionInserter(list_container.get(), createQuestionObject));
|
|
|
|
+ return (list_container.release());
|
|
} catch (const InvalidMessageSection& ex) {
|
|
} catch (const InvalidMessageSection& ex) {
|
|
PyErr_SetString(po_InvalidMessageSection, ex.what());
|
|
PyErr_SetString(po_InvalidMessageSection, ex.what());
|
|
- return (NULL);
|
|
|
|
- } catch (...) {
|
|
|
|
- PyErr_SetString(po_IscException,
|
|
|
|
- "Unexpected exception in getting section iterators");
|
|
|
|
- return (NULL);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- PyObject* list = PyList_New(0);
|
|
|
|
- if (list == NULL) {
|
|
|
|
- return (NULL);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- for (; qi != qi_end; ++qi) {
|
|
|
|
- if (PyList_Append(list, createQuestionObject(**qi)) == -1) {
|
|
|
|
- Py_DECREF(list);
|
|
|
|
- return (NULL);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return (list);
|
|
|
|
} catch (const exception& ex) {
|
|
} catch (const exception& ex) {
|
|
const string ex_what =
|
|
const string ex_what =
|
|
- "Unexpected failure getting Question section: " +
|
|
|
|
|
|
+ "Unexpected failure in Message.get_question: " +
|
|
string(ex.what());
|
|
string(ex.what());
|
|
PyErr_SetString(po_IscException, ex_what.c_str());
|
|
PyErr_SetString(po_IscException, ex_what.c_str());
|
|
} catch (...) {
|
|
} catch (...) {
|
|
PyErr_SetString(PyExc_SystemError,
|
|
PyErr_SetString(PyExc_SystemError,
|
|
- "Unexpected failure getting Question section");
|
|
|
|
|
|
+ "Unexpected failure in Message.get_question");
|
|
}
|
|
}
|
|
- Py_DECREF(list);
|
|
|
|
return (NULL);
|
|
return (NULL);
|
|
}
|
|
}
|
|
|
|
|
|
-class RRsetInserter {
|
|
|
|
-public:
|
|
|
|
- RRsetInserter(PyObject* pylist) : pylist_(pylist) {}
|
|
|
|
- void operator()(ConstRRsetPtr rrset) {
|
|
|
|
- if (PyList_Append(pylist_,
|
|
|
|
- PyObjectContainer(createRRsetObject(*rrset)).get())
|
|
|
|
- == -1) {
|
|
|
|
- isc_throw(PyCPPWrapperException, "PyList_Append failed, "
|
|
|
|
- "probably due to short memory");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-private:
|
|
|
|
- PyObject* pylist_;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
PyObject*
|
|
PyObject*
|
|
Message_getSection(s_Message* self, PyObject* args) {
|
|
Message_getSection(s_Message* self, PyObject* args) {
|
|
unsigned int section;
|
|
unsigned int section;
|
|
@@ -484,7 +472,7 @@ Message_getSection(s_Message* self, PyObject* args) {
|
|
static_cast<Message::Section>(section);
|
|
static_cast<Message::Section>(section);
|
|
for_each(self->cppobj->beginSection(msgsection),
|
|
for_each(self->cppobj->beginSection(msgsection),
|
|
self->cppobj->endSection(msgsection),
|
|
self->cppobj->endSection(msgsection),
|
|
- RRsetInserter(list_container.get()));
|
|
|
|
|
|
+ RRsetInserter(list_container.get(), createRRsetObject));
|
|
return (list_container.release());
|
|
return (list_container.release());
|
|
} catch (const isc::OutOfRange& ex) {
|
|
} catch (const isc::OutOfRange& ex) {
|
|
PyErr_SetString(PyExc_OverflowError, ex.what());
|
|
PyErr_SetString(PyExc_OverflowError, ex.what());
|