diff sat_frontends/quick_frontend/quick_contact_list.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 8990ed9aad31
children f8e3789912d0
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_contact_list.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat_frontends/quick_frontend/quick_contact_list.py	Tue Aug 13 19:08:41 2019 +0200
@@ -32,7 +32,7 @@
 
 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
     # XXX: pyjamas' max doesn't support key argument, so we implement it ourself
@@ -46,7 +46,7 @@
     # next doesn't exist in pyjamas
     def next(iterable, *args):
         try:
-            return iterable.next()
+            return iterable.__next__()
         except StopIteration as e:
             if args:
                 return args[0]
@@ -184,7 +184,7 @@
         @return (dict[jid.JID, set(unicode)])
         """
         result = {}
-        for group, data in self._groups.iteritems():
+        for group, data in self._groups.items():
             for entity in data["jids"]:
                 result.setdefault(entity, set()).add(group)
         return result
@@ -203,7 +203,7 @@
 
         entities are not sorted
         """
-        return self._cache.iteritems()
+        return iter(self._cache.items())
 
     @property
     def items(self):
@@ -214,7 +214,7 @@
         """
         return {
             jid_: cache
-            for jid_, cache in self._cache.iteritems()
+            for jid_, cache in self._cache.items()
             if self.entityVisible(jid_)
         }
 
@@ -340,9 +340,9 @@
         @raise ValueError: the entity is not bare
         """
         if entity.resource:
-            raise ValueError(u"getFullJid must be used with a bare jid")
+            raise ValueError("getFullJid must be used with a bare jid")
         main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE)
-        return jid.JID(u"{}/{}".format(entity, main_resource))
+        return jid.JID("{}/{}".format(entity, main_resource))
 
     def setGroupData(self, group, name, value):
         """Register a data for a group
@@ -508,7 +508,7 @@
             if entity.resource
             else cache
         )
-        for attribute, value in attributes.iteritems():
+        for attribute, value in attributes.items():
             if value is None:
                 # XXX: pyjamas hack: we need to use pop instead of del
                 try:
@@ -596,7 +596,7 @@
         try:
             groups = self._cache[entity_bare].get(C.CONTACT_GROUPS, set())
         except KeyError:
-            log.error(_(u"Trying to delete an unknow entity [{}]").format(entity))
+            log.error(_("Trying to delete an unknow entity [{}]").format(entity))
         try:
             self._roster.remove(entity_bare)
         except KeyError:
@@ -639,8 +639,8 @@
                     del cache[C.CONTACT_RESOURCES][entity.resource]
                 except KeyError:
                     log.error(
-                        u"Presence unavailable received "
-                        u"for an unknown resource [{}]".format(entity)
+                        "Presence unavailable received "
+                        "for an unknown resource [{}]".format(entity)
                     )
                 if not cache[C.CONTACT_RESOURCES]:
                     cache[C.CONTACT_MAIN_RESOURCE] = None
@@ -648,8 +648,8 @@
             if not entity.resource:
                 log.warning(
                     _(
-                        u"received presence from entity "
-                        u"without resource: {}".format(entity)
+                        "received presence from entity "
+                        "without resource: {}".format(entity)
                     )
                 )
             resources_data = cache[C.CONTACT_RESOURCES]
@@ -703,12 +703,12 @@
         try:
             cache = self._cache[entity.bare]
         except:
-            log.error(u"Try to unselect an entity not in cache")
+            log.error("Try to unselect an entity not in cache")
         else:
             try:
                 cache[C.CONTACT_SELECTED].remove(entity.resource)
             except KeyError:
-                log.error(u"Try to unselect a not selected entity")
+                log.error("Try to unselect a not selected entity")
             else:
                 self._selected.remove(entity)
                 self.update([entity], C.UPDATE_SELECTION)
@@ -721,15 +721,15 @@
         """
         if entity is None:
             self._selected.clear()
-            for cache in self._cache.itervalues():
+            for cache in self._cache.values():
                 cache[C.CONTACT_SELECTED].clear()
             self.update(type_=C.UPDATE_SELECTION, profile=self.profile)
         else:
-            log.debug(u"select %s" % entity)
+            log.debug("select %s" % entity)
             try:
                 cache = self._cache[entity.bare]
             except:
-                log.error(u"Try to select an entity not in cache")
+                log.error("Try to select an entity not in cache")
             else:
                 cache[C.CONTACT_SELECTED].add(entity.resource)
                 self._selected.add(entity)
@@ -777,7 +777,7 @@
         global handler
         if handler is not None:
             raise exceptions.InternalError(
-                u"QuickContactListHandler must be instanciated only once"
+                "QuickContactListHandler must be instanciated only once"
             )
         handler = self
         self._clist = {}  # key: profile, value: ProfileContactList
@@ -794,7 +794,7 @@
         @param entity (jid.JID): jid of the entity (resource is not ignored,
             use bare jid if needed)
         """
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             if entity in contact_list:
                 return True
         return False
@@ -806,7 +806,7 @@
         @return (set[jid.JID])
         """
         entities = set()
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             entities.update(contact_list.roster)
         return entities
 
@@ -817,7 +817,7 @@
         @return (set[jid.JID])
         """
         entities = set()
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             entities.update(contact_list.roster_connected)
         return entities
 
@@ -829,7 +829,7 @@
         @return (dict[unicode,set(jid.JID)])
         """
         groups = {}
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             groups.update(contact_list.roster_entities_by_group)
         return groups
 
@@ -841,7 +841,7 @@
         @return (dict[jid.JID, set(unicode)])
         """
         entities = {}
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             entities.update(contact_list.roster_groups_by_entities)
         return entities
 
@@ -852,7 +852,7 @@
         @return (set): set of selected entities
         """
         entities = set()
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             entities.update(contact_list.selected)
         return entities
 
@@ -862,7 +862,7 @@
 
         items are unordered
         """
-        for profile, contact_list in self._clist.iteritems():
+        for profile, contact_list in self._clist.items():
             for bare_jid, cache in contact_list.all_iter:
                 data = cache.copy()
                 data[C.CONTACT_PROFILE] = profile
@@ -876,8 +876,8 @@
         key: bare jid, value: data
         """
         items = {}
-        for profile, contact_list in self._clist.iteritems():
-            for bare_jid, cache in contact_list.items.iteritems():
+        for profile, contact_list in self._clist.items():
+            for bare_jid, cache in contact_list.items.items():
                 data = cache.copy()
                 items[bare_jid] = data
                 data[C.CONTACT_PROFILE] = profile
@@ -953,7 +953,7 @@
         @return (set[jid.JID])
         """
         entities = set()
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             entities.update(contact_list.getSpecialExtras(special_type))
         return entities
 
@@ -984,13 +984,13 @@
             assert profile in self._clist
             to_fill.add(profile)
         else:
-            to_fill.update(self._clist.keys())
+            to_fill.update(list(self._clist.keys()))
 
         remaining = to_fill.difference(filled)
         if remaining != to_fill:
             log.debug(
-                u"Not re-filling already filled contact list(s) for {}".format(
-                    u", ".join(to_fill.intersection(filled))
+                "Not re-filling already filled contact list(s) for {}".format(
+                    ", ".join(to_fill.intersection(filled))
                 )
             )
         for profile in remaining:
@@ -1001,17 +1001,17 @@
 
         @param keep_cache: if True, don't reset the cache
         """
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             contact_list.clearContacts(keep_cache)
         # we need a full update
         self.update()
 
     def select(self, entity):
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             contact_list.select(entity)
 
     def unselect(self, entity):
-        for contact_list in self._clist.itervalues():
+        for contact_list in self._clist.values():
             contact_list.select(entity)
 
     def lockUpdate(self, locked=True, do_update=True):
@@ -1025,8 +1025,8 @@
             what youa re doing!
         """
         log.debug(
-            u"Contact lists updates are now {}".format(
-                u"LOCKED" if locked else u"UNLOCKED"
+            "Contact lists updates are now {}".format(
+                "LOCKED" if locked else "UNLOCKED"
             )
         )
         self._update_locked = locked