2 Unix SMB/CIFS implementation.
4 Python interface to tdb.
6 Copyright (C) 2004-2006 Tim Potter <tpot@samba.org>
7 Copyright (C) 2007-2008 Jelmer Vernooij <jelmer@samba.org>
9 ** NOTE! The following LGPL license applies to the tdb
10 ** library. This does NOT imply that all of Samba is released
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, see <http://www.gnu.org/licenses/>.
29 #include "system/filesys.h"
31 /* Include tdb headers */
34 #if PY_MAJOR_VERSION >= 3
35 #define PyStr_FromString PyUnicode_FromString
36 #define PyStr_FromFormat PyUnicode_FromFormat
37 #define PyInt_FromLong PyLong_FromLong
38 #define PyInt_Check PyLong_Check
39 #define PyInt_AsLong PyLong_AsLong
40 #define Py_TPFLAGS_HAVE_ITER 0
42 #define PyStr_FromString PyString_FromString
43 #define PyStr_FromFormat PyString_FromFormat
52 static PyTypeObject PyTdb
;
54 static void PyErr_SetTDBError(TDB_CONTEXT
*tdb
)
56 PyErr_SetObject(PyExc_RuntimeError
,
57 Py_BuildValue("(i,s)", tdb_error(tdb
), tdb_errorstr(tdb
)));
60 static TDB_DATA
PyBytes_AsTDB_DATA(PyObject
*data
)
63 ret
.dptr
= (unsigned char *)PyBytes_AsString(data
);
64 ret
.dsize
= PyBytes_Size(data
);
68 static PyObject
*PyBytes_FromTDB_DATA(TDB_DATA data
)
70 if (data
.dptr
== NULL
&& data
.dsize
== 0) {
73 PyObject
*ret
= PyBytes_FromStringAndSize((const char *)data
.dptr
,
80 #define PyErr_TDB_ERROR_IS_ERR_RAISE(ret, tdb) \
82 PyErr_SetTDBError(tdb); \
86 #define PyErr_TDB_RAISE_IF_CLOSED(self) \
88 PyErr_SetObject(PyExc_RuntimeError, \
89 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
93 #define PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self) \
95 PyErr_SetObject(PyExc_RuntimeError, \
96 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
100 static PyObject
*py_tdb_open(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwargs
)
103 int hash_size
= 0, tdb_flags
= TDB_DEFAULT
, flags
= O_RDWR
, mode
= 0600;
106 const char *_kwnames
[] = { "name", "hash_size", "tdb_flags", "flags", "mode", NULL
};
107 char **kwnames
= discard_const_p(char *, _kwnames
);
109 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|siiii", kwnames
, &name
, &hash_size
, &tdb_flags
, &flags
, &mode
))
113 tdb_flags
|= TDB_INTERNAL
;
116 ctx
= tdb_open(name
, hash_size
, tdb_flags
, flags
, mode
);
118 PyErr_SetFromErrno(PyExc_IOError
);
122 ret
= PyObject_New(PyTdbObject
, &PyTdb
);
130 return (PyObject
*)ret
;
133 static PyObject
*obj_transaction_cancel(PyTdbObject
*self
)
137 PyErr_TDB_RAISE_IF_CLOSED(self
);
139 ret
= tdb_transaction_cancel(self
->ctx
);
140 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
144 static PyObject
*obj_transaction_commit(PyTdbObject
*self
)
147 PyErr_TDB_RAISE_IF_CLOSED(self
);
148 ret
= tdb_transaction_commit(self
->ctx
);
149 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
153 static PyObject
*obj_transaction_prepare_commit(PyTdbObject
*self
)
156 PyErr_TDB_RAISE_IF_CLOSED(self
);
157 ret
= tdb_transaction_prepare_commit(self
->ctx
);
158 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
162 static PyObject
*obj_transaction_start(PyTdbObject
*self
)
165 PyErr_TDB_RAISE_IF_CLOSED(self
);
166 ret
= tdb_transaction_start(self
->ctx
);
167 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
171 static PyObject
*obj_reopen(PyTdbObject
*self
)
174 PyErr_TDB_RAISE_IF_CLOSED(self
);
175 ret
= tdb_reopen(self
->ctx
);
178 PyErr_SetObject(PyExc_RuntimeError
,
179 Py_BuildValue("(i,s)",
181 "Failed to reopen database"));
187 static PyObject
*obj_lockall(PyTdbObject
*self
)
190 PyErr_TDB_RAISE_IF_CLOSED(self
);
191 ret
= tdb_lockall(self
->ctx
);
192 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
196 static PyObject
*obj_unlockall(PyTdbObject
*self
)
199 PyErr_TDB_RAISE_IF_CLOSED(self
);
200 ret
= tdb_unlockall(self
->ctx
);
201 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
205 static PyObject
*obj_lockall_read(PyTdbObject
*self
)
208 PyErr_TDB_RAISE_IF_CLOSED(self
);
209 ret
= tdb_lockall_read(self
->ctx
);
210 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
214 static PyObject
*obj_unlockall_read(PyTdbObject
*self
)
216 int ret
= tdb_unlockall_read(self
->ctx
);
217 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
221 static PyObject
*obj_close(PyTdbObject
*self
)
226 ret
= tdb_close(self
->ctx
);
229 PyErr_SetObject(PyExc_RuntimeError
,
230 Py_BuildValue("(i,s)",
232 "Failed to close database"));
238 static PyObject
*obj_get(PyTdbObject
*self
, PyObject
*args
)
243 PyErr_TDB_RAISE_IF_CLOSED(self
);
245 if (!PyArg_ParseTuple(args
, "O", &py_key
))
248 key
= PyBytes_AsTDB_DATA(py_key
);
252 return PyBytes_FromTDB_DATA(tdb_fetch(self
->ctx
, key
));
255 static PyObject
*obj_append(PyTdbObject
*self
, PyObject
*args
)
258 PyObject
*py_key
, *py_data
;
261 PyErr_TDB_RAISE_IF_CLOSED(self
);
263 if (!PyArg_ParseTuple(args
, "OO", &py_key
, &py_data
))
266 key
= PyBytes_AsTDB_DATA(py_key
);
269 data
= PyBytes_AsTDB_DATA(py_data
);
273 ret
= tdb_append(self
->ctx
, key
, data
);
274 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
278 static PyObject
*obj_firstkey(PyTdbObject
*self
)
280 PyErr_TDB_RAISE_IF_CLOSED(self
);
282 return PyBytes_FromTDB_DATA(tdb_firstkey(self
->ctx
));
285 static PyObject
*obj_nextkey(PyTdbObject
*self
, PyObject
*args
)
289 PyErr_TDB_RAISE_IF_CLOSED(self
);
291 if (!PyArg_ParseTuple(args
, "O", &py_key
))
294 key
= PyBytes_AsTDB_DATA(py_key
);
298 return PyBytes_FromTDB_DATA(tdb_nextkey(self
->ctx
, key
));
301 static PyObject
*obj_delete(PyTdbObject
*self
, PyObject
*args
)
306 PyErr_TDB_RAISE_IF_CLOSED(self
);
308 if (!PyArg_ParseTuple(args
, "O", &py_key
))
311 key
= PyBytes_AsTDB_DATA(py_key
);
314 ret
= tdb_delete(self
->ctx
, key
);
315 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
319 static PyObject
*obj_has_key(PyTdbObject
*self
, PyObject
*args
)
324 PyErr_TDB_RAISE_IF_CLOSED(self
);
326 if (!PyArg_ParseTuple(args
, "O", &py_key
))
329 key
= PyBytes_AsTDB_DATA(py_key
);
332 ret
= tdb_exists(self
->ctx
, key
);
333 if (ret
!= TDB_ERR_NOEXIST
) {
334 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
337 return (ret
== TDB_ERR_NOEXIST
)?Py_False
:Py_True
;
340 static PyObject
*obj_store(PyTdbObject
*self
, PyObject
*args
)
344 int flag
= TDB_REPLACE
;
345 PyObject
*py_key
, *py_value
;
347 PyErr_TDB_RAISE_IF_CLOSED(self
);
349 if (!PyArg_ParseTuple(args
, "OO|i", &py_key
, &py_value
, &flag
))
352 key
= PyBytes_AsTDB_DATA(py_key
);
355 value
= PyBytes_AsTDB_DATA(py_value
);
359 ret
= tdb_store(self
->ctx
, key
, value
, flag
);
360 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
364 static PyObject
*obj_add_flags(PyTdbObject
*self
, PyObject
*args
)
368 PyErr_TDB_RAISE_IF_CLOSED(self
);
370 if (!PyArg_ParseTuple(args
, "I", &flags
))
373 tdb_add_flags(self
->ctx
, flags
);
377 static PyObject
*obj_remove_flags(PyTdbObject
*self
, PyObject
*args
)
381 PyErr_TDB_RAISE_IF_CLOSED(self
);
383 if (!PyArg_ParseTuple(args
, "I", &flags
))
386 tdb_remove_flags(self
->ctx
, flags
);
393 PyTdbObject
*iteratee
;
394 } PyTdbIteratorObject
;
396 static PyObject
*tdb_iter_next(PyTdbIteratorObject
*self
)
400 if (self
->current
.dptr
== NULL
&& self
->current
.dsize
== 0)
402 current
= self
->current
;
403 self
->current
= tdb_nextkey(self
->iteratee
->ctx
, self
->current
);
404 ret
= PyBytes_FromTDB_DATA(current
);
408 static void tdb_iter_dealloc(PyTdbIteratorObject
*self
)
410 Py_DECREF(self
->iteratee
);
414 PyTypeObject PyTdbIterator
= {
415 .tp_name
= "Iterator",
416 .tp_basicsize
= sizeof(PyTdbIteratorObject
),
417 .tp_iternext
= (iternextfunc
)tdb_iter_next
,
418 .tp_dealloc
= (destructor
)tdb_iter_dealloc
,
419 .tp_flags
= Py_TPFLAGS_DEFAULT
,
420 .tp_iter
= PyObject_SelfIter
,
423 static PyObject
*tdb_object_iter(PyTdbObject
*self
)
425 PyTdbIteratorObject
*ret
;
427 PyErr_TDB_RAISE_IF_CLOSED(self
);
429 ret
= PyObject_New(PyTdbIteratorObject
, &PyTdbIterator
);
432 ret
->current
= tdb_firstkey(self
->ctx
);
433 ret
->iteratee
= self
;
435 return (PyObject
*)ret
;
438 static PyObject
*obj_clear(PyTdbObject
*self
)
441 PyErr_TDB_RAISE_IF_CLOSED(self
);
442 ret
= tdb_wipe_all(self
->ctx
);
443 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
447 static PyObject
*obj_repack(PyTdbObject
*self
)
450 PyErr_TDB_RAISE_IF_CLOSED(self
);
451 ret
= tdb_repack(self
->ctx
);
452 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
456 static PyObject
*obj_enable_seqnum(PyTdbObject
*self
)
458 PyErr_TDB_RAISE_IF_CLOSED(self
);
459 tdb_enable_seqnum(self
->ctx
);
463 static PyObject
*obj_increment_seqnum_nonblock(PyTdbObject
*self
)
465 PyErr_TDB_RAISE_IF_CLOSED(self
);
466 tdb_increment_seqnum_nonblock(self
->ctx
);
470 static PyMethodDef tdb_object_methods
[] = {
471 { "transaction_cancel", (PyCFunction
)obj_transaction_cancel
, METH_NOARGS
,
472 "S.transaction_cancel() -> None\n"
473 "Cancel the currently active transaction." },
474 { "transaction_commit", (PyCFunction
)obj_transaction_commit
, METH_NOARGS
,
475 "S.transaction_commit() -> None\n"
476 "Commit the currently active transaction." },
477 { "transaction_prepare_commit", (PyCFunction
)obj_transaction_prepare_commit
, METH_NOARGS
,
478 "S.transaction_prepare_commit() -> None\n"
479 "Prepare to commit the currently active transaction" },
480 { "transaction_start", (PyCFunction
)obj_transaction_start
, METH_NOARGS
,
481 "S.transaction_start() -> None\n"
482 "Start a new transaction." },
483 { "reopen", (PyCFunction
)obj_reopen
, METH_NOARGS
, "Reopen this file." },
484 { "lock_all", (PyCFunction
)obj_lockall
, METH_NOARGS
, NULL
},
485 { "unlock_all", (PyCFunction
)obj_unlockall
, METH_NOARGS
, NULL
},
486 { "read_lock_all", (PyCFunction
)obj_lockall_read
, METH_NOARGS
, NULL
},
487 { "read_unlock_all", (PyCFunction
)obj_unlockall_read
, METH_NOARGS
, NULL
},
488 { "close", (PyCFunction
)obj_close
, METH_NOARGS
, NULL
},
489 { "get", (PyCFunction
)obj_get
, METH_VARARGS
, "S.get(key) -> value\n"
491 { "append", (PyCFunction
)obj_append
, METH_VARARGS
, "S.append(key, value) -> None\n"
492 "Append data to an existing key." },
493 { "firstkey", (PyCFunction
)obj_firstkey
, METH_NOARGS
, "S.firstkey() -> data\n"
494 "Return the first key in this database." },
495 { "nextkey", (PyCFunction
)obj_nextkey
, METH_VARARGS
, "S.nextkey(key) -> data\n"
496 "Return the next key in this database." },
497 { "delete", (PyCFunction
)obj_delete
, METH_VARARGS
, "S.delete(key) -> None\n"
498 "Delete an entry." },
499 { "has_key", (PyCFunction
)obj_has_key
, METH_VARARGS
, "S.has_key(key) -> None\n"
500 "Check whether key exists in this database." },
501 { "store", (PyCFunction
)obj_store
, METH_VARARGS
, "S.store(key, data, flag=REPLACE) -> None"
503 { "add_flags", (PyCFunction
)obj_add_flags
, METH_VARARGS
, "S.add_flags(flags) -> None" },
504 { "remove_flags", (PyCFunction
)obj_remove_flags
, METH_VARARGS
, "S.remove_flags(flags) -> None" },
505 { "iterkeys", (PyCFunction
)tdb_object_iter
, METH_NOARGS
, "S.iterkeys() -> iterator" },
506 { "clear", (PyCFunction
)obj_clear
, METH_NOARGS
, "S.clear() -> None\n"
507 "Wipe the entire database." },
508 { "repack", (PyCFunction
)obj_repack
, METH_NOARGS
, "S.repack() -> None\n"
509 "Repack the entire database." },
510 { "enable_seqnum", (PyCFunction
)obj_enable_seqnum
, METH_NOARGS
,
511 "S.enable_seqnum() -> None" },
512 { "increment_seqnum_nonblock", (PyCFunction
)obj_increment_seqnum_nonblock
, METH_NOARGS
,
513 "S.increment_seqnum_nonblock() -> None" },
517 static PyObject
*obj_get_hash_size(PyTdbObject
*self
, void *closure
)
519 PyErr_TDB_RAISE_IF_CLOSED(self
);
520 return PyInt_FromLong(tdb_hash_size(self
->ctx
));
523 static int obj_set_max_dead(PyTdbObject
*self
, PyObject
*max_dead
, void *closure
)
525 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self
);
526 if (!PyInt_Check(max_dead
))
528 tdb_set_max_dead(self
->ctx
, PyInt_AsLong(max_dead
));
532 static PyObject
*obj_get_map_size(PyTdbObject
*self
, void *closure
)
534 PyErr_TDB_RAISE_IF_CLOSED(self
);
535 return PyInt_FromLong(tdb_map_size(self
->ctx
));
538 static PyObject
*obj_get_freelist_size(PyTdbObject
*self
, void *closure
)
540 PyErr_TDB_RAISE_IF_CLOSED(self
);
541 return PyInt_FromLong(tdb_freelist_size(self
->ctx
));
544 static PyObject
*obj_get_flags(PyTdbObject
*self
, void *closure
)
546 PyErr_TDB_RAISE_IF_CLOSED(self
);
547 return PyInt_FromLong(tdb_get_flags(self
->ctx
));
550 static PyObject
*obj_get_filename(PyTdbObject
*self
, void *closure
)
552 PyErr_TDB_RAISE_IF_CLOSED(self
);
553 return PyBytes_FromString(tdb_name(self
->ctx
));
556 static PyObject
*obj_get_seqnum(PyTdbObject
*self
, void *closure
)
558 PyErr_TDB_RAISE_IF_CLOSED(self
);
559 return PyInt_FromLong(tdb_get_seqnum(self
->ctx
));
563 static PyGetSetDef tdb_object_getsetters
[] = {
564 { discard_const_p(char, "hash_size"),
565 (getter
)obj_get_hash_size
, NULL
, NULL
},
566 { discard_const_p(char, "map_size"),
567 (getter
)obj_get_map_size
, NULL
, NULL
},
568 { discard_const_p(char, "freelist_size"),
569 (getter
)obj_get_freelist_size
, NULL
, NULL
},
570 { discard_const_p(char, "flags"),
571 (getter
)obj_get_flags
, NULL
, NULL
},
572 { discard_const_p(char, "max_dead"),
573 NULL
, (setter
)obj_set_max_dead
, NULL
},
574 { discard_const_p(char, "filename"),
575 (getter
)obj_get_filename
, NULL
,
576 discard_const_p(char, "The filename of this TDB file.") },
577 { discard_const_p(char, "seqnum"),
578 (getter
)obj_get_seqnum
, NULL
, NULL
},
582 static PyObject
*tdb_object_repr(PyTdbObject
*self
)
584 PyErr_TDB_RAISE_IF_CLOSED(self
);
585 if (tdb_get_flags(self
->ctx
) & TDB_INTERNAL
) {
586 return PyStr_FromString("Tdb(<internal>)");
588 return PyStr_FromFormat("Tdb('%s')", tdb_name(self
->ctx
));
592 static void tdb_object_dealloc(PyTdbObject
*self
)
595 tdb_close(self
->ctx
);
596 Py_TYPE(self
)->tp_free(self
);
599 static PyObject
*obj_getitem(PyTdbObject
*self
, PyObject
*key
)
602 PyErr_TDB_RAISE_IF_CLOSED(self
);
603 if (!PyBytes_Check(key
)) {
604 PyErr_SetString(PyExc_TypeError
, "Expected bytestring as key");
608 tkey
.dptr
= (unsigned char *)PyBytes_AsString(key
);
609 tkey
.dsize
= PyBytes_Size(key
);
611 val
= tdb_fetch(self
->ctx
, tkey
);
612 if (val
.dptr
== NULL
) {
613 PyErr_SetString(PyExc_KeyError
, "No such TDB entry");
616 return PyBytes_FromTDB_DATA(val
);
620 static int obj_setitem(PyTdbObject
*self
, PyObject
*key
, PyObject
*value
)
624 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self
);
625 if (!PyBytes_Check(key
)) {
626 PyErr_SetString(PyExc_TypeError
, "Expected bytestring as key");
630 tkey
= PyBytes_AsTDB_DATA(key
);
633 ret
= tdb_delete(self
->ctx
, tkey
);
635 if (!PyBytes_Check(value
)) {
636 PyErr_SetString(PyExc_TypeError
, "Expected string as value");
640 tval
= PyBytes_AsTDB_DATA(value
);
642 ret
= tdb_store(self
->ctx
, tkey
, tval
, TDB_REPLACE
);
646 PyErr_SetTDBError(self
->ctx
);
653 static PyMappingMethods tdb_object_mapping
= {
654 .mp_subscript
= (binaryfunc
)obj_getitem
,
655 .mp_ass_subscript
= (objobjargproc
)obj_setitem
,
657 static PyTypeObject PyTdb
= {
658 .tp_name
= "tdb.Tdb",
659 .tp_basicsize
= sizeof(PyTdbObject
),
660 .tp_methods
= tdb_object_methods
,
661 .tp_getset
= tdb_object_getsetters
,
662 .tp_new
= py_tdb_open
,
663 .tp_doc
= "A TDB file",
664 .tp_repr
= (reprfunc
)tdb_object_repr
,
665 .tp_dealloc
= (destructor
)tdb_object_dealloc
,
666 .tp_as_mapping
= &tdb_object_mapping
,
667 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
|Py_TPFLAGS_HAVE_ITER
,
668 .tp_iter
= (getiterfunc
)tdb_object_iter
,
671 static PyMethodDef tdb_methods
[] = {
672 { "open", (PyCFunction
)py_tdb_open
, METH_VARARGS
|METH_KEYWORDS
, "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, flags=O_RDWR, mode=0600)\n"
673 "Open a TDB file." },
677 #define MODULE_DOC "simple key-value database that supports multiple writers."
679 #if PY_MAJOR_VERSION >= 3
680 static struct PyModuleDef moduledef
= {
681 PyModuleDef_HEAD_INIT
,
685 .m_methods
= tdb_methods
,
689 PyObject
* module_init(void);
690 PyObject
* module_init(void)
694 if (PyType_Ready(&PyTdb
) < 0)
697 if (PyType_Ready(&PyTdbIterator
) < 0)
700 #if PY_MAJOR_VERSION >= 3
701 m
= PyModule_Create(&moduledef
);
703 m
= Py_InitModule3("tdb", tdb_methods
, MODULE_DOC
);
708 PyModule_AddIntConstant(m
, "REPLACE", TDB_REPLACE
);
709 PyModule_AddIntConstant(m
, "INSERT", TDB_INSERT
);
710 PyModule_AddIntConstant(m
, "MODIFY", TDB_MODIFY
);
712 PyModule_AddIntConstant(m
, "DEFAULT", TDB_DEFAULT
);
713 PyModule_AddIntConstant(m
, "CLEAR_IF_FIRST", TDB_CLEAR_IF_FIRST
);
714 PyModule_AddIntConstant(m
, "INTERNAL", TDB_INTERNAL
);
715 PyModule_AddIntConstant(m
, "NOLOCK", TDB_NOLOCK
);
716 PyModule_AddIntConstant(m
, "NOMMAP", TDB_NOMMAP
);
717 PyModule_AddIntConstant(m
, "CONVERT", TDB_CONVERT
);
718 PyModule_AddIntConstant(m
, "BIGENDIAN", TDB_BIGENDIAN
);
719 PyModule_AddIntConstant(m
, "NOSYNC", TDB_NOSYNC
);
720 PyModule_AddIntConstant(m
, "SEQNUM", TDB_SEQNUM
);
721 PyModule_AddIntConstant(m
, "VOLATILE", TDB_VOLATILE
);
722 PyModule_AddIntConstant(m
, "ALLOW_NESTING", TDB_ALLOW_NESTING
);
723 PyModule_AddIntConstant(m
, "DISALLOW_NESTING", TDB_DISALLOW_NESTING
);
724 PyModule_AddIntConstant(m
, "INCOMPATIBLE_HASH", TDB_INCOMPATIBLE_HASH
);
726 PyModule_AddStringConstant(m
, "__docformat__", "restructuredText");
728 PyModule_AddStringConstant(m
, "__version__", PACKAGE_VERSION
);
731 PyModule_AddObject(m
, "Tdb", (PyObject
*)&PyTdb
);
733 Py_INCREF(&PyTdbIterator
);
739 #if PY_MAJOR_VERSION >= 3
740 PyMODINIT_FUNC
PyInit_tdb(void);
741 PyMODINIT_FUNC
PyInit_tdb(void)
743 return module_init();