[py3k] unicode → six.text_type
authorRémi Cardona <remi.cardona@logilab.fr>
Thu, 17 Sep 2015 11:07:36 +0200
changeset 10702 f94c812c3669
parent 10701 ca3efd72e854
child 10703 3cb87b61b067
[py3k] unicode → six.text_type
devtools/fill.py
mail.py
sobjects/notification.py
uilib.py
web/component.py
web/views/ibreadcrumbs.py
--- a/devtools/fill.py	Fri Sep 18 14:50:44 2015 +0200
+++ b/devtools/fill.py	Thu Sep 17 11:07:36 2015 +0200
@@ -27,7 +27,7 @@
 from datetime import datetime, date, time, timedelta
 from decimal import Decimal
 
-from six import add_metaclass
+from six import text_type, add_metaclass
 from six.moves import range
 
 from logilab.common import attrdict
@@ -228,7 +228,7 @@
         """
         for cst in self.eschema.rdef(attrname).constraints:
             if isinstance(cst, StaticVocabularyConstraint):
-                return unicode(choice(cst.vocabulary()))
+                return text_type(choice(cst.vocabulary()))
         return None
 
     # XXX nothing to do here
@@ -353,7 +353,7 @@
                 fmt = vreg.property_value('ui.float-format')
                 value = fmt % value
             else:
-                value = unicode(value)
+                value = text_type(value)
     return entity
 
 
--- a/mail.py	Fri Sep 18 14:50:44 2015 +0200
+++ b/mail.py	Thu Sep 17 11:07:36 2015 +0200
@@ -86,7 +86,7 @@
     to_addrs and cc_addrs are expected to be a list of email address without
     name
     """
-    assert type(content) is unicode, repr(content)
+    assert isinstance(content, text_type), repr(content)
     msg = MIMEText(content.encode('UTF-8'), 'plain', 'UTF-8')
     # safety: keep only the first newline
     try:
@@ -97,13 +97,13 @@
     if uinfo.get('email'):
         email = uinfo['email']
     elif config and config['sender-addr']:
-        email = unicode(config['sender-addr'])
+        email = text_type(config['sender-addr'])
     else:
         email = u''
     if uinfo.get('name'):
         name = uinfo['name']
     elif config and config['sender-name']:
-        name = unicode(config['sender-name'])
+        name = text_type(config['sender-name'])
     else:
         name = u''
     msg['From'] = addrheader(email, name)
--- a/sobjects/notification.py	Fri Sep 18 14:50:44 2015 +0200
+++ b/sobjects/notification.py	Thu Sep 17 11:07:36 2015 +0200
@@ -22,6 +22,8 @@
 
 from itertools import repeat
 
+from six import text_type
+
 from logilab.common.textutils import normalize_text
 from logilab.common.deprecation import class_renamed, class_moved, deprecated
 from logilab.common.registry import yes
@@ -182,7 +184,7 @@
     def context(self, **kwargs):
         entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0)
         for key, val in kwargs.items():
-            if val and isinstance(val, unicode) and val.strip():
+            if val and isinstance(val, text_type) and val.strip():
                kwargs[key] = self._cw._(val)
         kwargs.update({'user': self.user_data['login'],
                        'eid': entity.eid,
@@ -255,7 +257,7 @@
 
 
 def format_value(value):
-    if isinstance(value, unicode):
+    if isinstance(value, text_type):
         return u'"%s"' % value
     return value
 
--- a/uilib.py	Fri Sep 18 14:50:44 2015 +0200
+++ b/uilib.py	Thu Sep 17 11:07:36 2015 +0200
@@ -339,9 +339,9 @@
     def __unicode__(self):
         if self.parent:
             return u'%s.%s' % (self.parent, self.id)
-        return unicode(self.id)
+        return text_type(self.id)
     def __str__(self):
-        return unicode(self).encode('utf8')
+        return text_type(self).encode('utf8')
     def __getattr__(self, attr):
         return _JSId(attr, self)
     def __call__(self, *args):
--- a/web/component.py	Fri Sep 18 14:50:44 2015 +0200
+++ b/web/component.py	Thu Sep 17 11:07:36 2015 +0200
@@ -427,7 +427,7 @@
 
     @property
     def domid(self):
-        return domid(self.__regid__) + unicode(self.entity.eid)
+        return domid(self.__regid__) + text_type(self.entity.eid)
 
     def lazy_view_holder(self, w, entity, oid, registry='views'):
         """add a holder and return a URL that may be used to replace this
@@ -500,7 +500,7 @@
                                                     args['subject'],
                                                     args['object'])
         return u'[<a href="javascript: %s" class="action">%s</a>] %s' % (
-            xml_escape(unicode(jscall)), label, etarget.view('incontext'))
+            xml_escape(text_type(jscall)), label, etarget.view('incontext'))
 
     def related_boxitems(self, entity):
         return [self.box_item(entity, etarget, 'delete_relation', u'-')
@@ -517,7 +517,7 @@
         """returns the list of unrelated entities, using the entity's
         appropriate vocabulary function
         """
-        skip = set(unicode(e.eid) for e in entity.related(self.rtype, role(self),
+        skip = set(text_type(e.eid) for e in entity.related(self.rtype, role(self),
                                                           entities=True))
         skip.add(None)
         skip.add(INTERNAL_FIELD_VALUE)
@@ -635,7 +635,7 @@
                 if maydel:
                     if not js_css_added:
                         js_css_added = self.add_js_css()
-                    jscall = unicode(js.ajaxBoxRemoveLinkedEntity(
+                    jscall = text_type(js.ajaxBoxRemoveLinkedEntity(
                         self.__regid__, entity.eid, rentity.eid,
                         self.fname_remove,
                         self.removed_msg and _(self.removed_msg)))
@@ -650,7 +650,7 @@
         if mayadd:
             multiple = self.rdef.role_cardinality(self.role) in '*+'
             w(u'<table><tr><td>')
-            jscall = unicode(js.ajaxBoxShowSelector(
+            jscall = text_type(js.ajaxBoxShowSelector(
                 self.__regid__, entity.eid, self.fname_vocabulary,
                 self.fname_validate, self.added_msg and _(self.added_msg),
                 _(stdmsgs.BUTTON_OK[0]), _(stdmsgs.BUTTON_CANCEL[0]),
--- a/web/views/ibreadcrumbs.py	Fri Sep 18 14:50:44 2015 +0200
+++ b/web/views/ibreadcrumbs.py	Thu Sep 17 11:07:36 2015 +0200
@@ -22,6 +22,8 @@
 
 from warnings import warn
 
+from six import text_type
+
 from logilab.mtconverter import xml_escape
 
 from cubicweb import tags, uilib
@@ -141,7 +143,7 @@
                 xml_escape(url), xml_escape(uilib.cut(title, textsize))))
         else:
             textsize = self._cw.property_value('navigation.short-line-size')
-            w(xml_escape(uilib.cut(unicode(part), textsize)))
+            w(xml_escape(uilib.cut(text_type(part), textsize)))
 
 
 class BreadCrumbETypeVComponent(BreadCrumbEntityVComponent):