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/Lib/sqlite3/dbapi2.py b/Lib/sqlite3/dbapi2.py
index 52fb4ae..d051f04 100644
--- a/Lib/sqlite3/dbapi2.py
+++ b/Lib/sqlite3/dbapi2.py
@@ -60,13 +60,13 @@
         return val.isoformat(" ")
 
     def convert_date(val):
-        return datetime.date(*map(int, val.split("-")))
+        return datetime.date(*map(int, val.split(b"-")))
 
     def convert_timestamp(val):
-        datepart, timepart = val.split(" ")
-        year, month, day = map(int, datepart.split("-"))
-        timepart_full = timepart.split(".")
-        hours, minutes, seconds = map(int, timepart_full[0].split(":"))
+        datepart, timepart = val.split(b" ")
+        year, month, day = map(int, datepart.split(b"-"))
+        timepart_full = timepart.split(b".")
+        hours, minutes, seconds = map(int, timepart_full[0].split(b":"))
         if len(timepart_full) == 2:
             microseconds = int(timepart_full[1])
         else:
diff --git a/Lib/sqlite3/test/factory.py b/Lib/sqlite3/test/factory.py
index f20848f..a9a828f 100644
--- a/Lib/sqlite3/test/factory.py
+++ b/Lib/sqlite3/test/factory.py
@@ -163,8 +163,8 @@
         germany = "Deutchland"
         a_row = self.con.execute("select ?", (austria,)).fetchone()
         d_row = self.con.execute("select ?", (germany,)).fetchone()
-        self.failUnless(type(a_row[0]) == str, "type of non-ASCII row must be unicode")
-        self.failUnless(type(d_row[0]) == str8, "type of ASCII-only row must be str8")
+        self.failUnless(type(a_row[0]) == str, "type of non-ASCII row must be str")
+        self.failUnless(type(d_row[0]) == str, "type of ASCII-only row must be str")
 
     def tearDown(self):
         self.con.close()
diff --git a/Lib/sqlite3/test/types.py b/Lib/sqlite3/test/types.py
index 4ff948d..8845e0c 100644
--- a/Lib/sqlite3/test/types.py
+++ b/Lib/sqlite3/test/types.py
@@ -62,11 +62,12 @@
         self.failUnlessEqual(row[0], val)
 
     def CheckBlob(self):
-        val = memoryview(b"Guglhupf")
+        sample = b"Guglhupf"
+        val = memoryview(sample)
         self.cur.execute("insert into test(b) values (?)", (val,))
         self.cur.execute("select b from test")
         row = self.cur.fetchone()
-        self.failUnlessEqual(row[0], val)
+        self.failUnlessEqual(row[0], sample)
 
     def CheckUnicodeExecute(self):
         self.cur.execute("select 'Österreich'")
@@ -76,8 +77,8 @@
 class DeclTypesTests(unittest.TestCase):
     class Foo:
         def __init__(self, _val):
-            if isinstance(_val, str8):
-                # sqlite3 always calls __init__ with a str8 created from a
+            if isinstance(_val, bytes):
+                # sqlite3 always calls __init__ with a bytes created from a
                 # UTF-8 string when __conform__ was used to store the object.
                 _val = _val.decode('utf8')
             self.val = _val
@@ -207,11 +208,12 @@
 
     def CheckBlob(self):
         # default
-        val = memoryview(b"Guglhupf")
+        sample = b"Guglhupf"
+        val = memoryview(sample)
         self.cur.execute("insert into test(bin) values (?)", (val,))
         self.cur.execute("select bin from test")
         row = self.cur.fetchone()
-        self.failUnlessEqual(row[0], val)
+        self.failUnlessEqual(row[0], sample)
 
 class ColNamesTests(unittest.TestCase):
     def setUp(self):
@@ -219,13 +221,11 @@
         self.cur = self.con.cursor()
         self.cur.execute("create table test(x foo)")
 
-        sqlite.converters["FOO"] = lambda x: "[%s]" % x
-        sqlite.converters["BAR"] = lambda x: "<%s>" % x
+        sqlite.converters["BAR"] = lambda x: b"<" + x + b">"
         sqlite.converters["EXC"] = lambda x: 5/0
         sqlite.converters["B1B1"] = lambda x: "MARKER"
 
     def tearDown(self):
-        del sqlite.converters["FOO"]
         del sqlite.converters["BAR"]
         del sqlite.converters["EXC"]
         del sqlite.converters["B1B1"]
@@ -252,14 +252,14 @@
         self.cur.execute("insert into test(x) values (?)", ("xxx",))
         self.cur.execute('select x as "x [bar]" from test')
         val = self.cur.fetchone()[0]
-        self.failUnlessEqual(val, "<xxx>")
+        self.failUnlessEqual(val, b"<xxx>")
 
         # Check if the stripping of colnames works. Everything after the first
         # whitespace should be stripped.
         self.failUnlessEqual(self.cur.description[0][0], "x")
 
     def CheckCaseInConverterName(self):
-        self.cur.execute("""select 'other' as "x [b1b1]\"""")
+        self.cur.execute("select 'other' as \"x [b1b1]\"")
         val = self.cur.fetchone()[0]
         self.failUnlessEqual(val, "MARKER")
 
diff --git a/Lib/sqlite3/test/userfunctions.py b/Lib/sqlite3/test/userfunctions.py
index 994057e..dc3a709 100644
--- a/Lib/sqlite3/test/userfunctions.py
+++ b/Lib/sqlite3/test/userfunctions.py
@@ -198,7 +198,7 @@
         cur.execute("select returnblob()")
         val = cur.fetchone()[0]
         self.failUnlessEqual(type(val), bytes)
-        self.failUnlessEqual(val, memoryview(b"blob"))
+        self.failUnlessEqual(val, b"blob")
 
     def CheckFuncException(self):
         cur = self.con.cursor()