[PATCH 04 of 10 logilab-database] [fix] missing python 3 port

Laurent Peuch cortex at worlddomination.be
Fri Apr 3 09:14:12 CEST 2020


# HG changeset patch
# User Laurent Peuch <cortex at worlddomination.be>
# Date 1585790179 -7200
#      Thu Apr 02 03:16:19 2020 +0200
# Node ID 19be3fc5f7481d111f1f162443d70df2c31282c7
# Parent  de107abc16067a18c08d1953a9e3c227fa6e90ac
# Available At https://hg.logilab.org/users/lpeuch/logilab-database
#              hg pull https://hg.logilab.org/users/lpeuch/logilab-database -r 19be3fc5f748
# EXP-Topic good-practice-modernisation
[fix] missing python 3 port

diff --git a/logilab/database/mysql.py b/logilab/database/mysql.py
--- a/logilab/database/mysql.py
+++ b/logilab/database/mysql.py
@@ -339,7 +339,7 @@ class _MyAdvFuncHelper(db._GenericAdvFun
         """Execute a full text query and return a list of 2-uple (rating, uid).
         """
         if isinstance(querystr, str):
-            querystr = unicode(querystr, self.dbencoding)
+            querystr = str(querystr, self.dbencoding)
         words = normalize_words(tokenize(querystr))
         cursor = cursor or self._cnx.cursor()
         cursor.execute(
diff --git a/logilab/database/sqlserver.py b/logilab/database/sqlserver.py
--- a/logilab/database/sqlserver.py
+++ b/logilab/database/sqlserver.py
@@ -204,7 +204,7 @@ class _BaseSqlServerAdapter(db.DBAPIAdap
         assert typecode is not None, self
         transform = None
         if typecode == self.STRING and not self.returns_unicode:
-            transform = lambda v: unicode(v, encoding, "replace")
+            transform = lambda v: str(v, encoding, "replace")
         elif typecode == self.BINARY:  # value is a python buffer
             if binarywrap is None:
                 transforn = lambda v: v[:]
@@ -247,7 +247,7 @@ class _PyodbcAdapter(_BaseSqlServerAdapt
         # Work around pyodbc setting BINARY to bytearray but description[1] to buffer
         # https://github.com/mkleehammer/pyodbc/pull/34
         typecode = description[1]
-        if typecode is buffer:
+        if typecode is memoryview:
             return binarywrap
         return super(_PyodbcAdapter, self)._transformation_callback(
             description, encoding, binarywrap
diff --git a/test/unittest_db.py b/test/unittest_db.py
--- a/test/unittest_db.py
+++ b/test/unittest_db.py
@@ -236,7 +236,7 @@ class BaseSqlServer(unittest.TestCase):
         cursor = self.cnx.cursor()
         data_length = range(400 * 1024 - 10, 400 * 1024 + 10)
         for length in data_length:
-            data = buffer("\x00" * length)
+            data = memoryview("\x00" * length)
             print("inserting string of length", len(data))
             cursor.execute(
                 "insert into TestBlob(id, data) VALUES(%(id)s, %(data)s)",



More information about the cubicweb-devel mailing list