[Python-3000-checkins] r58865 - in python/branches/py3k-pep3137: Lib/sqlite3/dbapi2.py Lib/sqlite3/test/factory.py Lib/sqlite3/test/types.py Lib/sqlite3/test/userfunctions.py Modules/_sqlite/cache.c Modules/_sqlite/connection.c Modules/_sqlite/cursor.c Modules/_sqlite/row.c Modules/_sqlite/statement.c
guido.van.rossum
python-3000-checkins at python.org
Mon Nov 5 22:19:14 CET 2007
Author: guido.van.rossum
Date: Mon Nov 5 22:19:13 2007
New Revision: 58865
Modified:
python/branches/py3k-pep3137/Lib/sqlite3/dbapi2.py
python/branches/py3k-pep3137/Lib/sqlite3/test/factory.py
python/branches/py3k-pep3137/Lib/sqlite3/test/types.py
python/branches/py3k-pep3137/Lib/sqlite3/test/userfunctions.py
python/branches/py3k-pep3137/Modules/_sqlite/cache.c
python/branches/py3k-pep3137/Modules/_sqlite/connection.c
python/branches/py3k-pep3137/Modules/_sqlite/cursor.c
python/branches/py3k-pep3137/Modules/_sqlite/row.c
python/branches/py3k-pep3137/Modules/_sqlite/statement.c
Log:
Make the sqlite tests pass again.
Converters are now always invoked with bytes arguments.
Modified: python/branches/py3k-pep3137/Lib/sqlite3/dbapi2.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/sqlite3/dbapi2.py (original)
+++ python/branches/py3k-pep3137/Lib/sqlite3/dbapi2.py Mon Nov 5 22:19:13 2007
@@ -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:
Modified: python/branches/py3k-pep3137/Lib/sqlite3/test/factory.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/sqlite3/test/factory.py (original)
+++ python/branches/py3k-pep3137/Lib/sqlite3/test/factory.py Mon Nov 5 22:19:13 2007
@@ -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()
Modified: python/branches/py3k-pep3137/Lib/sqlite3/test/types.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/sqlite3/test/types.py (original)
+++ python/branches/py3k-pep3137/Lib/sqlite3/test/types.py Mon Nov 5 22:19:13 2007
@@ -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")
Modified: python/branches/py3k-pep3137/Lib/sqlite3/test/userfunctions.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/sqlite3/test/userfunctions.py (original)
+++ python/branches/py3k-pep3137/Lib/sqlite3/test/userfunctions.py Mon Nov 5 22:19:13 2007
@@ -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()
Modified: python/branches/py3k-pep3137/Modules/_sqlite/cache.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/_sqlite/cache.c (original)
+++ python/branches/py3k-pep3137/Modules/_sqlite/cache.c Mon Nov 5 22:19:13 2007
@@ -241,7 +241,7 @@
if (!fmt_args) {
return NULL;
}
- template = PyString_FromString("%s <- %s ->%s\n");
+ template = PyUnicode_FromString("%s <- %s ->%s\n");
if (!template) {
Py_DECREF(fmt_args);
return NULL;
Modified: python/branches/py3k-pep3137/Modules/_sqlite/connection.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/_sqlite/connection.c (original)
+++ python/branches/py3k-pep3137/Modules/_sqlite/connection.c Mon Nov 5 22:19:13 2007
@@ -425,8 +425,6 @@
sqlite3_result_int64(context, (PY_LONG_LONG)longval);
} else if (PyFloat_Check(py_val)) {
sqlite3_result_double(context, PyFloat_AsDouble(py_val));
- } else if (PyString_Check(py_val)) {
- sqlite3_result_text(context, PyString_AsString(py_val), -1, SQLITE_TRANSIENT);
} else if (PyUnicode_Check(py_val)) {
sqlite3_result_text(context, PyUnicode_AsString(py_val), -1, SQLITE_TRANSIENT);
} else if (PyObject_CheckBuffer(py_val)) {
@@ -467,7 +465,7 @@
break;
case SQLITE_TEXT:
val_str = (const char*)sqlite3_value_text(cur_value);
- cur_py_value = PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL);
+ cur_py_value = PyUnicode_FromString(val_str);
/* TODO: have a way to show errors here */
if (!cur_py_value) {
PyErr_Clear();
@@ -477,7 +475,7 @@
break;
case SQLITE_BLOB:
buflen = sqlite3_value_bytes(cur_value);
- cur_py_value = PyBytes_FromStringAndSize(
+ cur_py_value = PyString_FromStringAndSize(
sqlite3_value_blob(cur_value), buflen);
break;
case SQLITE_NULL:
@@ -1023,8 +1021,8 @@
goto finally;
}
- string1 = PyString_FromStringAndSize((const char*)text1_data, text1_length);
- string2 = PyString_FromStringAndSize((const char*)text2_data, text2_length);
+ string1 = PyUnicode_FromStringAndSize((const char*)text1_data, text1_length);
+ string2 = PyUnicode_FromStringAndSize((const char*)text2_data, text2_length);
if (!string1 || !string2) {
goto finally; /* failed to allocate strings */
@@ -1093,7 +1091,7 @@
goto finally;
}
- chk = PyString_AsString(uppercase_name);
+ chk = PyUnicode_AsString(uppercase_name);
while (*chk) {
if ((*chk >= '0' && *chk <= '9')
|| (*chk >= 'A' && *chk <= 'Z')
@@ -1118,7 +1116,7 @@
}
rc = sqlite3_create_collation(self->db,
- PyString_AsString(uppercase_name),
+ PyUnicode_AsString(uppercase_name),
SQLITE_UTF8,
(callable != Py_None) ? callable : NULL,
(callable != Py_None) ? pysqlite_collation_callback : NULL);
Modified: python/branches/py3k-pep3137/Modules/_sqlite/cursor.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/_sqlite/cursor.c (original)
+++ python/branches/py3k-pep3137/Modules/_sqlite/cursor.c Mon Nov 5 22:19:13 2007
@@ -272,11 +272,7 @@
}
}
- if (is_ascii) {
- return PyString_FromString(val_str);
- } else {
- return PyUnicode_DecodeUTF8(val_str, strlen(val_str), NULL);
- }
+ return PyUnicode_FromString(val_str);
}
/*
@@ -379,7 +375,7 @@
} else {
/* coltype == SQLITE_BLOB */
nbytes = sqlite3_column_bytes(self->statement->st, i);
- buffer = PyBytes_FromStringAndSize(
+ buffer = PyString_FromStringAndSize(
sqlite3_column_blob(self->statement->st, i), nbytes);
if (!buffer) {
break;
@@ -436,8 +432,8 @@
return NULL;
}
- if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
- PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
+ if (!PyUnicode_Check(operation)) {
+ PyErr_SetString(PyExc_ValueError, "operation parameter must be str");
return NULL;
}
@@ -458,8 +454,8 @@
return NULL;
}
- if (!PyString_Check(operation) && !PyUnicode_Check(operation)) {
- PyErr_SetString(PyExc_ValueError, "operation parameter must be str or unicode");
+ if (!PyUnicode_Check(operation)) {
+ PyErr_SetString(PyExc_ValueError, "operation parameter must be str");
return NULL;
}
Modified: python/branches/py3k-pep3137/Modules/_sqlite/row.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/_sqlite/row.c (original)
+++ python/branches/py3k-pep3137/Modules/_sqlite/row.c Mon Nov 5 22:19:13 2007
@@ -87,7 +87,7 @@
nitems = PyTuple_Size(self->description);
for (i = 0; i < nitems; i++) {
- compare_key = PyString_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
+ compare_key = PyUnicode_AsString(PyTuple_GET_ITEM(PyTuple_GET_ITEM(self->description, i), 0));
if (!compare_key) {
return NULL;
}
Modified: python/branches/py3k-pep3137/Modules/_sqlite/statement.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/_sqlite/statement.c (original)
+++ python/branches/py3k-pep3137/Modules/_sqlite/statement.c Mon Nov 5 22:19:13 2007
@@ -105,11 +105,8 @@
#endif
} else if (PyFloat_Check(parameter)) {
rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
- } else if PyString_Check(parameter) {
- string = PyString_AsString(parameter);
- rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
} else if PyUnicode_Check(parameter) {
- string = PyUnicode_AsUTF8String(parameter);
+ string = PyUnicode_AsString(parameter);
rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
} else if (PyObject_CheckBuffer(parameter)) {
More information about the Python-3000-checkins
mailing list