[python3] replace 'unicode' by 'str'
authorLaurent Peuch <cortex@worlddomination.be>
Thu, 19 Dec 2019 08:13:22 +0100
changeset 12825 71a842bdf81d
parent 12824 bc623a3e44e9
child 12826 c13c0188f8a3
[python3] replace 'unicode' by 'str'
cubicweb/ext/tal.py
cubicweb/misc/migration/3.23.0_Any.py
cubicweb/server/serverctl.py
cubicweb/web/htmlwidgets.py
cubicweb/web/views/calendar.py
cubicweb/web/views/sparql.py
--- a/cubicweb/ext/tal.py	Tue Dec 17 21:21:55 2019 +0100
+++ b/cubicweb/ext/tal.py	Thu Dec 19 08:13:22 2019 +0100
@@ -207,7 +207,7 @@
     :param template: path of the file to compile
     """
     fp = open(filepath)
-    file_content = unicode(fp.read()) # template file should be pure ASCII
+    file_content = str(fp.read()) # template file should be pure ASCII
     fp.close()
     return compile_template(file_content)
 
--- a/cubicweb/misc/migration/3.23.0_Any.py	Tue Dec 17 21:21:55 2019 +0100
+++ b/cubicweb/misc/migration/3.23.0_Any.py	Thu Dec 19 08:13:22 2019 +0100
@@ -61,7 +61,7 @@
     rdef = cwrdef.yams_schema()
     cstr = rdef.constraint_by_eid(cwconstraint.eid)
     with cnx.deny_all_hooks_but():
-        cwconstraint.cw_set(value=unicode(cstr.serialize()))
+        cwconstraint.cw_set(value=str(cstr.serialize()))
     if cstr.type() not in ('BoundaryConstraint', 'IntervalBoundConstraint',
                            'StaticVocabularyConstraint'):
         # These cannot be translate into backend CHECK.
--- a/cubicweb/server/serverctl.py	Tue Dec 17 21:21:55 2019 +0100
+++ b/cubicweb/server/serverctl.py	Thu Dec 19 08:13:22 2019 +0100
@@ -529,18 +529,18 @@
                     if not sourceuri:
                         print('-> mandatory.')
                     else:
-                        sourceuri = unicode(sourceuri, sys.stdin.encoding)
+                        sourceuri = str(sourceuri, sys.stdin.encoding)
                         if sourceuri in used:
                             print('-> uri already used, choose another one.')
                         else:
                             break
                 url = input('source URL (leave empty for none): ').strip()
-                url = unicode(url) if url else None
+                url = str(url) if url else None
                 # XXX configurable inputlevel
                 sconfig = ask_source_config(config, type, inputlevel=self.config.config_level)
-                cfgstr = unicode(generate_source_config(sconfig), sys.stdin.encoding)
-                cnx.create_entity('CWSource', name=sourceuri, type=unicode(type),
-                                  config=cfgstr, parser=unicode(parser), url=unicode(url))
+                cfgstr = str(generate_source_config(sconfig), sys.stdin.encoding)
+                cnx.create_entity('CWSource', name=sourceuri, type=str(type),
+                                  config=cfgstr, parser=str(parser), url=str(url))
                 cnx.commit()
         finally:
             repo.hm.call_hooks('server_shutdown')
--- a/cubicweb/web/htmlwidgets.py	Tue Dec 17 21:21:55 2019 +0100
+++ b/cubicweb/web/htmlwidgets.py	Thu Dec 19 08:13:22 2019 +0100
@@ -302,10 +302,9 @@
         value =  self._rows[rowindex][colindex]
         if value is None:
             return u''
-        elif isinstance(value, int):
+        if isinstance(value, int):
             return u'%09d' % value
-        else:
-            return unicode(value)
+        return str(value)
 
 
 class TableWidget(HTMLWidget):
--- a/cubicweb/web/views/calendar.py	Tue Dec 17 21:21:55 2019 +0100
+++ b/cubicweb/web/views/calendar.py	Thu Dec 19 08:13:22 2019 +0100
@@ -101,8 +101,8 @@
                     elt.add(stop_kw).value = ical_task.stop
 
             buff = ical.serialize()
-            if not isinstance(buff, unicode):
-                buff = unicode(buff, self._cw.encoding)
+            if not isinstance(buff, str):
+                buff = str(buff, self._cw.encoding)
             self.w(buff)
 
 except ImportError:
--- a/cubicweb/web/views/sparql.py	Tue Dec 17 21:21:55 2019 +0100
+++ b/cubicweb/web/views/sparql.py	Thu Dec 19 08:13:22 2019 +0100
@@ -119,7 +119,7 @@
         sparql = E.sparql(E.head(*(E.variable(name=name) for name in varnames)),
                           results)
         self.w(u'<?xml version="1.0"?>\n')
-        self.w(etree.tostring(sparql, encoding=unicode, pretty_print=True))
+        self.w(etree.tostring(sparql, encoding=str, pretty_print=True))
 
     def cell_binding(self, row, col, varname):
         celltype = self.cw_rset.description[row][col]