diff sat_frontends/quick_frontend/quick_widgets.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 e3803ae89fbc
children 07aac71ea31f
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_widgets.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/quick_frontend/quick_widgets.py	Tue Aug 13 19:08:41 2019 +0200
@@ -29,12 +29,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
 
 
 def register(base_cls, child_cls=None):
@@ -63,8 +63,8 @@
 
     def __iter__(self):
         """Iterate throught all widgets"""
-        for widget_map in self._widgets.itervalues():
-            for widget_instances in widget_map.itervalues():
+        for widget_map in self._widgets.values():
+            for widget_instances in widget_map.values():
                 for widget in widget_instances:
                     yield widget
 
@@ -114,14 +114,14 @@
             return
         else:
             if target is not None:
-                filter_hash = unicode(class_.getWidgetHash(target, profiles))
+                filter_hash = str(class_.getWidgetHash(target, profiles))
             else:
                 filter_hash = None
             if filter_hash is not None:
                 for widget in widgets_map.get(filter_hash, []):
                     yield widget
             else:
-                for widget_instances in widgets_map.itervalues():
+                for widget_instances in widgets_map.values():
                     for widget in widget_instances:
                         yield widget
 
@@ -136,7 +136,7 @@
         @return: a class_ instance or None if the widget doesn't exist
         """
         assert (target is not None) or (profiles is not None)
-        if profiles is not None and isinstance(profiles, unicode):
+        if profiles is not None and isinstance(profiles, str):
             profiles = [profiles]
         class_ = self.getRealClass(class_)
         hash_ = class_.getWidgetHash(target, profiles)
@@ -223,7 +223,7 @@
 
         if widget is None:
             # we need to create a new widget
-            log.debug(u"Creating new widget for target {} {}".format(target, cls))
+            log.debug("Creating new widget for target {} {}".format(target, cls))
             widget = cls(*_args, **_kwargs)
             widgets_map[hash_] = [widget]
 
@@ -248,13 +248,13 @@
                     recreateArgs(_args, _kwargs)
                 widget = cls(*_args, **_kwargs)
                 widgets_map[hash_].append(widget)
-                log.debug(u"widget <{wid}> already exists, a new one has been recreated"
+                log.debug("widget <{wid}> already exists, a new one has been recreated"
                     .format(wid=widget))
             elif callable(on_existing_widget):
                 widget = on_existing_widget(widget)
                 if widget is None:
                     raise exceptions.InternalError(
-                        u"on_existing_widget method must return the widget to use")
+                        "on_existing_widget method must return the widget to use")
             else:
                 raise exceptions.InternalError(
                     "Unexpected on_existing_widget value ({})".format(on_existing_widget))
@@ -295,9 +295,9 @@
         try:
             widgets_map = self._widgets[class_.__name__]
         except KeyError:
-            log.error(u"no widgets_map found for class {cls}".format(cls=class_))
+            log.error("no widgets_map found for class {cls}".format(cls=class_))
             return
-        widget_hash = unicode(class_.getWidgetHash(widget_to_delete.target,
+        widget_hash = str(class_.getWidgetHash(widget_to_delete.target,
                                                    widget_to_delete.profiles))
         widget_instances = widgets_map[widget_hash]
         if all_instances:
@@ -306,16 +306,16 @@
             try:
                 widget_instances.remove(widget_to_delete)
             except ValueError:
-                log.error(u"widget_to_delete not found in widget instances")
+                log.error("widget_to_delete not found in widget instances")
                 return
 
-            log.debug(u"widget {} deleted".format(widget_to_delete))
+            log.debug("widget {} deleted".format(widget_to_delete))
 
         if not widget_instances:
             # all instances with this hash have been deleted
             # we remove the hash itself
             del widgets_map[widget_hash]
-            log.debug(u"All instances of {cls} with hash {widget_hash} have been deleted"
+            log.debug("All instances of {cls} with hash {widget_hash} have been deleted"
                 .format(cls=class_, widget_hash=widget_hash))
 
 
@@ -345,7 +345,7 @@
         self.addTarget(target)
         self.profiles = set()
         self._sync = True
-        if isinstance(profiles, basestring):
+        if isinstance(profiles, str):
             self.addProfile(profiles)
         elif profiles is None:
             if not self.PROFILES_ALLOW_NONE:
@@ -430,7 +430,7 @@
         @param profiles: profile(s) associated to target, see __init__ docstring
         @return: a hash (can correspond to one or many targets or profiles, depending of widget class)
         """
-        return unicode(target)  # by defaut, there is one hash for one target
+        return str(target)  # by defaut, there is one hash for one target
 
     # widget life events