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 int obj_contains(PyTdbObject
*self
, PyObject
*py_key
)
323 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self
);
325 key
= PyBytes_AsTDB_DATA(py_key
);
330 ret
= tdb_exists(self
->ctx
, key
);
336 #if PY_MAJOR_VERSION < 3
337 static PyObject
*obj_has_key(PyTdbObject
*self
, PyObject
*args
)
341 PyErr_TDB_RAISE_IF_CLOSED(self
);
343 if (!PyArg_ParseTuple(args
, "O", &py_key
))
346 ret
= obj_contains(self
, py_key
);
356 static PyObject
*obj_store(PyTdbObject
*self
, PyObject
*args
)
360 int flag
= TDB_REPLACE
;
361 PyObject
*py_key
, *py_value
;
363 PyErr_TDB_RAISE_IF_CLOSED(self
);
365 if (!PyArg_ParseTuple(args
, "OO|i", &py_key
, &py_value
, &flag
))
368 key
= PyBytes_AsTDB_DATA(py_key
);
371 value
= PyBytes_AsTDB_DATA(py_value
);
375 ret
= tdb_store(self
->ctx
, key
, value
, flag
);
376 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
380 static PyObject
*obj_add_flags(PyTdbObject
*self
, PyObject
*args
)
384 PyErr_TDB_RAISE_IF_CLOSED(self
);
386 if (!PyArg_ParseTuple(args
, "I", &flags
))
389 tdb_add_flags(self
->ctx
, flags
);
393 static PyObject
*obj_remove_flags(PyTdbObject
*self
, PyObject
*args
)
397 PyErr_TDB_RAISE_IF_CLOSED(self
);
399 if (!PyArg_ParseTuple(args
, "I", &flags
))
402 tdb_remove_flags(self
->ctx
, flags
);
409 PyTdbObject
*iteratee
;
410 } PyTdbIteratorObject
;
412 static PyObject
*tdb_iter_next(PyTdbIteratorObject
*self
)
416 if (self
->current
.dptr
== NULL
&& self
->current
.dsize
== 0)
418 current
= self
->current
;
419 self
->current
= tdb_nextkey(self
->iteratee
->ctx
, self
->current
);
420 ret
= PyBytes_FromTDB_DATA(current
);
424 static void tdb_iter_dealloc(PyTdbIteratorObject
*self
)
426 Py_DECREF(self
->iteratee
);
430 PyTypeObject PyTdbIterator
= {
431 .tp_name
= "Iterator",
432 .tp_basicsize
= sizeof(PyTdbIteratorObject
),
433 .tp_iternext
= (iternextfunc
)tdb_iter_next
,
434 .tp_dealloc
= (destructor
)tdb_iter_dealloc
,
435 .tp_flags
= Py_TPFLAGS_DEFAULT
,
436 .tp_iter
= PyObject_SelfIter
,
439 static PyObject
*tdb_object_iter(PyTdbObject
*self
)
441 PyTdbIteratorObject
*ret
;
443 PyErr_TDB_RAISE_IF_CLOSED(self
);
445 ret
= PyObject_New(PyTdbIteratorObject
, &PyTdbIterator
);
448 ret
->current
= tdb_firstkey(self
->ctx
);
449 ret
->iteratee
= self
;
451 return (PyObject
*)ret
;
454 static PyObject
*obj_clear(PyTdbObject
*self
)
457 PyErr_TDB_RAISE_IF_CLOSED(self
);
458 ret
= tdb_wipe_all(self
->ctx
);
459 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
463 static PyObject
*obj_repack(PyTdbObject
*self
)
466 PyErr_TDB_RAISE_IF_CLOSED(self
);
467 ret
= tdb_repack(self
->ctx
);
468 PyErr_TDB_ERROR_IS_ERR_RAISE(ret
, self
->ctx
);
472 static PyObject
*obj_enable_seqnum(PyTdbObject
*self
)
474 PyErr_TDB_RAISE_IF_CLOSED(self
);
475 tdb_enable_seqnum(self
->ctx
);
479 static PyObject
*obj_increment_seqnum_nonblock(PyTdbObject
*self
)
481 PyErr_TDB_RAISE_IF_CLOSED(self
);
482 tdb_increment_seqnum_nonblock(self
->ctx
);
486 static PyMethodDef tdb_object_methods
[] = {
487 { "transaction_cancel", (PyCFunction
)obj_transaction_cancel
, METH_NOARGS
,
488 "S.transaction_cancel() -> None\n"
489 "Cancel the currently active transaction." },
490 { "transaction_commit", (PyCFunction
)obj_transaction_commit
, METH_NOARGS
,
491 "S.transaction_commit() -> None\n"
492 "Commit the currently active transaction." },
493 { "transaction_prepare_commit", (PyCFunction
)obj_transaction_prepare_commit
, METH_NOARGS
,
494 "S.transaction_prepare_commit() -> None\n"
495 "Prepare to commit the currently active transaction" },
496 { "transaction_start", (PyCFunction
)obj_transaction_start
, METH_NOARGS
,
497 "S.transaction_start() -> None\n"
498 "Start a new transaction." },
499 { "reopen", (PyCFunction
)obj_reopen
, METH_NOARGS
, "Reopen this file." },
500 { "lock_all", (PyCFunction
)obj_lockall
, METH_NOARGS
, NULL
},
501 { "unlock_all", (PyCFunction
)obj_unlockall
, METH_NOARGS
, NULL
},
502 { "read_lock_all", (PyCFunction
)obj_lockall_read
, METH_NOARGS
, NULL
},
503 { "read_unlock_all", (PyCFunction
)obj_unlockall_read
, METH_NOARGS
, NULL
},
504 { "close", (PyCFunction
)obj_close
, METH_NOARGS
, NULL
},
505 { "get", (PyCFunction
)obj_get
, METH_VARARGS
, "S.get(key) -> value\n"
507 { "append", (PyCFunction
)obj_append
, METH_VARARGS
, "S.append(key, value) -> None\n"
508 "Append data to an existing key." },
509 { "firstkey", (PyCFunction
)obj_firstkey
, METH_NOARGS
, "S.firstkey() -> data\n"
510 "Return the first key in this database." },
511 { "nextkey", (PyCFunction
)obj_nextkey
, METH_VARARGS
, "S.nextkey(key) -> data\n"
512 "Return the next key in this database." },
513 { "delete", (PyCFunction
)obj_delete
, METH_VARARGS
, "S.delete(key) -> None\n"
514 "Delete an entry." },
515 #if PY_MAJOR_VERSION < 3
516 { "has_key", (PyCFunction
)obj_has_key
, METH_VARARGS
, "S.has_key(key) -> None\n"
517 "Check whether key exists in this database." },
519 { "store", (PyCFunction
)obj_store
, METH_VARARGS
, "S.store(key, data, flag=REPLACE) -> None"
521 { "add_flags", (PyCFunction
)obj_add_flags
, METH_VARARGS
, "S.add_flags(flags) -> None" },
522 { "remove_flags", (PyCFunction
)obj_remove_flags
, METH_VARARGS
, "S.remove_flags(flags) -> None" },
523 #if PY_MAJOR_VERSION >= 3
524 { "keys", (PyCFunction
)tdb_object_iter
, METH_NOARGS
, "S.iterkeys() -> iterator" },
526 { "iterkeys", (PyCFunction
)tdb_object_iter
, METH_NOARGS
, "S.iterkeys() -> iterator" },
528 { "clear", (PyCFunction
)obj_clear
, METH_NOARGS
, "S.clear() -> None\n"
529 "Wipe the entire database." },
530 { "repack", (PyCFunction
)obj_repack
, METH_NOARGS
, "S.repack() -> None\n"
531 "Repack the entire database." },
532 { "enable_seqnum", (PyCFunction
)obj_enable_seqnum
, METH_NOARGS
,
533 "S.enable_seqnum() -> None" },
534 { "increment_seqnum_nonblock", (PyCFunction
)obj_increment_seqnum_nonblock
, METH_NOARGS
,
535 "S.increment_seqnum_nonblock() -> None" },
539 static PyObject
*obj_get_hash_size(PyTdbObject
*self
, void *closure
)
541 PyErr_TDB_RAISE_IF_CLOSED(self
);
542 return PyInt_FromLong(tdb_hash_size(self
->ctx
));
545 static int obj_set_max_dead(PyTdbObject
*self
, PyObject
*max_dead
, void *closure
)
547 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self
);
548 if (!PyInt_Check(max_dead
))
550 tdb_set_max_dead(self
->ctx
, PyInt_AsLong(max_dead
));
554 static PyObject
*obj_get_map_size(PyTdbObject
*self
, void *closure
)
556 PyErr_TDB_RAISE_IF_CLOSED(self
);
557 return PyInt_FromLong(tdb_map_size(self
->ctx
));
560 static PyObject
*obj_get_freelist_size(PyTdbObject
*self
, void *closure
)
562 PyErr_TDB_RAISE_IF_CLOSED(self
);
563 return PyInt_FromLong(tdb_freelist_size(self
->ctx
));
566 static PyObject
*obj_get_flags(PyTdbObject
*self
, void *closure
)
568 PyErr_TDB_RAISE_IF_CLOSED(self
);
569 return PyInt_FromLong(tdb_get_flags(self
->ctx
));
572 static PyObject
*obj_get_filename(PyTdbObject
*self
, void *closure
)
574 PyErr_TDB_RAISE_IF_CLOSED(self
);
575 return PyBytes_FromString(tdb_name(self
->ctx
));
578 static PyObject
*obj_get_seqnum(PyTdbObject
*self
, void *closure
)
580 PyErr_TDB_RAISE_IF_CLOSED(self
);
581 return PyInt_FromLong(tdb_get_seqnum(self
->ctx
));
584 static PyObject
*obj_get_text(PyTdbObject
*self
, void *closure
)
586 PyObject
*mod
, *cls
, *inst
;
587 mod
= PyImport_ImportModule("_tdb_text");
590 cls
= PyObject_GetAttrString(mod
, "TdbTextWrapper");
595 inst
= PyObject_CallFunction(cls
, discard_const_p(char, "O"), self
);
601 static PyGetSetDef tdb_object_getsetters
[] = {
602 { discard_const_p(char, "hash_size"),
603 (getter
)obj_get_hash_size
, NULL
, NULL
},
604 { discard_const_p(char, "map_size"),
605 (getter
)obj_get_map_size
, NULL
, NULL
},
606 { discard_const_p(char, "freelist_size"),
607 (getter
)obj_get_freelist_size
, NULL
, NULL
},
608 { discard_const_p(char, "flags"),
609 (getter
)obj_get_flags
, NULL
, NULL
},
610 { discard_const_p(char, "max_dead"),
611 NULL
, (setter
)obj_set_max_dead
, NULL
},
612 { discard_const_p(char, "filename"),
613 (getter
)obj_get_filename
, NULL
,
614 discard_const_p(char, "The filename of this TDB file.") },
615 { discard_const_p(char, "seqnum"),
616 (getter
)obj_get_seqnum
, NULL
, NULL
},
617 { discard_const_p(char, "text"),
618 (getter
)obj_get_text
, NULL
, NULL
},
622 static PyObject
*tdb_object_repr(PyTdbObject
*self
)
624 PyErr_TDB_RAISE_IF_CLOSED(self
);
625 if (tdb_get_flags(self
->ctx
) & TDB_INTERNAL
) {
626 return PyStr_FromString("Tdb(<internal>)");
628 return PyStr_FromFormat("Tdb('%s')", tdb_name(self
->ctx
));
632 static void tdb_object_dealloc(PyTdbObject
*self
)
635 tdb_close(self
->ctx
);
636 Py_TYPE(self
)->tp_free(self
);
639 static PyObject
*obj_getitem(PyTdbObject
*self
, PyObject
*key
)
642 PyErr_TDB_RAISE_IF_CLOSED(self
);
643 if (!PyBytes_Check(key
)) {
644 PyErr_SetString(PyExc_TypeError
, "Expected bytestring as key");
648 tkey
.dptr
= (unsigned char *)PyBytes_AsString(key
);
649 tkey
.dsize
= PyBytes_Size(key
);
651 val
= tdb_fetch(self
->ctx
, tkey
);
652 if (val
.dptr
== NULL
) {
654 * if the key doesn't exist raise KeyError(key) to be
655 * consistent with python dict
657 PyErr_SetObject(PyExc_KeyError
, key
);
660 return PyBytes_FromTDB_DATA(val
);
664 static int obj_setitem(PyTdbObject
*self
, PyObject
*key
, PyObject
*value
)
668 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self
);
669 if (!PyBytes_Check(key
)) {
670 PyErr_SetString(PyExc_TypeError
, "Expected bytestring as key");
674 tkey
= PyBytes_AsTDB_DATA(key
);
677 ret
= tdb_delete(self
->ctx
, tkey
);
679 if (!PyBytes_Check(value
)) {
680 PyErr_SetString(PyExc_TypeError
, "Expected string as value");
684 tval
= PyBytes_AsTDB_DATA(value
);
686 ret
= tdb_store(self
->ctx
, tkey
, tval
, TDB_REPLACE
);
690 PyErr_SetTDBError(self
->ctx
);
697 static PyMappingMethods tdb_object_mapping
= {
698 .mp_subscript
= (binaryfunc
)obj_getitem
,
699 .mp_ass_subscript
= (objobjargproc
)obj_setitem
,
701 static PySequenceMethods tdb_object_seq
= {
702 .sq_contains
= (objobjproc
)obj_contains
,
704 static PyTypeObject PyTdb
= {
705 .tp_name
= "tdb.Tdb",
706 .tp_basicsize
= sizeof(PyTdbObject
),
707 .tp_methods
= tdb_object_methods
,
708 .tp_getset
= tdb_object_getsetters
,
709 .tp_new
= py_tdb_open
,
710 .tp_doc
= "A TDB file",
711 .tp_repr
= (reprfunc
)tdb_object_repr
,
712 .tp_dealloc
= (destructor
)tdb_object_dealloc
,
713 .tp_as_mapping
= &tdb_object_mapping
,
714 .tp_as_sequence
= &tdb_object_seq
,
715 .tp_flags
= Py_TPFLAGS_DEFAULT
|Py_TPFLAGS_BASETYPE
|Py_TPFLAGS_HAVE_ITER
,
716 .tp_iter
= (getiterfunc
)tdb_object_iter
,
719 static PyMethodDef tdb_methods
[] = {
720 { "open", (PyCFunction
)py_tdb_open
, METH_VARARGS
|METH_KEYWORDS
, "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, flags=O_RDWR, mode=0600)\n"
721 "Open a TDB file." },
725 #define MODULE_DOC "simple key-value database that supports multiple writers."
727 #if PY_MAJOR_VERSION >= 3
728 static struct PyModuleDef moduledef
= {
729 PyModuleDef_HEAD_INIT
,
733 .m_methods
= tdb_methods
,
737 PyObject
* module_init(void);
738 PyObject
* module_init(void)
742 if (PyType_Ready(&PyTdb
) < 0)
745 if (PyType_Ready(&PyTdbIterator
) < 0)
748 #if PY_MAJOR_VERSION >= 3
749 m
= PyModule_Create(&moduledef
);
751 m
= Py_InitModule3("tdb", tdb_methods
, MODULE_DOC
);
756 PyModule_AddIntConstant(m
, "REPLACE", TDB_REPLACE
);
757 PyModule_AddIntConstant(m
, "INSERT", TDB_INSERT
);
758 PyModule_AddIntConstant(m
, "MODIFY", TDB_MODIFY
);
760 PyModule_AddIntConstant(m
, "DEFAULT", TDB_DEFAULT
);
761 PyModule_AddIntConstant(m
, "CLEAR_IF_FIRST", TDB_CLEAR_IF_FIRST
);
762 PyModule_AddIntConstant(m
, "INTERNAL", TDB_INTERNAL
);
763 PyModule_AddIntConstant(m
, "NOLOCK", TDB_NOLOCK
);
764 PyModule_AddIntConstant(m
, "NOMMAP", TDB_NOMMAP
);
765 PyModule_AddIntConstant(m
, "CONVERT", TDB_CONVERT
);
766 PyModule_AddIntConstant(m
, "BIGENDIAN", TDB_BIGENDIAN
);
767 PyModule_AddIntConstant(m
, "NOSYNC", TDB_NOSYNC
);
768 PyModule_AddIntConstant(m
, "SEQNUM", TDB_SEQNUM
);
769 PyModule_AddIntConstant(m
, "VOLATILE", TDB_VOLATILE
);
770 PyModule_AddIntConstant(m
, "ALLOW_NESTING", TDB_ALLOW_NESTING
);
771 PyModule_AddIntConstant(m
, "DISALLOW_NESTING", TDB_DISALLOW_NESTING
);
772 PyModule_AddIntConstant(m
, "INCOMPATIBLE_HASH", TDB_INCOMPATIBLE_HASH
);
774 PyModule_AddStringConstant(m
, "__docformat__", "restructuredText");
776 PyModule_AddStringConstant(m
, "__version__", PACKAGE_VERSION
);
779 PyModule_AddObject(m
, "Tdb", (PyObject
*)&PyTdb
);
781 Py_INCREF(&PyTdbIterator
);
787 #if PY_MAJOR_VERSION >= 3
788 PyMODINIT_FUNC
PyInit_tdb(void);
789 PyMODINIT_FUNC
PyInit_tdb(void)
791 return module_init();