diff sat/plugins/plugin_xep_0048.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 fee60f17ebac
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0048.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/plugins/plugin_xep_0048.py	Tue Aug 13 19:08:41 2019 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 # SAT plugin for Bookmarks (xep-0048)
@@ -74,7 +74,7 @@
             in_sign="sss",
             out_sign="a{sa{sa{ss}}}",
             method=self._bookmarksList,
-            async=True,
+            async_=True,
         )
         host.bridge.addMethod(
             "bookmarksRemove",
@@ -82,7 +82,7 @@
             in_sign="ssss",
             out_sign="",
             method=self._bookmarksRemove,
-            async=True,
+            async_=True,
         )
         host.bridge.addMethod(
             "bookmarksAdd",
@@ -90,7 +90,7 @@
             in_sign="ssa{ss}ss",
             out_sign="",
             method=self._bookmarksAdd,
-            async=True,
+            async_=True,
         )
         try:
             self.private_plg = self.host.plugins["XEP-0049"]
@@ -115,7 +115,7 @@
 
         for bookmarks in (local, private, pubsub):
             if bookmarks is not None:
-                for (room_jid, data) in bookmarks[XEP_0048.MUC_TYPE].items():
+                for (room_jid, data) in list(bookmarks[XEP_0048.MUC_TYPE].items()):
                     if data.get("autojoin", "false") == "true":
                         nick = data.get("nick", client.jid.user)
                         self.host.plugins["XEP-0045"].join(client, room_jid, nick, {})
@@ -196,8 +196,8 @@
                 if conference_elt.hasAttribute(attr):
                     data[attr] = conference_elt[attr]
             try:
-                data["nick"] = unicode(
-                    conference_elt.elements(NS_BOOKMARKS, "nick").next()
+                data["nick"] = str(
+                    next(conference_elt.elements(NS_BOOKMARKS, "nick"))
                 )
             except StopIteration:
                 pass
@@ -264,7 +264,7 @@
         d = self.host.plugins["XEP-0045"].join(client, room_jid, nick, {})
 
         def join_eb(failure):
-            log.warning(u"Error while trying to join room: {}".format(failure))
+            log.warning("Error while trying to join room: {}".format(failure))
             # FIXME: failure are badly managed in plugin XEP-0045. Plugin XEP-0045 need to be fixed before managing errors correctly here
             return {}
 
@@ -292,12 +292,12 @@
             if bookmarks is None:
                 continue
             for (room_jid, data) in sorted(
-                bookmarks[XEP_0048.MUC_TYPE].items(),
+                list(bookmarks[XEP_0048.MUC_TYPE].items()),
                 key=lambda item: item[1].get("name", item[0].user),
             ):
                 room_jid_s = room_jid.full()
                 adv_list.setRowIndex(
-                    u"%s %s" % (room_jid_s, data.get("nick") or client.jid.user)
+                    "%s %s" % (room_jid_s, data.get("nick") or client.jid.user)
                 )
                 xmlui.addText(data.get("name", ""))
                 xmlui.addJid(room_jid)
@@ -354,7 +354,7 @@
         @param profile_key: %(doc_profile_key)s
         """
         assert storage_type in ("auto", "pubsub", "private", "local")
-        if type_ == XEP_0048.URL_TYPE and {"autojoin", "nick"}.intersection(data.keys()):
+        if type_ == XEP_0048.URL_TYPE and {"autojoin", "nick"}.intersection(list(data.keys())):
             raise ValueError("autojoin or nick can't be used with URLs")
         client = self.host.getClient(profile_key)
         if storage_type == "auto":