Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137
branch.  The most obvious changes:

  - str8 renamed to bytes (PyString at the C level);
  - bytes renamed to buffer (PyBytes at the C level);
  - PyString and PyUnicode are no longer compatible.

I.e. we now have an immutable bytes type and a mutable bytes type.

The behavior of PyString was modified quite a bit, to make it more
bytes-like.  Some changes are still on the to-do list.
diff --git a/Modules/_bsddb.c b/Modules/_bsddb.c
index bd1c271..0587071 100644
--- a/Modules/_bsddb.c
+++ b/Modules/_bsddb.c
@@ -1171,13 +1171,16 @@
         else if (PyInt_Check(result)) {
             retval = PyInt_AsLong(result);
         }
-        else if (PyBytes_Check(result)) {
+        else if (PyBytes_Check(result) || PyString_Check(result)) {
             char* data;
             Py_ssize_t size;
 
             CLEAR_DBT(*secKey);
-            size = PyBytes_Size(result);
-            data = PyBytes_AsString(result);
+            size = Py_Size(result);
+            if (PyBytes_Check(result))
+                data = PyBytes_AS_STRING(result);
+            else
+                data = PyString_AS_STRING(result);
             secKey->flags = DB_DBT_APPMALLOC;   /* DB will free */
             secKey->data = malloc(size);        /* TODO, check this */
 	    if (secKey->data) {
@@ -1517,7 +1520,7 @@
             retval = Py_BuildValue("y#y#", key.data, key.size, data.data,
                                    data.size);
         else /* return just the data */
-            retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
+            retval = PyString_FromStringAndSize((char*)data.data, data.size);
         free_dbt(&data);
     }
     FREE_DBT_VIEW(key, keyobj, key_buf_view);
@@ -1587,13 +1590,13 @@
     else if (!err) {
         PyObject *pkeyObj;
         PyObject *dataObj;
-        dataObj = PyBytes_FromStringAndSize(data.data, data.size);
+        dataObj = PyString_FromStringAndSize(data.data, data.size);
 
         if (self->primaryDBType == DB_RECNO ||
             self->primaryDBType == DB_QUEUE)
             pkeyObj = PyInt_FromLong(*(int *)pkey.data);
         else
-            pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size);
+            pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size);
 
         if (flags & DB_SET_RECNO) /* return key , pkey and data */
         {
@@ -1602,7 +1605,7 @@
             if (type == DB_RECNO || type == DB_QUEUE)
                 keyObj = PyInt_FromLong(*(int *)key.data);
             else
-                keyObj = PyBytes_FromStringAndSize(key.data, key.size);
+                keyObj = PyString_FromStringAndSize(key.data, key.size);
 #if (PY_VERSION_HEX >= 0x02040000)
             retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
 #else
@@ -1729,7 +1732,8 @@
     else if (!err) {
         /* XXX(nnorwitz): can we do: retval = dataobj; Py_INCREF(retval); */
         /* XXX(gps) I think not: buffer API input vs. bytes object output. */
-        retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
+        /* XXX(guido) But what if the input is PyString? */
+        retval = PyString_FromStringAndSize((char*)data.data, data.size);
 
         /* Even though the flags require DB_DBT_MALLOC, data is not always
            allocated.  4.4: allocated, 4.5: *not* allocated. :-( */
@@ -2773,7 +2777,7 @@
         retval = NULL;
     }
     else {
-        retval = PyBytes_FromStringAndSize((char*)data.data, data.size);
+        retval = PyString_FromStringAndSize((char*)data.data, data.size);
         free_dbt(&data);
     }
 
@@ -2928,7 +2932,7 @@
             case DB_BTREE:
             case DB_HASH:
             default:
-                item = PyBytes_FromStringAndSize((char*)key.data, key.size);
+                item = PyString_FromStringAndSize((char*)key.data, key.size);
                 break;
             case DB_RECNO:
             case DB_QUEUE:
@@ -2938,7 +2942,7 @@
             break;
 
         case _VALUES_LIST:
-            item = PyBytes_FromStringAndSize((char*)data.data, data.size);
+            item = PyString_FromStringAndSize((char*)data.data, data.size);
             break;
 
         case _ITEMS_LIST:
@@ -3286,13 +3290,13 @@
     else {
         PyObject *pkeyObj;
         PyObject *dataObj;
-        dataObj = PyBytes_FromStringAndSize(data.data, data.size);
+        dataObj = PyString_FromStringAndSize(data.data, data.size);
 
         if (self->mydb->primaryDBType == DB_RECNO ||
             self->mydb->primaryDBType == DB_QUEUE)
             pkeyObj = PyInt_FromLong(*(int *)pkey.data);
         else
-            pkeyObj = PyBytes_FromStringAndSize(pkey.data, pkey.size);
+            pkeyObj = PyString_FromStringAndSize(pkey.data, pkey.size);
 
         if (key.data && key.size) /* return key, pkey and data */
         {
@@ -3301,7 +3305,7 @@
             if (type == DB_RECNO || type == DB_QUEUE)
                 keyObj = PyInt_FromLong(*(int *)key.data);
             else
-                keyObj = PyBytes_FromStringAndSize(key.data, key.size);
+                keyObj = PyString_FromStringAndSize(key.data, key.size);
             retval = PyTuple_Pack(3, keyObj, pkeyObj, dataObj);
             Py_DECREF(keyObj);
         }
@@ -4909,7 +4913,7 @@
     MYDB_END_ALLOW_THREADS
 
     if (!err)
-        retval = PyBytes_FromStringAndSize(key.data, key.size);
+        retval = PyString_FromStringAndSize(key.data, key.size);
 
     free_dbt(&key);
     RETURN_IF_ERR();