diff sat_frontends/quick_frontend/quick_blog.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 0b7ce5daee9b
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_blog.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/quick_frontend/quick_blog.py	Tue Aug 13 19:08:41 2019 +0200
@@ -30,12 +30,12 @@
 
 try:
     # FIXME: to be removed when an acceptable solution is here
-    unicode("")  # XXX: unicode doesn't exist in pyjamas
+    str("")  # XXX: unicode doesn't exist in pyjamas
 except (
     TypeError,
     AttributeError,
 ):  # Error raised is not the same depending on pyjsbuild options
-    unicode = str
+    str = str
 
 ENTRY_CLS = None
 COMMENTS_CLS = None
@@ -266,7 +266,7 @@
         for key in keys_to_keep:
             value = getattr(self.item, key)
             if value is not None:
-                mb_data[key] = unicode(value)
+                mb_data[key] = str(value)
 
         for prefix in ("content", "title"):
             for suffix in ("", "_rich", "_xhtml"):
@@ -287,7 +287,7 @@
             mb_data['groups'] = list(self.blog.targets)
 
         self.blog.host.bridge.mbSend(
-            unicode(self.service or ""),
+            str(self.service or ""),
             self.node or "",
             data_format.serialise(mb_data),
             profile=self.blog.profile,
@@ -300,14 +300,14 @@
         all children entries will be recursively removed too
         """
         # XXX: named delete and not remove to avoid conflict with pyjamas
-        log.debug(u"deleting entry {}".format("EDIT ENTRY" if self.new else self.item.id))
+        log.debug("deleting entry {}".format("EDIT ENTRY" if self.new else self.item.id))
         for child in self.entries:
             child.delete()
         try:
             self.manager.entries.remove(self)
         except ValueError:
             if self != self.manager.edit_entry:
-                log.error(u"Internal Error: entry not found in manager")
+                log.error("Internal Error: entry not found in manager")
             else:
                 self.manager.edit_entry = None
         if not self.new:
@@ -328,12 +328,12 @@
         # TODO: manage several comments nodes case.
         if self.item.comments:
             self.blog.host.bridge.psNodeDelete(
-                unicode(self.item.comments_service) or "",
+                str(self.item.comments_service) or "",
                 self.item.comments_node,
                 profile=self.blog.profile,
             )
         self.blog.host.bridge.mbRetract(
-            unicode(self.service or ""),
+            str(self.service or ""),
             self.node or "",
             self.item.id,
             profile=self.blog.profile,
@@ -358,10 +358,10 @@
             quick_widgets.QuickWidget.__init__(self, host, targets, C.PROF_KEY_NONE)
             self._targets_type = C.ALL
         else:
-            assert isinstance(targets[0], basestring)
+            assert isinstance(targets[0], str)
             quick_widgets.QuickWidget.__init__(self, host, targets[0], C.PROF_KEY_NONE)
             for target in targets[1:]:
-                assert isinstance(target, basestring)
+                assert isinstance(target, str)
                 self.addTarget(target)
             self._targets_type = C.GROUP
 
@@ -375,7 +375,7 @@
             raise ValueError("Unkown targets type")
 
     def __str__(self):
-        return u"Blog Widget [target: {}, profile: {}]".format(
+        return "Blog Widget [target: {}, profile: {}]".format(
             ", ".join(self.targets), self.profile
         )
 
@@ -436,7 +436,7 @@
             own_pep = self.host.whoami.bare
             self.host.bridge.mbGetFromManyWithComments(
                 C.JID,
-                (unicode(own_pep),),
+                (str(own_pep),),
                 10,
                 10,
                 {},
@@ -446,7 +446,7 @@
             )
         else:
             raise NotImplementedError(
-                u"{} target type is not managed".format(self._targets_type)
+                "{} target type is not managed".format(self._targets_type)
             )
 
     def isJidAccepted(self, jid_):