diff sat_frontends/quick_frontend/quick_menus.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 003b8b4b56a7
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_menus.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/quick_frontend/quick_menus.py	Tue Aug 13 19:08:41 2019 +0200
@@ -19,12 +19,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
 
 from sat.core.log import getLogger
 from sat.core.i18n import _, languageSwitch
@@ -100,11 +100,11 @@
 
         else:
             if caller is None:
-                log.error(u"Caller can't be None with a dictionary as data_collector")
+                log.error("Caller can't be None with a dictionary as data_collector")
                 return {}
             data = {}
-            for data_key, caller_attr in data_collector.iteritems():
-                data[data_key] = unicode(getattr(caller, caller_attr))
+            for data_key, caller_attr in data_collector.items():
+                data[data_key] = str(getattr(caller, caller_attr))
             return data
 
     def call(self, caller, profile=C.PROF_KEY_NONE):
@@ -189,7 +189,7 @@
 
     def __init__(self):
         MenuSeparator.SEP_IDX += 1
-        name = u"___separator_{}".format(MenuSeparator.SEP_IDX)
+        name = "___separator_{}".format(MenuSeparator.SEP_IDX)
         MenuItem.__init__(self, name, name)
 
 
@@ -208,7 +208,7 @@
         return item.canonical in self._items
 
     def __iter__(self):
-        return self._items.itervalues()
+        return iter(self._items.values())
 
     def __getitem__(self, item):
         try:
@@ -218,8 +218,8 @@
 
     def getOrCreate(self, item):
         log.debug(
-            u"MenuContainer getOrCreate: item=%s name=%s\nlist=%s"
-            % (item, item.canonical, self._items.keys())
+            "MenuContainer getOrCreate: item=%s name=%s\nlist=%s"
+            % (item, item.canonical, list(self._items.keys()))
         )
         try:
             return self[item]
@@ -229,7 +229,7 @@
 
     def getActiveMenus(self):
         """Return an iterator on active children"""
-        for child in self._items.itervalues():
+        for child in self._items.values():
             if child.ACTIVE:
                 yield child
 
@@ -347,7 +347,7 @@
         try:
             return QuickMenusManager._data_collectors[type_]
         except KeyError:
-            log.error(u"No data collector registered for {}".format(type_))
+            log.error("No data collector registered for {}".format(type_))
             return None
 
     def addMenuItem(self, type_, path, item, path_i18n=None, top_extra=None):
@@ -375,14 +375,14 @@
                 elif isinstance(container_item, MenuHook):
                     # MenuHook must not be replaced
                     log.debug(
-                        u"ignoring menu at path [{}] because a hook is already in place".format(
+                        "ignoring menu at path [{}] because a hook is already in place".format(
                             path
                         )
                     )
                 else:
-                    log.error(u"Conflicting menus at path [{}]".format(path))
+                    log.error("Conflicting menus at path [{}]".format(path))
         else:
-            log.debug(u"Adding menu [{type_}] {path}".format(type_=type_, path=path))
+            log.debug("Adding menu [{type_}] {path}".format(type_=type_, path=path))
             menu_container.append(item)
             self.host.callListeners("menu", type_, path, path_i18n, item)
 
@@ -461,7 +461,7 @@
             type_, path[-1], path_i18n[-1], callback=callback, extra=extra
         )
         self.addMenuItem(type_, path[:-1], menu_item, path_i18n[:-1], top_extra)
-        log.info(u"Menu hook set on {path} ({type_})".format(path=path, type_=type_))
+        log.info("Menu hook set on {path} ({type_})".format(path=path, type_=type_))
 
     def addCategory(self, type_, path, path_i18n=None, extra=None, top_extra=None):
         """Create a category with all parents, and set extra on the last one