summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-14 15:42:45 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-14 15:42:45 (GMT)
commit956e359579abf3a5fd88783ee625c2e0ca30bf60 (patch)
tree9fdd8898f9ae6fdd72f439c6d3307085ab11ab2e
parent5bcf109c735b2649ae762f9df6c8d1dfcb20a25b (diff)
downloadcpython-956e359579abf3a5fd88783ee625c2e0ca30bf60.zip
cpython-956e359579abf3a5fd88783ee625c2e0ca30bf60.tar.gz
cpython-956e359579abf3a5fd88783ee625c2e0ca30bf60.tar.bz2
The dbm module should use bytes for keys. This makes test_shelve pass.
-rwxr-xr-xLib/test/test_dbm.py6
-rw-r--r--Modules/dbmmodule.c10
2 files changed, 8 insertions, 8 deletions
diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
index ebe37b4..88b0bf6 100755
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -26,10 +26,10 @@ def cleanup():
def test_keys():
d = dbm.open(filename, 'c')
verify(d.keys() == [])
- d['a'] = 'b'
- d['12345678910'] = '019237410982340912840198242'
+ d[b'a'] = b'b'
+ d[b'12345678910'] = b'019237410982340912840198242'
d.keys()
- if 'a' in d:
+ if b'a' in d:
if verbose:
print('Test dbm keys: ', d.keys())
diff --git a/Modules/dbmmodule.c b/Modules/dbmmodule.c
index a6c9e99..5660882 100644
--- a/Modules/dbmmodule.c
+++ b/Modules/dbmmodule.c
@@ -188,7 +188,7 @@ dbm_keys(register dbmobject *dp, PyObject *unused)
return NULL;
for (key = dbm_firstkey(dp->di_dbm); key.dptr;
key = dbm_nextkey(dp->di_dbm)) {
- item = PyString_FromStringAndSize(key.dptr, key.dsize);
+ item = PyBytes_FromStringAndSize(key.dptr, key.dsize);
if (item == NULL) {
Py_DECREF(v);
return NULL;
@@ -219,14 +219,14 @@ dbm_contains(PyObject *self, PyObject *arg)
if (arg == NULL)
return -1;
}
- if (!PyString_Check(arg)) {
+ if (!PyBytes_Check(arg)) {
PyErr_Format(PyExc_TypeError,
"dbm key must be string, not %.100s",
arg->ob_type->tp_name);
return -1;
}
- key.dptr = PyString_AS_STRING(arg);
- key.dsize = PyString_GET_SIZE(arg);
+ key.dptr = PyBytes_AS_STRING(arg);
+ key.dsize = PyBytes_GET_SIZE(arg);
val = dbm_fetch(dp->di_dbm, key);
return val.dptr != NULL;
}
@@ -395,7 +395,7 @@ initdbm(void) {
d = PyModule_GetDict(m);
if (DbmError == NULL)
DbmError = PyErr_NewException("dbm.error", NULL, NULL);
- s = PyString_FromString(which_dbm);
+ s = PyUnicode_FromString(which_dbm);
if (s != NULL) {
PyDict_SetItemString(d, "library", s);
Py_DECREF(s);