libsmb: Make cli_smb2_create_fnum async
[Samba.git] / lib / tdb / pytdb.c
blob93207992cb6719ad81369feed8a444499618d1c5
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 };
95 char **kwnames = discard_const_p(char *, _kwnames);
97 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siiii", kwnames, &name, &hash_size, &tdb_flags, &flags, &mode))
98 return NULL;
100 if (name == NULL) {
101 tdb_flags |= TDB_INTERNAL;
104 ctx = tdb_open(name, hash_size, tdb_flags, flags, mode);
105 if (ctx == NULL) {
106 PyErr_SetFromErrno(PyExc_IOError);
107 return NULL;
110 ret = PyObject_New(PyTdbObject, &PyTdb);
111 if (!ret) {
112 tdb_close(ctx);
113 return NULL;
116 ret->ctx = ctx;
117 ret->closed = false;
118 return (PyObject *)ret;
121 static PyObject *obj_transaction_cancel(PyTdbObject *self)
123 int ret;
125 PyErr_TDB_RAISE_IF_CLOSED(self);
127 ret = tdb_transaction_cancel(self->ctx);
128 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
129 Py_RETURN_NONE;
132 static PyObject *obj_transaction_commit(PyTdbObject *self)
134 int ret;
135 PyErr_TDB_RAISE_IF_CLOSED(self);
136 ret = tdb_transaction_commit(self->ctx);
137 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
138 Py_RETURN_NONE;
141 static PyObject *obj_transaction_prepare_commit(PyTdbObject *self)
143 int ret;
144 PyErr_TDB_RAISE_IF_CLOSED(self);
145 ret = tdb_transaction_prepare_commit(self->ctx);
146 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
147 Py_RETURN_NONE;
150 static PyObject *obj_transaction_start(PyTdbObject *self)
152 int ret;
153 PyErr_TDB_RAISE_IF_CLOSED(self);
154 ret = tdb_transaction_start(self->ctx);
155 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
156 Py_RETURN_NONE;
159 static PyObject *obj_reopen(PyTdbObject *self)
161 int ret;
162 PyErr_TDB_RAISE_IF_CLOSED(self);
163 ret = tdb_reopen(self->ctx);
164 if (ret != 0) {
165 self->closed = true;
166 PyErr_SetObject(PyExc_RuntimeError,
167 Py_BuildValue("(i,s)",
168 TDB_ERR_IO,
169 "Failed to reopen database"));
170 return NULL;
172 Py_RETURN_NONE;
175 static PyObject *obj_lockall(PyTdbObject *self)
177 int ret;
178 PyErr_TDB_RAISE_IF_CLOSED(self);
179 ret = tdb_lockall(self->ctx);
180 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
181 Py_RETURN_NONE;
184 static PyObject *obj_unlockall(PyTdbObject *self)
186 int ret;
187 PyErr_TDB_RAISE_IF_CLOSED(self);
188 ret = tdb_unlockall(self->ctx);
189 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
190 Py_RETURN_NONE;
193 static PyObject *obj_lockall_read(PyTdbObject *self)
195 int ret;
196 PyErr_TDB_RAISE_IF_CLOSED(self);
197 ret = tdb_lockall_read(self->ctx);
198 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
199 Py_RETURN_NONE;
202 static PyObject *obj_unlockall_read(PyTdbObject *self)
204 int ret = tdb_unlockall_read(self->ctx);
205 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
206 Py_RETURN_NONE;
209 static PyObject *obj_close(PyTdbObject *self)
211 int ret;
212 if (self->closed)
213 Py_RETURN_NONE;
214 ret = tdb_close(self->ctx);
215 self->closed = true;
216 if (ret != 0) {
217 PyErr_SetObject(PyExc_RuntimeError,
218 Py_BuildValue("(i,s)",
219 TDB_ERR_IO,
220 "Failed to close database"));
221 return NULL;
223 Py_RETURN_NONE;
226 static PyObject *obj_get(PyTdbObject *self, PyObject *args)
228 TDB_DATA key;
229 PyObject *py_key;
231 PyErr_TDB_RAISE_IF_CLOSED(self);
233 if (!PyArg_ParseTuple(args, "O", &py_key))
234 return NULL;
236 key = PyString_AsTDB_DATA(py_key);
237 if (!key.dptr)
238 return NULL;
240 return PyString_FromTDB_DATA(tdb_fetch(self->ctx, key));
243 static PyObject *obj_append(PyTdbObject *self, PyObject *args)
245 TDB_DATA key, data;
246 PyObject *py_key, *py_data;
247 int ret;
249 PyErr_TDB_RAISE_IF_CLOSED(self);
251 if (!PyArg_ParseTuple(args, "OO", &py_key, &py_data))
252 return NULL;
254 key = PyString_AsTDB_DATA(py_key);
255 if (!key.dptr)
256 return NULL;
257 data = PyString_AsTDB_DATA(py_data);
258 if (!data.dptr)
259 return NULL;
261 ret = tdb_append(self->ctx, key, data);
262 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
263 Py_RETURN_NONE;
266 static PyObject *obj_firstkey(PyTdbObject *self)
268 PyErr_TDB_RAISE_IF_CLOSED(self);
270 return PyString_FromTDB_DATA(tdb_firstkey(self->ctx));
273 static PyObject *obj_nextkey(PyTdbObject *self, PyObject *args)
275 TDB_DATA key;
276 PyObject *py_key;
277 PyErr_TDB_RAISE_IF_CLOSED(self);
279 if (!PyArg_ParseTuple(args, "O", &py_key))
280 return NULL;
282 key = PyString_AsTDB_DATA(py_key);
283 if (!key.dptr)
284 return NULL;
286 return PyString_FromTDB_DATA(tdb_nextkey(self->ctx, key));
289 static PyObject *obj_delete(PyTdbObject *self, PyObject *args)
291 TDB_DATA key;
292 PyObject *py_key;
293 int ret;
294 PyErr_TDB_RAISE_IF_CLOSED(self);
296 if (!PyArg_ParseTuple(args, "O", &py_key))
297 return NULL;
299 key = PyString_AsTDB_DATA(py_key);
300 if (!key.dptr)
301 return NULL;
302 ret = tdb_delete(self->ctx, key);
303 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
304 Py_RETURN_NONE;
307 static PyObject *obj_has_key(PyTdbObject *self, PyObject *args)
309 TDB_DATA key;
310 int ret;
311 PyObject *py_key;
312 PyErr_TDB_RAISE_IF_CLOSED(self);
314 if (!PyArg_ParseTuple(args, "O", &py_key))
315 return NULL;
317 key = PyString_AsTDB_DATA(py_key);
318 if (!key.dptr)
319 return NULL;
320 ret = tdb_exists(self->ctx, key);
321 if (ret != TDB_ERR_NOEXIST) {
322 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
325 return (ret == TDB_ERR_NOEXIST)?Py_False:Py_True;
328 static PyObject *obj_store(PyTdbObject *self, PyObject *args)
330 TDB_DATA key, value;
331 int ret;
332 int flag = TDB_REPLACE;
333 PyObject *py_key, *py_value;
335 PyErr_TDB_RAISE_IF_CLOSED(self);
337 if (!PyArg_ParseTuple(args, "OO|i", &py_key, &py_value, &flag))
338 return NULL;
340 key = PyString_AsTDB_DATA(py_key);
341 if (!key.dptr)
342 return NULL;
343 value = PyString_AsTDB_DATA(py_value);
344 if (!value.dptr)
345 return NULL;
347 ret = tdb_store(self->ctx, key, value, flag);
348 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
349 Py_RETURN_NONE;
352 static PyObject *obj_add_flags(PyTdbObject *self, PyObject *args)
354 unsigned flags;
356 PyErr_TDB_RAISE_IF_CLOSED(self);
358 if (!PyArg_ParseTuple(args, "I", &flags))
359 return NULL;
361 tdb_add_flags(self->ctx, flags);
362 Py_RETURN_NONE;
365 static PyObject *obj_remove_flags(PyTdbObject *self, PyObject *args)
367 unsigned flags;
369 PyErr_TDB_RAISE_IF_CLOSED(self);
371 if (!PyArg_ParseTuple(args, "I", &flags))
372 return NULL;
374 tdb_remove_flags(self->ctx, flags);
375 Py_RETURN_NONE;
378 typedef struct {
379 PyObject_HEAD
380 TDB_DATA current;
381 PyTdbObject *iteratee;
382 } PyTdbIteratorObject;
384 static PyObject *tdb_iter_next(PyTdbIteratorObject *self)
386 TDB_DATA current;
387 PyObject *ret;
388 if (self->current.dptr == NULL && self->current.dsize == 0)
389 return NULL;
390 current = self->current;
391 self->current = tdb_nextkey(self->iteratee->ctx, self->current);
392 ret = PyString_FromTDB_DATA(current);
393 return ret;
396 static void tdb_iter_dealloc(PyTdbIteratorObject *self)
398 Py_DECREF(self->iteratee);
399 PyObject_Del(self);
402 PyTypeObject PyTdbIterator = {
403 .tp_name = "Iterator",
404 .tp_basicsize = sizeof(PyTdbIteratorObject),
405 .tp_iternext = (iternextfunc)tdb_iter_next,
406 .tp_dealloc = (destructor)tdb_iter_dealloc,
407 .tp_flags = Py_TPFLAGS_DEFAULT,
408 .tp_iter = PyObject_SelfIter,
411 static PyObject *tdb_object_iter(PyTdbObject *self)
413 PyTdbIteratorObject *ret;
415 PyErr_TDB_RAISE_IF_CLOSED(self);
417 ret = PyObject_New(PyTdbIteratorObject, &PyTdbIterator);
418 if (!ret)
419 return NULL;
420 ret->current = tdb_firstkey(self->ctx);
421 ret->iteratee = self;
422 Py_INCREF(self);
423 return (PyObject *)ret;
426 static PyObject *obj_clear(PyTdbObject *self)
428 int ret;
429 PyErr_TDB_RAISE_IF_CLOSED(self);
430 ret = tdb_wipe_all(self->ctx);
431 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
432 Py_RETURN_NONE;
435 static PyObject *obj_repack(PyTdbObject *self)
437 int ret;
438 PyErr_TDB_RAISE_IF_CLOSED(self);
439 ret = tdb_repack(self->ctx);
440 PyErr_TDB_ERROR_IS_ERR_RAISE(ret, self->ctx);
441 Py_RETURN_NONE;
444 static PyObject *obj_enable_seqnum(PyTdbObject *self)
446 PyErr_TDB_RAISE_IF_CLOSED(self);
447 tdb_enable_seqnum(self->ctx);
448 Py_RETURN_NONE;
451 static PyObject *obj_increment_seqnum_nonblock(PyTdbObject *self)
453 PyErr_TDB_RAISE_IF_CLOSED(self);
454 tdb_increment_seqnum_nonblock(self->ctx);
455 Py_RETURN_NONE;
458 static PyMethodDef tdb_object_methods[] = {
459 { "transaction_cancel", (PyCFunction)obj_transaction_cancel, METH_NOARGS,
460 "S.transaction_cancel() -> None\n"
461 "Cancel the currently active transaction." },
462 { "transaction_commit", (PyCFunction)obj_transaction_commit, METH_NOARGS,
463 "S.transaction_commit() -> None\n"
464 "Commit the currently active transaction." },
465 { "transaction_prepare_commit", (PyCFunction)obj_transaction_prepare_commit, METH_NOARGS,
466 "S.transaction_prepare_commit() -> None\n"
467 "Prepare to commit the currently active transaction" },
468 { "transaction_start", (PyCFunction)obj_transaction_start, METH_NOARGS,
469 "S.transaction_start() -> None\n"
470 "Start a new transaction." },
471 { "reopen", (PyCFunction)obj_reopen, METH_NOARGS, "Reopen this file." },
472 { "lock_all", (PyCFunction)obj_lockall, METH_NOARGS, NULL },
473 { "unlock_all", (PyCFunction)obj_unlockall, METH_NOARGS, NULL },
474 { "read_lock_all", (PyCFunction)obj_lockall_read, METH_NOARGS, NULL },
475 { "read_unlock_all", (PyCFunction)obj_unlockall_read, METH_NOARGS, NULL },
476 { "close", (PyCFunction)obj_close, METH_NOARGS, NULL },
477 { "get", (PyCFunction)obj_get, METH_VARARGS, "S.get(key) -> value\n"
478 "Fetch a value." },
479 { "append", (PyCFunction)obj_append, METH_VARARGS, "S.append(key, value) -> None\n"
480 "Append data to an existing key." },
481 { "firstkey", (PyCFunction)obj_firstkey, METH_NOARGS, "S.firstkey() -> data\n"
482 "Return the first key in this database." },
483 { "nextkey", (PyCFunction)obj_nextkey, METH_NOARGS, "S.nextkey(key) -> data\n"
484 "Return the next key in this database." },
485 { "delete", (PyCFunction)obj_delete, METH_VARARGS, "S.delete(key) -> None\n"
486 "Delete an entry." },
487 { "has_key", (PyCFunction)obj_has_key, METH_VARARGS, "S.has_key(key) -> None\n"
488 "Check whether key exists in this database." },
489 { "store", (PyCFunction)obj_store, METH_VARARGS, "S.store(key, data, flag=REPLACE) -> None"
490 "Store data." },
491 { "add_flags", (PyCFunction)obj_add_flags, METH_VARARGS, "S.add_flags(flags) -> None" },
492 { "remove_flags", (PyCFunction)obj_remove_flags, METH_VARARGS, "S.remove_flags(flags) -> None" },
493 { "iterkeys", (PyCFunction)tdb_object_iter, METH_NOARGS, "S.iterkeys() -> iterator" },
494 { "clear", (PyCFunction)obj_clear, METH_NOARGS, "S.clear() -> None\n"
495 "Wipe the entire database." },
496 { "repack", (PyCFunction)obj_repack, METH_NOARGS, "S.repack() -> None\n"
497 "Repack the entire database." },
498 { "enable_seqnum", (PyCFunction)obj_enable_seqnum, METH_NOARGS,
499 "S.enable_seqnum() -> None" },
500 { "increment_seqnum_nonblock", (PyCFunction)obj_increment_seqnum_nonblock, METH_NOARGS,
501 "S.increment_seqnum_nonblock() -> None" },
502 { NULL }
505 static PyObject *obj_get_hash_size(PyTdbObject *self, void *closure)
507 PyErr_TDB_RAISE_IF_CLOSED(self);
508 return PyInt_FromLong(tdb_hash_size(self->ctx));
511 static int obj_set_max_dead(PyTdbObject *self, PyObject *max_dead, void *closure)
513 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
514 if (!PyInt_Check(max_dead))
515 return -1;
516 tdb_set_max_dead(self->ctx, PyInt_AsLong(max_dead));
517 return 0;
520 static PyObject *obj_get_map_size(PyTdbObject *self, void *closure)
522 PyErr_TDB_RAISE_IF_CLOSED(self);
523 return PyInt_FromLong(tdb_map_size(self->ctx));
526 static PyObject *obj_get_freelist_size(PyTdbObject *self, void *closure)
528 PyErr_TDB_RAISE_IF_CLOSED(self);
529 return PyInt_FromLong(tdb_freelist_size(self->ctx));
532 static PyObject *obj_get_flags(PyTdbObject *self, void *closure)
534 PyErr_TDB_RAISE_IF_CLOSED(self);
535 return PyInt_FromLong(tdb_get_flags(self->ctx));
538 static PyObject *obj_get_filename(PyTdbObject *self, void *closure)
540 PyErr_TDB_RAISE_IF_CLOSED(self);
541 return PyString_FromString(tdb_name(self->ctx));
544 static PyObject *obj_get_seqnum(PyTdbObject *self, void *closure)
546 PyErr_TDB_RAISE_IF_CLOSED(self);
547 return PyInt_FromLong(tdb_get_seqnum(self->ctx));
551 static PyGetSetDef tdb_object_getsetters[] = {
552 { discard_const_p(char, "hash_size"),
553 (getter)obj_get_hash_size, NULL, NULL },
554 { discard_const_p(char, "map_size"),
555 (getter)obj_get_map_size, NULL, NULL },
556 { discard_const_p(char, "freelist_size"),
557 (getter)obj_get_freelist_size, NULL, NULL },
558 { discard_const_p(char, "flags"),
559 (getter)obj_get_flags, NULL, NULL },
560 { discard_const_p(char, "max_dead"),
561 NULL, (setter)obj_set_max_dead, NULL },
562 { discard_const_p(char, "filename"),
563 (getter)obj_get_filename, NULL,
564 discard_const_p(char, "The filename of this TDB file.") },
565 { discard_const_p(char, "seqnum"),
566 (getter)obj_get_seqnum, NULL, NULL },
567 { NULL }
570 static PyObject *tdb_object_repr(PyTdbObject *self)
572 PyErr_TDB_RAISE_IF_CLOSED(self);
573 if (tdb_get_flags(self->ctx) & TDB_INTERNAL) {
574 return PyString_FromString("Tdb(<internal>)");
575 } else {
576 return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx));
580 static void tdb_object_dealloc(PyTdbObject *self)
582 if (!self->closed)
583 tdb_close(self->ctx);
584 self->ob_type->tp_free(self);
587 static PyObject *obj_getitem(PyTdbObject *self, PyObject *key)
589 TDB_DATA tkey, val;
590 PyErr_TDB_RAISE_IF_CLOSED(self);
591 if (!PyString_Check(key)) {
592 PyErr_SetString(PyExc_TypeError, "Expected string as key");
593 return NULL;
596 tkey.dptr = (unsigned char *)PyString_AsString(key);
597 tkey.dsize = PyString_Size(key);
599 val = tdb_fetch(self->ctx, tkey);
600 if (val.dptr == NULL) {
601 PyErr_SetString(PyExc_KeyError, "No such TDB entry");
602 return NULL;
603 } else {
604 return PyString_FromTDB_DATA(val);
608 static int obj_setitem(PyTdbObject *self, PyObject *key, PyObject *value)
610 TDB_DATA tkey, tval;
611 int ret;
612 PyErr_TDB_RAISE_RETURN_MINUS_1_IF_CLOSED(self);
613 if (!PyString_Check(key)) {
614 PyErr_SetString(PyExc_TypeError, "Expected string as key");
615 return -1;
618 tkey = PyString_AsTDB_DATA(key);
620 if (value == NULL) {
621 ret = tdb_delete(self->ctx, tkey);
622 } else {
623 if (!PyString_Check(value)) {
624 PyErr_SetString(PyExc_TypeError, "Expected string as value");
625 return -1;
628 tval = PyString_AsTDB_DATA(value);
630 ret = tdb_store(self->ctx, tkey, tval, TDB_REPLACE);
633 if (ret != 0) {
634 PyErr_SetTDBError(self->ctx);
635 return -1;
638 return ret;
641 static PyMappingMethods tdb_object_mapping = {
642 .mp_subscript = (binaryfunc)obj_getitem,
643 .mp_ass_subscript = (objobjargproc)obj_setitem,
645 static PyTypeObject PyTdb = {
646 .tp_name = "tdb.Tdb",
647 .tp_basicsize = sizeof(PyTdbObject),
648 .tp_methods = tdb_object_methods,
649 .tp_getset = tdb_object_getsetters,
650 .tp_new = py_tdb_open,
651 .tp_doc = "A TDB file",
652 .tp_repr = (reprfunc)tdb_object_repr,
653 .tp_dealloc = (destructor)tdb_object_dealloc,
654 .tp_as_mapping = &tdb_object_mapping,
655 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_ITER,
656 .tp_iter = (getiterfunc)tdb_object_iter,
659 static PyMethodDef tdb_methods[] = {
660 { "open", (PyCFunction)py_tdb_open, METH_VARARGS|METH_KEYWORDS, "open(name, hash_size=0, tdb_flags=TDB_DEFAULT, flags=O_RDWR, mode=0600)\n"
661 "Open a TDB file." },
662 { NULL }
665 void inittdb(void);
666 void inittdb(void)
668 PyObject *m;
670 if (PyType_Ready(&PyTdb) < 0)
671 return;
673 if (PyType_Ready(&PyTdbIterator) < 0)
674 return;
676 m = Py_InitModule3("tdb", tdb_methods,
677 "simple key-value database that supports multiple writers.");
678 if (m == NULL)
679 return;
681 PyModule_AddObject(m, "REPLACE", PyInt_FromLong(TDB_REPLACE));
682 PyModule_AddObject(m, "INSERT", PyInt_FromLong(TDB_INSERT));
683 PyModule_AddObject(m, "MODIFY", PyInt_FromLong(TDB_MODIFY));
685 PyModule_AddObject(m, "DEFAULT", PyInt_FromLong(TDB_DEFAULT));
686 PyModule_AddObject(m, "CLEAR_IF_FIRST", PyInt_FromLong(TDB_CLEAR_IF_FIRST));
687 PyModule_AddObject(m, "INTERNAL", PyInt_FromLong(TDB_INTERNAL));
688 PyModule_AddObject(m, "NOLOCK", PyInt_FromLong(TDB_NOLOCK));
689 PyModule_AddObject(m, "NOMMAP", PyInt_FromLong(TDB_NOMMAP));
690 PyModule_AddObject(m, "CONVERT", PyInt_FromLong(TDB_CONVERT));
691 PyModule_AddObject(m, "BIGENDIAN", PyInt_FromLong(TDB_BIGENDIAN));
692 PyModule_AddObject(m, "NOSYNC", PyInt_FromLong(TDB_NOSYNC));
693 PyModule_AddObject(m, "SEQNUM", PyInt_FromLong(TDB_SEQNUM));
694 PyModule_AddObject(m, "VOLATILE", PyInt_FromLong(TDB_VOLATILE));
695 PyModule_AddObject(m, "ALLOW_NESTING", PyInt_FromLong(TDB_ALLOW_NESTING));
696 PyModule_AddObject(m, "DISALLOW_NESTING", PyInt_FromLong(TDB_DISALLOW_NESTING));
697 PyModule_AddObject(m, "INCOMPATIBLE_HASH", PyInt_FromLong(TDB_INCOMPATIBLE_HASH));
699 PyModule_AddObject(m, "__docformat__", PyString_FromString("restructuredText"));
701 PyModule_AddObject(m, "__version__", PyString_FromString(PACKAGE_VERSION));
703 Py_INCREF(&PyTdb);
704 PyModule_AddObject(m, "Tdb", (PyObject *)&PyTdb);
706 Py_INCREF(&PyTdbIterator);