[py3k] unicode → six.text_type
authorRémi Cardona <remi.cardona@logilab.fr>
Fri, 18 Sep 2015 18:03:19 +0200
changeset 10717 46f934bebd85
parent 10716 9a9d57edb1c1
child 10718 97d398e17f8c
[py3k] unicode → six.text_type
web/facet.py
web/formwidgets.py
web/request.py
web/views/boxes.py
web/views/debug.py
web/views/pyviews.py
--- a/web/facet.py	Fri Sep 18 18:02:20 2015 +0200
+++ b/web/facet.py	Fri Sep 18 18:03:19 2015 +0200
@@ -672,7 +672,7 @@
                 insert_attr_select_relation(
                     select, self.filtered_variable, self.rtype, self.role,
                     self.target_attr, select_target_entity=False)
-            values = [unicode(x) for x, in self.rqlexec(select.as_string())]
+            values = [text_type(x) for x, in self.rqlexec(select.as_string())]
         except Exception:
             self.exception('while computing values for %s', self)
             return []
@@ -1126,7 +1126,7 @@
             cleanup_select(select, self.filtered_variable)
             varmap, restrvar = self.add_path_to_select(skiplabel=True)
             select.append_selected(nodes.VariableRef(restrvar))
-            values = [unicode(x) for x, in self.rqlexec(select.as_string())]
+            values = [text_type(x) for x, in self.rqlexec(select.as_string())]
         except Exception:
             self.exception('while computing values for %s', self)
             return []
@@ -1253,7 +1253,7 @@
         rset = self._range_rset()
         if rset:
             minv, maxv = rset[0]
-            return [(unicode(minv), minv), (unicode(maxv), maxv)]
+            return [(text_type(minv), minv), (text_type(maxv), maxv)]
         return []
 
     def possible_values(self):
@@ -1272,7 +1272,7 @@
 
     def formatvalue(self, value):
         """format `value` before in order to insert it in the RQL query"""
-        return unicode(value)
+        return text_type(value)
 
     def infvalue(self, min=False):
         if min:
@@ -1373,7 +1373,7 @@
         # *list* (see rqlexec implementation)
         if rset:
             minv, maxv = rset[0]
-            return [(unicode(minv), minv), (unicode(maxv), maxv)]
+            return [(text_type(minv), minv), (text_type(maxv), maxv)]
         return []
 
 
@@ -1516,7 +1516,7 @@
                        if not val or val & mask])
 
     def possible_values(self):
-        return [unicode(val) for label, val in self.vocabulary()]
+        return [text_type(val) for label, val in self.vocabulary()]
 
 
 ## html widets ################################################################
@@ -1595,7 +1595,7 @@
         if selected:
             cssclass += ' facetValueSelected'
         w(u'<div class="%s" cubicweb:value="%s">\n'
-          % (cssclass, xml_escape(unicode(value))))
+          % (cssclass, xml_escape(text_type(value))))
         # If it is overflowed one must add padding to compensate for the vertical
         # scrollbar; given current css values, 4 blanks work perfectly ...
         padding = u'&#160;' * self.scrollbar_padding_factor if overflow else u''
@@ -1754,7 +1754,7 @@
             imgsrc = self._cw.data_url(self.unselected_img)
             imgalt = self._cw._('not selected')
         w(u'<div class="%s" cubicweb:value="%s">\n'
-          % (cssclass, xml_escape(unicode(self.value))))
+          % (cssclass, xml_escape(text_type(self.value))))
         w(u'<div>')
         w(u'<img src="%s" alt="%s" cubicweb:unselimg="true" />&#160;' % (imgsrc, imgalt))
         w(u'<label class="facetTitle" cubicweb:facetName="%s">%s</label>'
--- a/web/formwidgets.py	Fri Sep 18 18:02:20 2015 +0200
+++ b/web/formwidgets.py	Fri Sep 18 18:03:19 2015 +0200
@@ -99,7 +99,7 @@
 from datetime import date
 from warnings import warn
 
-from six import string_types
+from six import text_type, string_types
 
 from logilab.mtconverter import xml_escape
 from logilab.common.deprecation import deprecated
@@ -476,7 +476,7 @@
             options.append(u'</optgroup>')
         if not 'size' in attrs:
             if self._multiple:
-                size = unicode(min(self.default_size, len(vocab) or 1))
+                size = text_type(min(self.default_size, len(vocab) or 1))
             else:
                 size = u'1'
             attrs['size'] = size
@@ -708,7 +708,7 @@
         else:
             value = self.value
         attrs = self.attributes(form, field)
-        attrs.setdefault('size', unicode(self.default_size))
+        attrs.setdefault('size', text_type(self.default_size))
         return tags.input(name=field.input_name(form, self.suffix),
                           value=value, type='text', **attrs)
 
@@ -781,13 +781,13 @@
         try:
             date = todatetime(req.parse_datetime(datestr, 'Date'))
         except ValueError as exc:
-            raise ProcessFormError(unicode(exc))
+            raise ProcessFormError(text_type(exc))
         if timestr is None:
             return date
         try:
             time = req.parse_datetime(timestr, 'Time')
         except ValueError as exc:
-            raise ProcessFormError(unicode(exc))
+            raise ProcessFormError(text_type(exc))
         return date.replace(hour=time.hour, minute=time.minute, second=time.second)
 
 
--- a/web/request.py	Fri Sep 18 18:02:20 2015 +0200
+++ b/web/request.py	Fri Sep 18 18:03:19 2015 +0200
@@ -319,7 +319,7 @@
                 return None
 
     def set_message(self, msg):
-        assert isinstance(msg, unicode)
+        assert isinstance(msg, text_type)
         self.reset_message()
         self._msg = msg
 
@@ -332,7 +332,7 @@
 
     def set_redirect_message(self, msg):
         # TODO - this should probably be merged with append_to_redirect_message
-        assert isinstance(msg, unicode)
+        assert isinstance(msg, text_type)
         msgid = self.redirect_message_id()
         self.session.data[msgid] = msg
         return msgid
--- a/web/views/boxes.py	Fri Sep 18 18:02:20 2015 +0200
+++ b/web/views/boxes.py	Fri Sep 18 18:03:19 2015 +0200
@@ -30,7 +30,7 @@
 
 from warnings import warn
 
-from six import add_metaclass
+from six import text_type, add_metaclass
 
 from logilab.mtconverter import xml_escape
 from logilab.common.deprecation import class_deprecated
@@ -218,7 +218,7 @@
 
     @property
     def domid(self):
-        return super(RsetBox, self).domid + unicode(abs(id(self))) + unicode(abs(id(self.cw_rset)))
+        return super(RsetBox, self).domid + text_type(abs(id(self))) + text_type(abs(id(self.cw_rset)))
 
     def render_title(self, w):
         w(self.cw_extra_kwargs['title'])
--- a/web/views/debug.py	Fri Sep 18 18:02:20 2015 +0200
+++ b/web/views/debug.py	Fri Sep 18 18:03:19 2015 +0200
@@ -22,6 +22,8 @@
 
 from time import strftime, localtime
 
+from six import text_type
+
 from logilab.mtconverter import xml_escape
 
 from cubicweb.predicates import none_rset, match_user_groups
@@ -106,7 +108,7 @@
                 stats[k] = '%s / %s' % (stats[k]['size'], stats[k]['maxsize'])
         for element in sorted(stats):
             w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>'
-                   % (element, xml_escape(unicode(stats[element])),
+                   % (element, xml_escape(text_type(stats[element])),
                       element.endswith('percent') and '%' or '' ))
         w(u'</table>')
         if req.cnx.is_repo_in_memory and req.user.is_in_group('managers'):
@@ -116,7 +118,7 @@
                 w(u'<ul>')
                 for session in sessions:
                     w(u'<li>%s (%s: %s)<br/>' % (
-                        xml_escape(unicode(session)),
+                        xml_escape(text_type(session)),
                         _('last usage'),
                         strftime(dtformat, localtime(session.timestamp))))
                     dict_to_html(w, session.data)
--- a/web/views/pyviews.py	Fri Sep 18 18:02:20 2015 +0200
+++ b/web/views/pyviews.py	Fri Sep 18 18:03:19 2015 +0200
@@ -19,6 +19,7 @@
 """
 __docformat__ = "restructuredtext en"
 
+from six import text_type
 from six.moves import range
 
 from cubicweb.view import View
@@ -40,7 +41,7 @@
             w(self.empty_cell_content)
 
     def render_cell(self, w, rownum):
-        w(unicode(self.data[rownum][self.colid]))
+        w(text_type(self.data[rownum][self.colid]))
 
 
 class PyValTableView(tableview.TableMixIn, View):