diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tdb/pytdb.c | 16 | ||||
-rw-r--r-- | lib/tdb/python/tests/simple.py | 12 |
2 files changed, 15 insertions, 13 deletions
diff --git a/lib/tdb/pytdb.c b/lib/tdb/pytdb.c index 2f0580f1d8..f2638db492 100644 --- a/lib/tdb/pytdb.c +++ b/lib/tdb/pytdb.c @@ -77,15 +77,19 @@ static PyObject *PyString_FromTDB_DATA(TDB_DATA data) static PyObject *py_tdb_open(PyTypeObject *type, PyObject *args, PyObject *kwargs) { - char *name; + char *name = NULL; int hash_size = 0, tdb_flags = TDB_DEFAULT, flags = O_RDWR, mode = 0600; TDB_CONTEXT *ctx; PyTdbObject *ret; const char *kwnames[] = { "name", "hash_size", "tdb_flags", "flags", "mode", NULL }; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", (char **)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|siiii", (char **)kwnames, &name, &hash_size, &tdb_flags, &flags, &mode)) return NULL; + if (name == NULL) { + tdb_flags |= TDB_INTERNAL; + } + ctx = tdb_open(name, hash_size, tdb_flags, flags, mode); if (ctx == NULL) { PyErr_SetFromErrno(PyExc_IOError); @@ -448,9 +452,11 @@ static PyGetSetDef tdb_object_getsetters[] = { static PyObject *tdb_object_repr(PyTdbObject *self) { - return PyString_FromFormat("Tdb('%s')", - (tdb_get_flags(self->ctx) & TDB_INTERNAL) ? "<internal>" - : tdb_name(self->ctx)); + if (tdb_get_flags(self->ctx) & TDB_INTERNAL) { + return PyString_FromString("Tdb(<internal>)"); + } else { + return PyString_FromFormat("Tdb('%s')", tdb_name(self->ctx)); + } } static void tdb_object_dealloc(PyTdbObject *self) diff --git a/lib/tdb/python/tests/simple.py b/lib/tdb/python/tests/simple.py index 7088235536..18180e16bd 100644 --- a/lib/tdb/python/tests/simple.py +++ b/lib/tdb/python/tests/simple.py @@ -18,6 +18,7 @@ class OpenTdbTests(TestCase): tdb.DEFAULT, os.O_RDWR) class CloseTdbTests(TestCase): + def test_double_close(self): self.tdb = tdb.Tdb(tempfile.mkstemp()[1], 0, tdb.DEFAULT, os.O_CREAT|os.O_RDWR) @@ -29,11 +30,12 @@ class CloseTdbTests(TestCase): class InternalTdbTests(TestCase): + def test_repr(self): - self.tdb = tdb.Tdb("whatever", tdb_flags=tdb.INTERNAL) + self.tdb = tdb.Tdb() # repr used to crash on internal db - self.assertEquals(repr(self.tdb), "Tdb('<internal>')") + self.assertEquals(repr(self.tdb), "Tdb(<internal>)") class SimpleTdbTests(TestCase): @@ -127,12 +129,6 @@ class SimpleTdbTests(TestCase): self.tdb.transaction_commit() self.assertEquals("1", self.tdb["bloe"]) - def test_iterator(self): - self.tdb["bloe"] = "2" - self.tdb["bla"] = "hoi" - i = iter(self.tdb) - self.assertEquals(set(["bloe", "bla"]), set([i.next(), i.next()])) - def test_iterkeys(self): self.tdb["bloe"] = "2" self.tdb["bla"] = "25" |