Thanks! I ran into a segfault when running this, but it was easily
tracked down and fixed; see r56903.

On 8/10/07, gerhard.haering <[email protected]> wrote:
> Author: gerhard.haering
> Date: Fri Aug 10 20:15:11 2007
> New Revision: 56902
>
> Modified:
>    python/branches/py3k/Lib/sqlite3/test/factory.py
>    python/branches/py3k/Lib/sqlite3/test/types.py
>    python/branches/py3k/Lib/sqlite3/test/userfunctions.py
>    python/branches/py3k/Modules/_sqlite/connection.c
>    python/branches/py3k/Modules/_sqlite/cursor.c
>    python/branches/py3k/Modules/_sqlite/row.c
>    python/branches/py3k/Modules/_sqlite/statement.c
> Log:
> Make the sqlite tests pass.
>
>
> Modified: python/branches/py3k/Lib/sqlite3/test/factory.py
> ==============================================================================
> --- python/branches/py3k/Lib/sqlite3/test/factory.py    (original)
> +++ python/branches/py3k/Lib/sqlite3/test/factory.py    Fri Aug 10 20:15:11 
> 2007
> @@ -139,32 +139,32 @@
>          self.con = sqlite.connect(":memory:")
>
>      def CheckUnicode(self):
> -        austria = str("Österreich", "latin1")
> +        austria = "Österreich"
>          row = self.con.execute("select ?", (austria,)).fetchone()
>          self.failUnless(type(row[0]) == str, "type of row[0] must be 
> unicode")
>
>      def CheckString(self):
> -        self.con.text_factory = str
> -        austria = str("Österreich", "latin1")
> +        self.con.text_factory = bytes
> +        austria = "Österreich"
>          row = self.con.execute("select ?", (austria,)).fetchone()
> -        self.failUnless(type(row[0]) == str, "type of row[0] must be str")
> +        self.failUnless(type(row[0]) == bytes, "type of row[0] must be 
> bytes")
>          self.failUnless(row[0] == austria.encode("utf-8"), "column must 
> equal original data in UTF-8")
>
>      def CheckCustom(self):
>          self.con.text_factory = lambda x: str(x, "utf-8", "ignore")
> -        austria = str("Österreich", "latin1")
> -        row = self.con.execute("select ?", 
> (austria.encode("latin1"),)).fetchone()
> +        austria = "Österreich"
> +        row = self.con.execute("select ?", (austria,)).fetchone()
>          self.failUnless(type(row[0]) == str, "type of row[0] must be 
> unicode")
>          self.failUnless(row[0].endswith("reich"), "column must contain 
> original data")
>
>      def CheckOptimizedUnicode(self):
>          self.con.text_factory = sqlite.OptimizedUnicode
> -        austria = str("Österreich", "latin1")
> -        germany = str("Deutchland")
> +        austria = "Österreich"
> +        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]) == str, "type of ASCII-only row must 
> be str")
> +        self.failUnless(type(d_row[0]) == str8, "type of ASCII-only row must 
> be str8")
>
>      def tearDown(self):
>          self.con.close()
>
> Modified: python/branches/py3k/Lib/sqlite3/test/types.py
> ==============================================================================
> --- python/branches/py3k/Lib/sqlite3/test/types.py      (original)
> +++ python/branches/py3k/Lib/sqlite3/test/types.py      Fri Aug 10 20:15:11 
> 2007
> @@ -62,7 +62,7 @@
>          self.failUnlessEqual(row[0], val)
>
>      def CheckBlob(self):
> -        val = buffer("Guglhupf")
> +        val = buffer(b"Guglhupf")
>          self.cur.execute("insert into test(b) values (?)", (val,))
>          self.cur.execute("select b from test")
>          row = self.cur.fetchone()
> @@ -203,7 +203,7 @@
>
>      def CheckBlob(self):
>          # default
> -        val = buffer("Guglhupf")
> +        val = buffer(b"Guglhupf")
>          self.cur.execute("insert into test(bin) values (?)", (val,))
>          self.cur.execute("select bin from test")
>          row = self.cur.fetchone()
> @@ -304,7 +304,7 @@
>          self.con.close()
>
>      def CheckBinaryInputForConverter(self):
> -        testdata = "abcdefg" * 10
> +        testdata = b"abcdefg" * 10
>          result = self.con.execute('select ? as "x [bin]"', 
> (buffer(bz2.compress(testdata)),)).fetchone()[0]
>          self.failUnlessEqual(testdata, result)
>
>
> Modified: python/branches/py3k/Lib/sqlite3/test/userfunctions.py
> ==============================================================================
> --- python/branches/py3k/Lib/sqlite3/test/userfunctions.py      (original)
> +++ python/branches/py3k/Lib/sqlite3/test/userfunctions.py      Fri Aug 10 
> 20:15:11 2007
> @@ -36,7 +36,7 @@
>  def func_returnnull():
>      return None
>  def func_returnblob():
> -    return buffer("blob")
> +    return buffer(b"blob")
>  def func_raiseexception():
>      5/0
>
> @@ -197,7 +197,7 @@
>          cur.execute("select returnblob()")
>          val = cur.fetchone()[0]
>          self.failUnlessEqual(type(val), buffer)
> -        self.failUnlessEqual(val, buffer("blob"))
> +        self.failUnlessEqual(val, buffer(b"blob"))
>
>      def CheckFuncException(self):
>          cur = self.con.cursor()
>
> Modified: python/branches/py3k/Modules/_sqlite/connection.c
> ==============================================================================
> --- python/branches/py3k/Modules/_sqlite/connection.c   (original)
> +++ python/branches/py3k/Modules/_sqlite/connection.c   Fri Aug 10 20:15:11 
> 2007
> @@ -435,10 +435,8 @@
>      } else if (PyString_Check(py_val)) {
>          sqlite3_result_text(context, PyString_AsString(py_val), -1, 
> SQLITE_TRANSIENT);
>      } else if (PyUnicode_Check(py_val)) {
> -        stringval = PyUnicode_AsUTF8String(py_val);
>          if (stringval) {
> -            sqlite3_result_text(context, PyString_AsString(stringval), -1, 
> SQLITE_TRANSIENT);
> -            Py_DECREF(stringval);
> +            sqlite3_result_text(context, PyUnicode_AsString(stringval), -1, 
> SQLITE_TRANSIENT);
>          }
>      } else {
>          /* TODO: raise error */
> @@ -1094,7 +1092,7 @@
>          goto finally;
>      }
>
> -    if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", 
> &PyString_Type, &name, &callable)) {
> +    if (!PyArg_ParseTuple(args, "O!O:create_collation(name, callback)", 
> &PyUnicode_Type, &name, &callable)) {
>          goto finally;
>      }
>
>
> Modified: python/branches/py3k/Modules/_sqlite/cursor.c
> ==============================================================================
> --- python/branches/py3k/Modules/_sqlite/cursor.c       (original)
> +++ python/branches/py3k/Modules/_sqlite/cursor.c       Fri Aug 10 20:15:11 
> 2007
> @@ -248,7 +248,7 @@
>              if ((*pos == '[') && (pos > colname) && (*(pos-1) == ' ')) {
>                  pos--;
>              }
> -            return PyString_FromStringAndSize(colname, pos - colname);
> +            return PyUnicode_FromStringAndSize(colname, pos - colname);
>          }
>      }
>  }
> @@ -372,8 +372,10 @@
>                      }
>                  } else if (self->connection->text_factory == 
> (PyObject*)&PyString_Type) {
>                      converted = PyString_FromString(val_str);
> +                } else if (self->connection->text_factory == 
> (PyObject*)&PyBytes_Type) {
> +                    converted = PyBytes_FromStringAndSize(val_str, 
> strlen(val_str));
>                  } else {
> -                    converted = 
> PyObject_CallFunction(self->connection->text_factory, "s", val_str);
> +                    converted = 
> PyObject_CallFunction(self->connection->text_factory, "y", val_str);
>                  }
>              } else {
>                  /* coltype == SQLITE_BLOB */
> @@ -746,17 +748,13 @@
>          return NULL;
>      }
>
> -    if (PyString_Check(script_obj)) {
> -        script_cstr = PyString_AsString(script_obj);
> -    } else if (PyUnicode_Check(script_obj)) {
> -        script_str = PyUnicode_AsUTF8String(script_obj);
> -        if (!script_str) {
> +    if (PyUnicode_Check(script_obj)) {
> +        script_cstr = PyUnicode_AsString(script_obj);
> +        if (!script_cstr) {
>              return NULL;
>          }
> -
> -        script_cstr = PyString_AsString(script_str);
>      } else {
> -        PyErr_SetString(PyExc_ValueError, "script argument must be unicode 
> or string.");
> +        PyErr_SetString(PyExc_ValueError, "script argument must be 
> unicode.");
>          return NULL;
>      }
>
>
> Modified: python/branches/py3k/Modules/_sqlite/row.c
> ==============================================================================
> --- python/branches/py3k/Modules/_sqlite/row.c  (original)
> +++ python/branches/py3k/Modules/_sqlite/row.c  Fri Aug 10 20:15:11 2007
> @@ -86,8 +86,8 @@
>          item = PyTuple_GetItem(self->data, _idx);
>          Py_XINCREF(item);
>          return item;
> -    } else if (PyString_Check(idx)) {
> -        key = PyString_AsString(idx);
> +    } else if (PyUnicode_Check(idx)) {
> +        key = PyUnicode_AsString(idx);
>
>          nitems = PyTuple_Size(self->description);
>
>
> Modified: python/branches/py3k/Modules/_sqlite/statement.c
> ==============================================================================
> --- python/branches/py3k/Modules/_sqlite/statement.c    (original)
> +++ python/branches/py3k/Modules/_sqlite/statement.c    Fri Aug 10 20:15:11 
> 2007
> @@ -113,7 +113,8 @@
>          rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
>      } else if PyUnicode_Check(parameter) {
>          stringval = PyUnicode_AsUTF8String(parameter);
> -        string = PyString_AsString(stringval);
> +        string = PyBytes_AsString(stringval);
> +
>          rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
>          Py_DECREF(stringval);
>      } else {
>
> _______________________________________________
> Python-3000-checkins mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/python-3000-checkins
>
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to