summaryrefslogtreecommitdiffstats
path: root/Modules/gdbmmodule.c
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2008-02-25 22:33:55 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2008-02-25 22:33:55 (GMT)
commitdf4198915a5329ba300e29d187febdf8bae65b74 (patch)
tree8c9dfa8da83bb3c81f4c2dd0983eaee334da0dd1 /Modules/gdbmmodule.c
parentfd429063e16739b152441d49371298a9b0341cb9 (diff)
downloadcpython-df4198915a5329ba300e29d187febdf8bae65b74.zip
cpython-df4198915a5329ba300e29d187febdf8bae65b74.tar.gz
cpython-df4198915a5329ba300e29d187febdf8bae65b74.tar.bz2
Issue 2168. gdbm and dbm needs to be iterable; this fixes a
failure in the shelve module. Thanks Thomas Herve.
Diffstat (limited to 'Modules/gdbmmodule.c')
-rw-r--r--Modules/gdbmmodule.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c
index db83a54..8d3e048 100644
--- a/Modules/gdbmmodule.c
+++ b/Modules/gdbmmodule.c
@@ -178,6 +178,33 @@ dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
return 0;
}
+static int
+dbm_contains(register dbmobject *dp, PyObject *v)
+{
+ datum key;
+
+ if (PyString_AsStringAndSize(v, &key.dptr, &key.dsize)) {
+ return -1;
+ }
+
+ check_dbmobject_open(dp);
+
+ return gdbm_exists(dp->di_dbm, key);
+}
+
+static PySequenceMethods dbm_as_sequence = {
+ (lenfunc)dbm_length, /*_length*/
+ 0, /*sq_concat*/
+ 0, /*sq_repeat*/
+ 0, /*sq_item*/
+ 0, /*sq_slice*/
+ 0, /*sq_ass_item*/
+ 0, /*sq_ass_slice*/
+ (objobjproc)dbm_contains, /*sq_contains*/
+ 0, /*sq_inplace_concat*/
+ 0 /*sq_inplace_repeat*/
+};
+
static PyMappingMethods dbm_as_mapping = {
(lenfunc)dbm_length, /*mp_length*/
(binaryfunc)dbm_subscript, /*mp_subscript*/
@@ -381,7 +408,7 @@ static PyTypeObject Dbmtype = {
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
+ &dbm_as_sequence, /*tp_as_sequence*/
&dbm_as_mapping, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
@@ -389,7 +416,7 @@ static PyTypeObject Dbmtype = {
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
- 0, /*tp_xxx4*/
+ Py_TPFLAGS_DEFAULT, /*tp_xxx4*/
gdbm_object__doc__, /*tp_doc*/
};