[py3k] unicode -> text_type, basestring -> string_types
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 23 Sep 2016 15:36:11 +0200
changeset 1594 70e13297f997
parent 1593 7896a09a5f08
child 1595 d975d2435d7d
[py3k] unicode -> text_type, basestring -> string_types
entities/html_generation.py
entities/profile_generation.py
test/test_entities.py
test/test_views.py
views/archiveunit.py
views/dataobject.py
views/mgmt_rules.py
views/widgets.py
xsd2uicfg.py
--- a/entities/html_generation.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/entities/html_generation.py	Fri Sep 23 15:36:11 2016 +0200
@@ -15,6 +15,8 @@
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-seda adapter classes for generation of a profile generation as HTML"""
 
+from six import string_types
+
 from cubicweb import _
 
 from cubes.seda.entities.profile_generation import SEDA2ExportAdapter, content_types
@@ -190,7 +192,7 @@
         self.element('span', div, text=occ.target.local_name, attributes={'class': 'label'})
         self.element('span', div, text=card, attributes={'class': 'card'})
         fixed_value = self.serialize(target_value)
-        if isinstance(fixed_value, basestring):
+        if isinstance(fixed_value, string_types):
             self.element('span', div, text=fixed_value, attributes={'class': 'value'})
         else:
             span = self.element('span', div, attributes={'class': 'value'})
@@ -243,7 +245,7 @@
         value_div = self.element('div', div)
         self.element('span', value_div, text=self._cw._('fixed value'),
                      attributes={'class': 'label'})
-        if isinstance(fixed_value, basestring):
+        if isinstance(fixed_value, string_types):
             self.element('span', value_div, text=fixed_value, attributes={'class': 'value'})
         else:
             span = self.element('span', value_div, attributes={'class': 'value'})
@@ -289,5 +291,5 @@
         else:
             if isinstance(value, bool):
                 value = 'true' if value else 'false'
-            assert isinstance(value, basestring), repr(value)
+            assert isinstance(value, string_types), repr(value)
             return value
--- a/entities/profile_generation.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/entities/profile_generation.py	Fri Sep 23 15:36:11 2016 +0200
@@ -17,6 +17,8 @@
 
 from collections import defaultdict
 
+from six import text_type, string_types
+
 from lxml import etree
 from pyxst.xml_struct import graph_nodes
 
@@ -84,8 +86,8 @@
         return None  # intermediary entity
     if isinstance(value, bool):
         return 'true' if value else 'false'
-    assert isinstance(value, basestring), repr(value)
-    return unicode(value)
+    assert isinstance(value, string_types), repr(value)
+    return text_type(value)
 
 
 def element_minmax_cardinality(occ, card_entity):
--- a/test/test_entities.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/test/test_entities.py	Fri Sep 23 15:36:11 2016 +0200
@@ -15,6 +15,8 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-saem_ref unit tests for entities.container"""
 
+from six import text_type
+
 from cubicweb.devtools.testlib import CubicWebTC
 
 from cubes.seda.entities import seda_profile_container_def, simplified_profile, full_seda2_profile
@@ -92,7 +94,7 @@
             self.assertEqual(simplified_profile_pred(None, req, entity=being_created), 0)
             self.assertEqual(full_seda2_profile_pred(None, req, entity=being_created), 1)
             del req.form['__linkto']
-            req.form['arg'] = [unicode(transfer.eid)]
+            req.form['arg'] = [text_type(transfer.eid)]
             self.assertEqual(simplified_profile_pred(None, req, entity=being_created), 0)
             self.assertEqual(full_seda2_profile_pred(None, req, entity=being_created), 1)
             transfer.cw_set(simplified_profile=True)
--- a/test/test_views.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/test/test_views.py	Fri Sep 23 15:36:11 2016 +0200
@@ -17,6 +17,8 @@
 
 import unittest
 
+from six import text_type
+
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.web import INTERNAL_FIELD_VALUE
 
@@ -55,9 +57,9 @@
             cnx.commit()
 
             self.assertEqual(_rule_ref_vocabulary(rule_base, transfer),
-                             [(access_concept.label(), unicode(access_concept.eid))])
+                             [(access_concept.label(), text_type(access_concept.eid))])
             self.assertEqual(_rule_ref_vocabulary(rule_alt, transfer),
-                             [(access_concept.label(), unicode(access_concept.eid))])
+                             [(access_concept.label(), text_type(access_concept.eid))])
 
 
 class PermissionsTC(CubicWebTC):
@@ -108,7 +110,7 @@
         with self.admin_access.web_request() as req:
             compressed = req.entity_from_eid(compressed.eid)
             req.form = {'relation': 'seda_algorithm:Concept:subject',
-                        'container': unicode(transfer.eid)}
+                        'container': text_type(transfer.eid)}
             view = self.vreg['views'].select('search_related_entities', req,
                                              rset=compressed.as_rset())
             self.failIf(view.linkable_rset())
@@ -122,7 +124,7 @@
         with self.admin_access.web_request() as req:
             compressed = req.entity_from_eid(compressed.eid)
             req.form = {'relation': 'seda_algorithm:Concept:subject',
-                        'container': unicode(transfer.eid)}
+                        'container': text_type(transfer.eid)}
             view = self.vreg['views'].select('search_related_entities', req,
                                              rset=compressed.as_rset())
             self.assertEqual(len(view.linkable_rset()), 1)
--- a/views/archiveunit.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/views/archiveunit.py	Fri Sep 23 15:36:11 2016 +0200
@@ -15,6 +15,8 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-seda views for ArchiveUnit"""
 
+from six import text_type
+
 from logilab.common.registry import objectify_predicate, yes
 
 from cubicweb import tags, _
@@ -413,7 +415,7 @@
     def display_add_button(self, entity):
         rtype_roles = [(rtype, role) for rtype, role, _ in self.rtype_role_targets]
         params = self.url_params(entity)
-        params['referenced_by'] = unicode(entity.eid)
+        params['referenced_by'] = text_type(entity.eid)
         transfer = entity.container[0]
         button = add_subobjects_button(transfer, rtype_roles, params)
         if button:
--- a/views/dataobject.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/views/dataobject.py	Fri Sep 23 15:36:11 2016 +0200
@@ -17,6 +17,8 @@
 
 import json
 
+from six import text_type
+
 from logilab.mtconverter import xml_escape
 
 from cubicweb import tags, view, _
@@ -76,7 +78,7 @@
         _, container = parent_and_container(entity)
         # and put it as an extra url param
         if container is not None:
-            url_params['container'] = unicode(container.eid)
+            url_params['container'] = text_type(container.eid)
         return super(ContainedRelationFacetWidget, self).trigger_search_url(entity, url_params)
 
 
--- a/views/mgmt_rules.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/views/mgmt_rules.py	Fri Sep 23 15:36:11 2016 +0200
@@ -15,6 +15,8 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-seda views for management rules"""
 
+from six import text_type
+
 from logilab.mtconverter import xml_escape
 
 from cubicweb.predicates import is_instance
@@ -50,7 +52,7 @@
            'CACLV seda_{0}_rule_code_list_version_to CS'.format(rule_type))
     rset = req.execute(rql, {'at': container.eid})
     if rset:
-        return [(concept.label(), unicode(concept.eid))
+        return [(concept.label(), text_type(concept.eid))
                 for concept in rset.entities()]
     else:
         scheme_relation = 'seda_{0}_rule_code_list_version_from_object'.format(rule_type)
--- a/views/widgets.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/views/widgets.py	Fri Sep 23 15:36:11 2016 +0200
@@ -15,6 +15,8 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-seda custom fields/widgets"""
 
+from six import text_type
+
 from logilab.common.decorators import monkeypatch
 
 from cubicweb import tags, utils
@@ -138,7 +140,7 @@
             eid = u''
         else:
             value = concept.label()
-            eid = unicode(concept.eid)
+            eid = text_type(concept.eid)
         # we need an hidden input to handle the value while the text input display the label
         inputs = [
             tags.input(name=field.input_name(form, 'Label'), id=slave_id + 'Label',
@@ -206,7 +208,7 @@
         else:
             hidden = ' hidden'
             icon = 'icon-list-add'
-        wdgs.append(tags.a(u'', onclick=unicode(js.seda.toggleFormMetaVisibility(divid)),
+        wdgs.append(tags.a(u'', onclick=text_type(js.seda.toggleFormMetaVisibility(divid)),
                            href='javascript:$.noop()', title=form._cw._('show/hide meta fields'),
                            # take care, related js relies on the icon class position
                            klass=icon + ' metaFieldSwitch'))
--- a/xsd2uicfg.py	Thu Sep 01 15:22:53 2016 +0200
+++ b/xsd2uicfg.py	Fri Sep 23 15:36:11 2016 +0200
@@ -19,6 +19,8 @@
 used bits).
 """
 
+from six import text_type
+
 from cubicweb import neg_role
 
 from xsd import XSDM_MAPPING
@@ -193,9 +195,9 @@
             yield mapping.etype, attributes
 
 
-class Code(unicode):
-    """Special unicode subclass whose repr() doesn't add quotes, for insertion of python code in a data
-    structure
+class Code(text_type):
+    """Special string subclass whose repr() doesn't add quotes, for insertion of python code in a
+    data structure
     """
     def __repr__(self):
         return str(self)