Use correct error code value for NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE
[Samba.git] / ctdb / lib / tdb / pytdb.c
blob98a624687ebd3535ca977b3c56c574a07cee0a4c
1 /*
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
11 ** under the LGPL
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/>.
27 #include <Python.h>
28 #include "replace.h"
29 #include "system/filesys.h"
31 /* Include tdb headers */
32 #include <tdb.h>
34 typedef struct {
35 PyObject_HEAD
36 TDB_CONTEXT *ctx;
37 bool closed;
38 } PyTdbObject;
40 staticforward PyTypeObject PyTdb;
42 static void PyErr_SetTDBError(TDB_CONTEXT *tdb)
44 PyErr_SetObject(PyExc_RuntimeError,
45 Py_BuildValue("(i,s)", tdb_error(tdb), tdb_errorstr(tdb)));
48 static TDB_DATA PyString_AsTDB_DATA(PyObject *data)
50 TDB_DATA ret;
51 ret.dptr = (unsigned char *)PyString_AsString(data);
52 ret.dsize = PyString_Size(data);
53 return ret;
56 static PyObject *PyString_FromTDB_DATA(TDB_DATA data)
58 if (data.dptr == NULL && data.dsize == 0) {
59 Py_RETURN_NONE;
60 } else {
61 PyObject *ret = PyString_FromStringAndSize((const char *)data.dptr,
62 data.dsize);
63 free(data.dptr);
64 return ret;
68 #define PyErr_TDB_ERROR_IS_ERR_RAISE(ret, tdb) \
69 if (ret != 0) { \
70 PyErr_SetTDBError(tdb); \
71 return NULL; \
74 #define PyErr_TDB_RAISE_IF_CLOSED(self) \
75 if (self->closed) { \
76 PyErr_SetObject(PyExc_RuntimeError, \
77 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
78 return NULL; \
81 #define PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self) \
82 if (self->closed) { \
83 PyErr_SetObject(PyExc_RuntimeError, \
84 Py_BuildValue("(i,s)", TDB_ERR_IO, "Database is already closed")); \
85 return -1; \
88 static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs)
90 char *name = NULL;
91 int hash_size = 0, tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600;
92 TDB_CONTEXT *ctx;
93 PyTdbObject *ret;
94 const char *kwnames[] = { "name", "hash_size", "tdb_flags", "flags", "mode", NULL };
96 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siiii", (char **)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode))
97 return NULL;
99 if (name == NULL) {
100 tdb_flags |= TDB_INTERNAL;
103 ctx = tdb_open(name, hash_size, tdb_flags, flags, mode);
104 if (ctx == NULL) {
105 PyErr_SetFromErrno(PyExc_IOError);
106 return NULL;
109 ret = PyObject_New(PyTdbObject, &PyTdb);
110 if (!ret) {
111 tdb_close(ctx);
112 return NULL;
115 ret->ctx = ctx;
116 ret->closed = false;
117 return (PyObject *)ret;
120 static PyObject *obj_transaction_cancel(PyTdbObject *self)
122 int ret;
124 PyErr_TDB_RAISE_IF_CLOSED(self);
126 ret = tdb_transaction_cancel(self->ctx);
127 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
128 Py_RETURN_NONE;
131 static PyObject *obj_transaction_commit(PyTdbObject *self)
133 int ret;
134 PyErr_TDB_RAISE_IF_CLOSED(self);
135 ret = tdb_transaction_commit(self->ctx);
136 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
137 Py_RETURN_NONE;
140 static PyObject *obj_transaction_prepare_commit(PyTdbObject *self)
142 int ret;
143 PyErr_TDB_RAISE_IF_CLOSED(self);
144 ret = tdb_transaction_prepare_commit(self->ctx);
145 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
146 Py_RETURN_NONE;
149 static PyObject *obj_transaction_start(PyTdbObject *self)
151 int ret;
152 PyErr_TDB_RAISE_IF_CLOSED(self);
153 ret = tdb_transaction_start(self->ctx);
154 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
155 Py_RETURN_NONE;
158 static PyObject *obj_reopen(PyTdbObject *self)
160 int ret;
161 PyErr_TDB_RAISE_IF_CLOSED(self);
162 ret = tdb_reopen(self->ctx);
163 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
164 Py_RETURN_NONE;
167 static PyObject *obj_lockall(PyTdbObject *self)
169 int ret;
170 PyErr_TDB_RAISE_IF_CLOSED(self);
171 ret = tdb_lockall(self->ctx);
172 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
173 Py_RETURN_NONE;
176 static PyObject *obj_unlockall(PyTdbObject *self)
178 int ret;
179 PyErr_TDB_RAISE_IF_CLOSED(self);
180 ret = tdb_unlockall(self->ctx);
181 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
182 Py_RETURN_NONE;
185 static PyObject *obj_lockall_read(PyTdbObject *self)
187 int ret;
188 PyErr_TDB_RAISE_IF_CLOSED(self);
189 ret = tdb_lockall_read(self->ctx);
190 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
191 Py_RETURN_NONE;
194 static PyObject *obj_unlockall_read(PyTdbObject *self)
196 int ret = tdb_unlockall_read(self->ctx);
197 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
198 Py_RETURN_NONE;
201 static PyObject *obj_close(PyTdbObject *self)
203 int ret;
204 if (self->closed)
205 Py_RETURN_NONE;
206 ret = tdb_close(self->ctx);
207 self->closed = true;
208 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
209 Py_RETURN_NONE;
212 static PyObject *obj_get(PyTdbObject *self, PyObject *args)
214 TDB_DATA key;
215 PyObject *py_key;
217 PyErr_TDB_RAISE_IF_CLOSED(self);
219 if (!PyArg_ParseTuple(args, "O", &py_key))
220 return NULL;
222 key = PyString_AsTDB_DATA(py_key);
223 if (!key.dptr)
224 return NULL;
226 return PyString_FromTDB_DATA(tdb_fetch(self->ctx, key));
229 static PyObject *obj_append(PyTdbObject *self, PyObject *args)
231 TDB_DATA key, data;
232 PyObject *py_key, *py_data;
233 int ret;
235 PyErr_TDB_RAISE_IF_CLOSED(self);
237 if (!PyArg_ParseTuple(args, "OO", &py_key, &py_data))
238 return NULL;
240 key = PyString_AsTDB_DATA(py_key);
241 if (!key.dptr)
242 return NULL;
243 data = PyString_AsTDB_DATA(py_data);
244 if (!data.dptr)
245 return NULL;
247 ret = tdb_append(self->ctx, key, data);
248 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
249 Py_RETURN_NONE;
252 static PyObject *obj_firstkey(PyTdbObject *self)
254 PyErr_TDB_RAISE_IF_CLOSED(self);
256 return PyString_FromTDB_DATA(tdb_firstkey(self->ctx));
259 static PyObject *obj_nextkey(PyTdbObject *self, PyObject *args)
261 TDB_DATA key;
262 PyObject *py_key;
263 PyErr_TDB_RAISE_IF_CLOSED(self);
265 if (!PyArg_ParseTuple(args, "O", &py_key))
266 return NULL;
268 key = PyString_AsTDB_DATA(py_key);
269 if (!key.dptr)
270 return NULL;
272 return PyString_FromTDB_DATA(tdb_nextkey(self->ctx, key));
275 static PyObject *obj_delete(PyTdbObject *self, PyObject *args)
277 TDB_DATA key;
278 PyObject *py_key;
279 int ret;
280 PyErr_TDB_RAISE_IF_CLOSED(self);
282 if (!PyArg_ParseTuple(args, "O", &py_key))
283 return NULL;
285 key = PyString_AsTDB_DATA(py_key);
286 if (!key.dptr)
287 return NULL;
288 ret = tdb_delete(self->ctx, key);
289 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
290 Py_RETURN_NONE;
293 static PyObject *obj_has_key(PyTdbObject *self, PyObject *args)
295 TDB_DATA key;
296 int ret;
297 PyObject *py_key;
298 PyErr_TDB_RAISE_IF_CLOSED(self);
300 if (!PyArg_ParseTuple(args, "O", &py_key))
301 return NULL;
303 key = PyString_AsTDB_DATA(py_key);
304 if (!key.dptr)
305 return NULL;
306 ret = tdb_exists(self->ctx, key);
307 if (ret != TDB_ERR_NOEXIST) {
308 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
311 return (ret == TDB_ERR_NOEXIST)?Py_False:Py_True;
314 static PyObject *obj_store(PyTdbObject *self, PyObject *args)
316 TDB_DATA key, value;
317 int ret;
318 int flag = TDB_REPLACE;
319 PyObject *py_key, *py_value;
321 PyErr_TDB_RAISE_IF_CLOSED(self);
323 if (!PyArg_ParseTuple(args, "OO|i", &py_key, &py_value, &flag))
324 return NULL;
326 key = PyString_AsTDB_DATA(py_key);
327 if (!key.dptr)
328 return NULL;
329 value = PyString_AsTDB_DATA(py_value);
330 if (!value.dptr)
331 return NULL;
333 ret = tdb_store(self->ctx, key, value, flag);
334 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
335 Py_RETURN_NONE;
338 static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args)
340 unsigned flags;
342 PyErr_TDB_RAISE_IF_CLOSED(self);
344 if (!PyArg_ParseTuple(args, "I", &flags))
345 return NULL;
347 tdb_add_flags(self->ctx, flags);
348 Py_RETURN_NONE;
351 static PyObject *obj_remove_flags(PyTdbObject *self, PyObject *args)
353 unsigned flags;
355 PyErr_TDB_RAISE_IF_CLOSED(self);
357 if (!PyArg_ParseTuple(args, "I", &flags))
358 return NULL;
360 tdb_remove_flags(self->ctx, flags);
361 Py_RETURN_NONE;
364 typedef struct {
365 PyObject_HEAD
366 TDB_DATA current;
367 PyTdbObject *iteratee;
368 } PyTdbIteratorObject;
370 static PyObject *tdb_iter_next(PyTdbIteratorObject *self)
372 TDB_DATA current;
373 PyObject *ret;
374 if (self->current.dptr == NULL && self->current.dsize == 0)
375 return NULL;
376 current = self->current;
377 self->current = tdb_nextkey(self->iteratee->ctx, self->current);
378 ret = PyString_FromTDB_DATA(current);
379 return ret;
382 static void tdb_iter_dealloc(PyTdbIteratorObject *self)
384 Py_DECREF(self->iteratee);
385 PyObject_Del(self);
388 PyTypeObject PyTdbIterator = {
389 .tp_name = "Iterator",
390 .tp_basicsize = sizeof(PyTdbIteratorObject),
391 .tp_iternext = (iternextfunc)tdb_iter_next,
392 .tp_dealloc = (destructor)tdb_iter_dealloc,
393 .tp_flags = Py_TPFLAGS_DEFAULT,
394 .tp_iter = PyObject_SelfIter,
397 static PyObject *tdb_object_iter(PyTdbObject *self)
399 PyTdbIteratorObject *ret;
401 PyErr_TDB_RAISE_IF_CLOSED(self);
403 ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator);
404 if (!ret)
405 return NULL;
406 ret->current = tdb_firstkey(self->ctx);
407 ret->iteratee = self;
408 Py_INCREF(self);
409 return (PyObject *)ret;
412 static PyObject *obj_clear(PyTdbObject *self)
414 int ret;
415 PyErr_TDB_RAISE_IF_CLOSED(self);
416 ret = tdb_wipe_all(self->ctx);
417 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
418 Py_RETURN_NONE;
421 static PyObject *obj_repack(PyTdbObject *self)
423 int ret;
424 PyErr_TDB_RAISE_IF_CLOSED(self);
425 ret = tdb_repack(self->ctx);
426 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
427 Py_RETURN_NONE;
430 static PyObject *obj_enable_seqnum(PyTdbObject *self)
432 PyErr_TDB_RAISE_IF_CLOSED(self);
433 tdb_enable_seqnum(self->ctx);
434 Py_RETURN_NONE;
437 static PyObject *obj_increment_seqnum_nonblock(PyTdbObject *self)
439 PyErr_TDB_RAISE_IF_CLOSED(self);
440 tdb_increment_seqnum_nonblock(self->ctx);
441 Py_RETURN_NONE;
444 static PyMethodDef tdb_object_methods[] = {
445 { "transaction_cancel", (PyCFunction)obj_transaction_cancel, METH_NOARGS,
446 "S.transaction_cancel() -> None\n"
447 "Cancel the currently active transaction." },
448 { "transaction_commit", (PyCFunction)obj_transaction_commit, METH_NOARGS,
449 "S.transaction_commit() -> None\n"
450 "Commit the currently active transaction." },
451 { "transaction_prepare_commit", (PyCFunction)obj_transaction_prepare_commit, METH_NOARGS,
452 "S.transaction_prepare_commit() -> None\n"
453 "Prepare to commit the currently active transaction" },
454 { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
455 "S.transaction_start() -> None\n"
456 "Start a new transaction." },
457 { "reopen", (PyCFunction)obj_reopen, METH_NOARGS, "Reopen this file." },
458 { "lock_all", (PyCFunction)obj_lockall, METH_NOARGS, NULL },
459 { "unlock_all", (PyCFunction)obj_unlockall, METH_NOARGS, NULL },
460 { "read_lock_all", (PyCFunction)obj_lockall_read, METH_NOARGS, NULL },
461 { "read_unlock_all", (PyCFunction)obj_unlockall_read, METH_NOARGS, NULL },
462 { "close", (PyCFunction)obj_close, METH_NOARGS, NULL },
463 { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n"
464 "Fetch a value." },
465 { "append", (PyCFunction)obj_append, METH_VARARGS, "S.append(key, value) -> None\n"
466 "Append data to an existing key." },
467 { "firstkey", (PyCFunction)obj_firstkey, METH_NOARGS, "S.firstkey() -> data\n"
468 "Return the first key in this database." },
469 { "nextkey", (PyCFunction)obj_nextkey, METH_NOARGS, "S.nextkey(key) -> data\n"
470 "Return the next key in this database." },
471 { "delete", (PyCFunction)obj_delete, METH_VARARGS, "S.delete(key) -> None\n"
472 "Delete an entry." },
473 { "has_key", (PyCFunction)obj_has_key, METH_VARARGS, "S.has_key(key) -> None\n"
474 "Check whether key exists in this database." },
475 { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None"
476 "Store data." },
477 { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" },
478 { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" },
479 { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
480 { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
481 "Wipe the entire database." },
482 { "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n"
483 "Repack the entire database." },
484 { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS,
485 "S.enable_seqnum() -> None" },
486 { "increment_seqnum_nonblock", (PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS,
487 "S.increment_seqnum_nonblock() -> None" },
488 { NULL }
491 static PyObject *obj_get_hash_size(PyTdbObject *self, void *closure)
493 PyErr_TDB_RAISE_IF_CLOSED(self);
494 return PyInt_FromLong(tdb_hash_size(self->ctx));
497 static int obj_set_max_dead(PyTdbObject *self, PyObject *max_dead, void *closure)
499 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
500 if (!PyInt_Check(max_dead))
501 return -1;
502 tdb_set_max_dead(self->ctx, PyInt_AsLong(max_dead));
503 return 0;
506 static PyObject *obj_get_map_size(PyTdbObject *self, void *closure)
508 PyErr_TDB_RAISE_IF_CLOSED(self);
509 return PyInt_FromLong(tdb_map_size(self->ctx));
512 static PyObject *obj_get_freelist_size(PyTdbObject *self, void *closure)
514 PyErr_TDB_RAISE_IF_CLOSED(self);
515 return PyInt_FromLong(tdb_freelist_size(self->ctx));
518 static PyObject *obj_get_flags(PyTdbObject *self, void *closure)
520 PyErr_TDB_RAISE_IF_CLOSED(self);
521 return PyInt_FromLong(tdb_get_flags(self->ctx));
524 static PyObject *obj_get_filename(PyTdbObject *self, void *closure)
526 PyErr_TDB_RAISE_IF_CLOSED(self);
527 return PyString_FromString(tdb_name(self->ctx));
530 static PyObject *obj_get_seqnum(PyTdbObject *self, void *closure)
532 PyErr_TDB_RAISE_IF_CLOSED(self);
533 return PyInt_FromLong(tdb_get_seqnum(self->ctx));
537 static PyGetSetDef tdb_object_getsetters[] = {
538 { (char *)"hash_size", (getter)obj_get_hash_size, NULL, NULL },
539 { (char *)"map_size", (getter)obj_get_map_size, NULL, NULL },
540 { (char *)"freelist_size", (getter)obj_get_freelist_size, NULL, NULL },
541 { (char *)"flags", (getter)obj_get_flags, NULL, NULL },
542 { (char *)"max_dead", NULL, (setter)obj_set_max_dead, NULL },
543 { (char *)"filename", (getter)obj_get_filename, NULL, (char *)"The filename of this TDB file."},
544 { (char *)"seqnum", (getter)obj_get_seqnum, NULL, NULL },
545 { NULL }
548 static PyObject *tdb_object_repr(PyTdbObject *self)
550 PyErr_TDB_RAISE_IF_CLOSED(self);
551 if (tdb_get_flags(self->ctx) & TDB_INTERNAL) {
552 return PyString_FromString("Tdb(<internal>)");
553 } else {
554 return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx));
558 static void tdb_object_dealloc(PyTdbObject *self)
560 if (!self->closed)
561 tdb_close(self->ctx);
562 self->ob_type->tp_free(self);
565 static PyObject *obj_getitem(PyTdbObject *self, PyObject *key)
567 TDB_DATA tkey, val;
568 PyErr_TDB_RAISE_IF_CLOSED(self);
569 if (!PyString_Check(key)) {
570 PyErr_SetString(PyExc_TypeError, "Expected string as key");
571 return NULL;
574 tkey.dptr = (unsigned char *)PyString_AsString(key);
575 tkey.dsize = PyString_Size(key);
577 val = tdb_fetch(self->ctx, tkey);
578 if (val.dptr == NULL) {
579 PyErr_SetString(PyExc_KeyError, "No such TDB entry");
580 return NULL;
581 } else {
582 return PyString_FromTDB_DATA(val);
586 static int obj_setitem(PyTdbObject *self, PyObject *key, PyObject *value)
588 TDB_DATA tkey, tval;
589 int ret;
590 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
591 if (!PyString_Check(key)) {
592 PyErr_SetString(PyExc_TypeError, "Expected string as key");
593 return -1;
596 tkey = PyString_AsTDB_DATA(key);
598 if (value == NULL) {
599 ret = tdb_delete(self->ctx, tkey);
600 } else {
601 if (!PyString_Check(value)) {
602 PyErr_SetString(PyExc_TypeError, "Expected string as value");
603 return -1;
606 tval = PyString_AsTDB_DATA(value);
608 ret = tdb_store(self->ctx, tkey, tval, TDB_REPLACE);
611 if (ret != 0) {
612 PyErr_SetTDBError(self->ctx);
613 return -1;
616 return ret;
619 static PyMappingMethods tdb_object_mapping = {
620 .mp_subscript = (binaryfunc)obj_getitem,
621 .mp_ass_subscript = (objobjargproc)obj_setitem,
623 static PyTypeObject PyTdb = {
624 .tp_name = "tdb.Tdb",
625 .tp_basicsize = sizeof(PyTdbObject),
626 .tp_methods = tdb_object_methods,
627 .tp_getset = tdb_object_getsetters,
628 .tp_new = py_tdb_open,
629 .tp_doc = "A TDB file",
630 .tp_repr = (reprfunc)tdb_object_repr,
631 .tp_dealloc = (destructor)tdb_object_dealloc,
632 .tp_as_mapping = &tdb_object_mapping,
633 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_ITER,
634 .tp_iter = (getiterfunc)tdb_object_iter,
637 static PyMethodDef tdb_methods[] = {
638 { "open", (PyCFunction)py_tdb_open, METH_VARARGS|METH_KEYWORDS, "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, flags=O_RDWR, mode=0600)\n"
639 "Open a TDB file." },
640 { NULL }
643 void inittdb(void);
644 void inittdb(void)
646 PyObject *m;
648 if (PyType_Ready(&PyTdb) < 0)
649 return;
651 if (PyType_Ready(&PyTdbIterator) < 0)
652 return;
654 m = Py_InitModule3("tdb", tdb_methods,
655 "simple key-value database that supports multiple writers.");
656 if (m == NULL)
657 return;
659 PyModule_AddObject(m, "REPLACE", PyInt_FromLong(TDB_REPLACE));
660 PyModule_AddObject(m, "INSERT", PyInt_FromLong(TDB_INSERT));
661 PyModule_AddObject(m, "MODIFY", PyInt_FromLong(TDB_MODIFY));
663 PyModule_AddObject(m, "DEFAULT", PyInt_FromLong(TDB_DEFAULT));
664 PyModule_AddObject(m, "CLEAR_IF_FIRST", PyInt_FromLong(TDB_CLEAR_IF_FIRST));
665 PyModule_AddObject(m, "INTERNAL", PyInt_FromLong(TDB_INTERNAL));
666 PyModule_AddObject(m, "NOLOCK", PyInt_FromLong(TDB_NOLOCK));
667 PyModule_AddObject(m, "NOMMAP", PyInt_FromLong(TDB_NOMMAP));
668 PyModule_AddObject(m, "CONVERT", PyInt_FromLong(TDB_CONVERT));
669 PyModule_AddObject(m, "BIGENDIAN", PyInt_FromLong(TDB_BIGENDIAN));
670 PyModule_AddObject(m, "NOSYNC", PyInt_FromLong(TDB_NOSYNC));
671 PyModule_AddObject(m, "SEQNUM", PyInt_FromLong(TDB_SEQNUM));
672 PyModule_AddObject(m, "VOLATILE", PyInt_FromLong(TDB_VOLATILE));
673 PyModule_AddObject(m, "ALLOW_NESTING", PyInt_FromLong(TDB_ALLOW_NESTING));
674 PyModule_AddObject(m, "DISALLOW_NESTING", PyInt_FromLong(TDB_DISALLOW_NESTING));
675 PyModule_AddObject(m, "INCOMPATIBLE_HASH", PyInt_FromLong(TDB_INCOMPATIBLE_HASH));
677 PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText"));
679 PyModule_AddObject(m, "__version__", PyString_FromString(PACKAGE_VERSION));
681 Py_INCREF(&PyTdb);
682 PyModule_AddObject(m, "Tdb", (PyObject *)&PyTdb);
684 Py_INCREF(&PyTdbIterator);