[PATCH logilab-database] [py3] Use six.text_type() instead of unicode() in DBAPIAdapter

Nicola Spanti nicola.spanti at logilab.fr
Tue Jun 11 17:00:19 CEST 2019


Applied, thanks.

Le 11/06/2019 à 16:53, Denis Laxalde a écrit :
> # HG changeset patch
> # User Denis Laxalde <denis.laxalde at logilab.fr>
> # Date 1560262462 -7200
> #      mar. juin 11 16:14:22 2019 +0200
> # Node ID c7f9db5924c2b5922b05b817c81f0398f3971bdf
> # Parent  180423b69159a770ad62ef85351e980043a1e6c6
> # Available At https://hg.logilab.org/review/logilab/database
> #              hg pull https://hg.logilab.org/review/logilab/database -r c7f9db5924c2
> [py3] Use six.text_type() instead of unicode() in DBAPIAdapter
> 
> diff --git a/logilab/database/__init__.py b/logilab/database/__init__.py
> --- a/logilab/database/__init__.py
> +++ b/logilab/database/__init__.py
> @@ -44,7 +44,7 @@ import logging
>  from datetime import datetime, time, date
>  from warnings import warn
>  
> -from six import binary_type
> +from six import binary_type, text_type
>  from six.moves import range
>  from logilab.common.modutils import load_module_from_name
>  from logilab.common.date import todate, todatetime, utcdatetime, utctime
> @@ -364,7 +364,7 @@ class DBAPIAdapter(object):
>          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: text_type(v, encoding, 'replace')
>          elif typecode == self.BOOLEAN:
>              transform = bool
>          elif typecode == self.BINARY and binarywrap is not None:
> @@ -372,7 +372,7 @@ class DBAPIAdapter(object):
>          elif typecode == self.UNKNOWN:
>              # may occurs on constant selection for instance (e.g. SELECT 'hop')
>              # with postgresql at least
> -            transform = lambda v: unicode(v, encoding, 'replace') if isinstance(v, str) else v
> +            transform = lambda v: text_type(v, encoding, 'replace') if isinstance(v, binary_type) else v
>          return transform
>  
>      def process_cursor(self, cursor, encoding, binarywrap=None):
> 



More information about the cubicweb-devel mailing list