[Python-3000-checkins] r57020 - in python/branches/py3k: Lib/test/test_dbm.py Modules/dbmmodule.c

guido.van.rossum python-3000-checkins at python.org
Tue Aug 14 17:42:46 CEST 2007


Author: guido.van.rossum
Date: Tue Aug 14 17:42:45 2007
New Revision: 57020

Modified:
   python/branches/py3k/Lib/test/test_dbm.py
   python/branches/py3k/Modules/dbmmodule.c
Log:
The dbm module should use bytes for keys.  This makes test_shelve pass.


Modified: python/branches/py3k/Lib/test/test_dbm.py
==============================================================================
--- python/branches/py3k/Lib/test/test_dbm.py	(original)
+++ python/branches/py3k/Lib/test/test_dbm.py	Tue Aug 14 17:42:45 2007
@@ -26,10 +26,10 @@
 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())
 

Modified: python/branches/py3k/Modules/dbmmodule.c
==============================================================================
--- python/branches/py3k/Modules/dbmmodule.c	(original)
+++ python/branches/py3k/Modules/dbmmodule.c	Tue Aug 14 17:42:45 2007
@@ -188,7 +188,7 @@
 		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 @@
 		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 @@
 	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);


More information about the Python-3000-checkins mailing list