/* Include tdb headers */
#include <tdb.h>
-#if PY_MAJOR_VERSION >= 3
#define Py_TPFLAGS_HAVE_ITER 0
-#endif
/* discard signature of 'func' in favour of 'target_sig' */
#define PY_DISCARD_FUNC_SIG(target_sig, func) (target_sig)(void(*)(void))func
return 0;
}
-#if PY_MAJOR_VERSION < 3
-static PyObject *obj_has_key(PyTdbObject *self, PyObject *args)
-{
- int ret;
- PyObject *py_key;
- PyErr_TDB_RAISE_IF_CLOSED(self);
-
- if (!PyArg_ParseTuple(args, "O", &py_key))
- return NULL;
-
- ret = obj_contains(self, py_key);
- if (ret == -1)
- return NULL;
- if (ret)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
-
-}
-#endif
-
static PyObject *obj_store(PyTdbObject *self, PyObject *args)
{
TDB_DATA key, value;
"Return the next key in this database." },
{ "delete", (PyCFunction)obj_delete, METH_VARARGS, "S.delete(key) -> None\n"
"Delete an entry." },
-#if PY_MAJOR_VERSION < 3
- { "has_key", (PyCFunction)obj_has_key, METH_VARARGS, "S.has_key(key) -> None\n"
- "Check whether key exists in this database." },
-#endif
{ "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None"
"Store data." },
{ "storev", (PyCFunction)obj_storev, METH_VARARGS, "S.storev(key, data, flag=REPLACE) -> None"
"Store several data." },
{ "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" },
{ "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" },
-#if PY_MAJOR_VERSION >= 3
{ "keys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.keys() -> iterator" },
-#else
- { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
-#endif
{ "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
"Wipe the entire database." },
{ "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n"
#define MODULE_DOC "simple key-value database that supports multiple writers."
-#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
.m_name = "tdb",
.m_size = -1,
.m_methods = tdb_methods,
};
-#endif
PyObject* module_init(void);
PyObject* module_init(void)
if (PyType_Ready(&PyTdbIterator) < 0)
return NULL;
-#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef);
-#else
- m = Py_InitModule3("tdb", tdb_methods, MODULE_DOC);
-#endif
if (m == NULL)
return NULL;
}
-#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit_tdb(void);
PyMODINIT_FUNC PyInit_tdb(void)
{
return module_init();
}
-#else
-void inittdb(void);
-void inittdb(void)
-{
- module_init();
-}
-#endif