mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
a19f80c6df
commit
98297ee781
148 changed files with 2533 additions and 3517 deletions
|
@ -60,13 +60,13 @@ def register_adapters_and_converters():
|
|||
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:
|
||||
|
|
|
@ -163,8 +163,8 @@ class TextFactoryTests(unittest.TestCase):
|
|||
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()
|
||||
|
|
|
@ -62,11 +62,12 @@ class SqliteTypeTests(unittest.TestCase):
|
|||
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 SqliteTypeTests(unittest.TestCase):
|
|||
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 @@ class DeclTypesTests(unittest.TestCase):
|
|||
|
||||
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 @@ class ColNamesTests(unittest.TestCase):
|
|||
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 @@ class ColNamesTests(unittest.TestCase):
|
|||
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")
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ class FunctionTests(unittest.TestCase):
|
|||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue