[py3k] unicode → six.text_type
authorRémi Cardona <remi.cardona@logilab.fr>
Wed, 16 Sep 2015 11:28:07 +0200
changeset 10687 d394bfcd8c25
parent 10686 a08d5a657836
child 10688 fa29f3628a1b
[py3k] unicode → six.text_type
devtools/testlib.py
req.py
rset.py
sobjects/cwxmlparser.py
utils.py
--- a/devtools/testlib.py	Mon Oct 05 17:10:36 2015 +0200
+++ b/devtools/testlib.py	Wed Sep 16 11:28:07 2015 +0200
@@ -286,7 +286,7 @@
         """provide a new RepoAccess object for a given user
 
         The access is automatically closed at the end of the test."""
-        login = unicode(login)
+        login = text_type(login)
         access = RepoAccess(self.repo, login, self.requestcls)
         self._open_access.add(access)
         return access
@@ -313,7 +313,7 @@
         db_handler.restore_database(self.test_db_id)
         self.repo = db_handler.get_repo(startup=True)
         # get an admin session (without actual login)
-        login = unicode(db_handler.config.default_admin_config['login'])
+        login = text_type(db_handler.config.default_admin_config['login'])
         self.admin_access = self.new_access(login)
         self._admin_session = self.admin_access._session
 
@@ -456,14 +456,14 @@
         if password is None:
             password = login
         if login is not None:
-            login = unicode(login)
+            login = text_type(login)
         user = req.create_entity('CWUser', login=login,
                                  upassword=password, **kwargs)
         req.execute('SET X in_group G WHERE X eid %%(x)s, G name IN(%s)'
                     % ','.join(repr(str(g)) for g in groups),
                     {'x': user.eid})
         if email is not None:
-            req.create_entity('EmailAddress', address=unicode(email),
+            req.create_entity('EmailAddress', address=text_type(email),
                               reverse_primary_email=user)
         user.cw_clear_relation_cache('in_group', 'subject')
         if commit:
--- a/req.py	Mon Oct 05 17:10:36 2015 +0200
+++ b/req.py	Wed Sep 16 11:28:07 2015 +0200
@@ -22,7 +22,7 @@
 from warnings import warn
 from datetime import time, datetime, timedelta
 
-from six import text_type
+from six import PY2, text_type
 from six.moves.urllib.parse import parse_qs, parse_qsl, quote as urlquote, unquote as urlunquote, urlsplit, urlunsplit
 
 from logilab.common.decorators import cached
@@ -313,7 +313,7 @@
         necessary encoding / decoding. Also it's designed to quote each
         part of a url path and so the '/' character will be encoded as well.
         """
-        if isinstance(value, unicode):
+        if PY2 and isinstance(value, unicode):
             quoted = urlquote(value.encode(self.encoding), safe=safe)
             return unicode(quoted, self.encoding)
         return urlquote(str(value), safe=safe)
--- a/rset.py	Mon Oct 05 17:10:36 2015 +0200
+++ b/rset.py	Wed Sep 16 11:28:07 2015 +0200
@@ -21,6 +21,7 @@
 
 from warnings import warn
 
+from six import PY3
 from six.moves import range
 
 from logilab.common import nullobject
@@ -375,6 +376,8 @@
             warn('[3.21] the "encoded" argument is deprecated', DeprecationWarning)
         encoding = self.req.encoding
         rqlstr = self.syntax_tree().as_string(kwargs=self.args)
+        if PY3:
+            return rqlstr
         # sounds like we get encoded or unicode string due to a bug in as_string
         if not encoded:
             if isinstance(rqlstr, unicode):
--- a/sobjects/cwxmlparser.py	Mon Oct 05 17:10:36 2015 +0200
+++ b/sobjects/cwxmlparser.py	Wed Sep 16 11:28:07 2015 +0200
@@ -34,6 +34,7 @@
 from datetime import datetime, time
 import urllib
 
+from six import text_type
 from six.moves.urllib.parse import urlparse, urlunparse, parse_qs
 
 from logilab.common.date import todate, totime
@@ -51,7 +52,7 @@
 # XXX see cubicweb.cwvreg.YAMS_TO_PY
 # XXX see cubicweb.web.views.xmlrss.SERIALIZERS
 DEFAULT_CONVERTERS = BASE_CONVERTERS.copy()
-DEFAULT_CONVERTERS['String'] = unicode
+DEFAULT_CONVERTERS['String'] = text_type
 DEFAULT_CONVERTERS['Password'] = lambda x: x.encode('utf8')
 def convert_date(ustr):
     return todate(datetime.strptime(ustr, '%Y-%m-%d'))
@@ -315,7 +316,7 @@
         """
         node = self.node
         item = dict(node.attrib.items())
-        item['cwtype'] = unicode(node.tag)
+        item['cwtype'] = text_type(node.tag)
         item.setdefault('cwsource', None)
         try:
             item['eid'] = int(item['eid'])
@@ -332,7 +333,7 @@
                 related += self.parser.parse_etree(child)
             elif child.text:
                 # attribute
-                item[child.tag] = unicode(child.text)
+                item[child.tag] = text_type(child.text)
             else:
                 # None attribute (empty tag)
                 item[child.tag] = None
--- a/utils.py	Mon Oct 05 17:10:36 2015 +0200
+++ b/utils.py	Wed Sep 16 11:28:07 2015 +0200
@@ -35,6 +35,7 @@
 from threading import Lock
 from logging import getLogger
 
+from six import text_type
 from six.moves.urllib.parse import urlparse
 
 from logilab.mtconverter import xml_escape
@@ -229,7 +230,7 @@
         return True
 
     def write(self, value):
-        assert isinstance(value, unicode), u"unicode required not %s : %s"\
+        assert isinstance(value, text_type), u"unicode required not %s : %s"\
                                      % (type(value).__name__, repr(value))
         if self.tracewrites:
             from traceback import format_stack