123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #include <Python.h>
- #include <util/python/pycppwrapper_util.h>
- #include <datasrc/client.h>
- #include <datasrc/database.h>
- #include <datasrc/sqlite3_accessor.h>
- #include <datasrc/iterator.h>
- #include <dns/python/name_python.h>
- #include <dns/python/rrset_python.h>
- #include "datasrc.h"
- #include "iterator_python.h"
- #include "iterator_inc.cc"
- using namespace std;
- using namespace isc::util::python;
- using namespace isc::dns::python;
- using namespace isc::datasrc;
- using namespace isc::datasrc::python;
- namespace {
- class s_ZoneIterator : public PyObject {
- public:
- s_ZoneIterator() : cppobj(ZoneIteratorPtr()), base_obj(NULL) {};
- ZoneIteratorPtr cppobj;
-
-
-
-
-
- PyObject* base_obj;
- };
- typedef CPPPyObjectContainer<s_ZoneIterator, ZoneIterator>
- ZoneIteratorContainer;
- int
- ZoneIterator_init(s_ZoneIterator* self, PyObject* args) {
-
- PyErr_SetString(PyExc_TypeError,
- "ZoneIterator cannot be constructed directly");
- return (-1);
- }
- void
- ZoneIterator_destroy(s_ZoneIterator* const self) {
-
-
- self->cppobj.reset();
- if (self->base_obj != NULL) {
- Py_DECREF(self->base_obj);
- }
- Py_TYPE(self)->tp_free(self);
- }
- PyObject*
- ZoneIterator_getNextRRset(PyObject* po_self, PyObject*) {
- s_ZoneIterator* self = static_cast<s_ZoneIterator*>(po_self);
- if (!self->cppobj) {
- PyErr_SetString(getDataSourceException("Error"),
- "get_next_rrset() called past end of iterator");
- return (NULL);
- }
- try {
- isc::dns::ConstRRsetPtr rrset = self->cppobj->getNextRRset();
- if (!rrset) {
- Py_RETURN_NONE;
- }
- return (createRRsetObject(*rrset));
- } catch (const isc::Exception& isce) {
-
-
-
- PyErr_SetString(getDataSourceException("Error"), isce.what());
- return (NULL);
- } catch (const std::exception& exc) {
- PyErr_SetString(getDataSourceException("Error"), exc.what());
- return (NULL);
- } catch (...) {
- PyErr_SetString(getDataSourceException("Error"),
- "Unexpected exception");
- return (NULL);
- }
- }
- PyObject*
- ZoneIterator_iter(PyObject *self) {
- Py_INCREF(self);
- return (self);
- }
- PyObject*
- ZoneIterator_next(PyObject* self) {
- PyObject *result = ZoneIterator_getNextRRset(self, NULL);
-
- if (result == Py_None) {
- Py_DECREF(result);
- return (NULL);
- } else {
- return (result);
- }
- }
- PyMethodDef ZoneIterator_methods[] = {
- { "get_next_rrset",
- reinterpret_cast<PyCFunction>(ZoneIterator_getNextRRset), METH_NOARGS,
- ZoneIterator_getNextRRset_doc },
- { NULL, NULL, 0, NULL }
- };
- }
- namespace isc {
- namespace datasrc {
- namespace python {
- PyTypeObject zoneiterator_type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "datasrc.ZoneIterator",
- sizeof(s_ZoneIterator),
- 0,
- reinterpret_cast<destructor>(ZoneIterator_destroy),
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- Py_TPFLAGS_DEFAULT,
- ZoneIterator_doc,
- NULL,
- NULL,
- NULL,
- 0,
- ZoneIterator_iter,
- ZoneIterator_next,
- ZoneIterator_methods,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- reinterpret_cast<initproc>(ZoneIterator_init),
- NULL,
- PyType_GenericNew,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0
- };
- PyObject*
- createZoneIteratorObject(isc::datasrc::ZoneIteratorPtr source,
- PyObject* base_obj)
- {
- s_ZoneIterator* py_zi = static_cast<s_ZoneIterator*>(
- zoneiterator_type.tp_alloc(&zoneiterator_type, 0));
- if (py_zi != NULL) {
- py_zi->cppobj = source;
- py_zi->base_obj = base_obj;
- }
- if (base_obj != NULL) {
- Py_INCREF(base_obj);
- }
- return (py_zi);
- }
- }
- }
- }
|