diff sat/plugins/plugin_xep_0070.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 a55a14c3cbf4
children 559a625a236b
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0070.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/plugins/plugin_xep_0070.py	Tue Aug 13 19:08:41 2019 +0200
@@ -26,7 +26,7 @@
 from sat.tools import xml_tools
 
 from wokkel import disco, iwokkel
-from zope.interface import implements
+from zope.interface import implementer
 
 try:
     from twisted.words.protocols.xmlstream import XMPPHandler
@@ -63,7 +63,7 @@
     """
 
     def __init__(self, host):
-        log.info(_(u"Plugin XEP_0070 initialization"))
+        log.info(_("Plugin XEP_0070 initialization"))
         self.host = host
         self._dictRequest = dict()
 
@@ -90,15 +90,15 @@
 
     def _treatHttpAuthRequest(self, elt, stanzaType, client):
         elt.handled = True
-        auth_elt = elt.elements(NS_HTTP_AUTH, "confirm").next()
+        auth_elt = next(elt.elements(NS_HTTP_AUTH, "confirm"))
         auth_id = auth_elt["id"]
         auth_method = auth_elt["method"]
         auth_url = auth_elt["url"]
         self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt)
-        title = D_(u"Auth confirmation")
-        message = D_(u"{auth_url} needs to validate your identity, do you agree?\n"
-                     u"Validation code : {auth_id}\n\n"
-                     u"Please check that this code is the same as on {auth_url}"
+        title = D_("Auth confirmation")
+        message = D_("{auth_url} needs to validate your identity, do you agree?\n"
+                     "Validation code : {auth_id}\n\n"
+                     "Please check that this code is the same as on {auth_url}"
                     ).format(auth_url=auth_url, auth_id=auth_id)
         d = xml_tools.deferConfirm(self.host, message=message, title=title,
             profile=client.profile)
@@ -114,23 +114,23 @@
         if authorized:
             if stanzaType == IQ:
                 # iq
-                log.debug(_(u"XEP-0070 reply iq"))
+                log.debug(_("XEP-0070 reply iq"))
                 iq_result_elt = xmlstream.toResponse(elt, "result")
                 client.send(iq_result_elt)
             elif stanzaType == MSG:
                 # message
-                log.debug(_(u"XEP-0070 reply message"))
+                log.debug(_("XEP-0070 reply message"))
                 msg_result_elt = xmlstream.toResponse(elt, "result")
-                msg_result_elt.addChild(elt.elements(NS_HTTP_AUTH, "confirm").next())
+                msg_result_elt.addChild(next(elt.elements(NS_HTTP_AUTH, "confirm")))
                 client.send(msg_result_elt)
         else:
-            log.debug(_(u"XEP-0070 reply error"))
+            log.debug(_("XEP-0070 reply error"))
             result_elt = jabber.error.StanzaError("not-authorized").toResponse(elt)
             client.send(result_elt)
 
 
+@implementer(iwokkel.IDisco)
 class XEP_0070_handler(XMPPHandler):
-    implements(iwokkel.IDisco)
 
     def __init__(self, plugin_parent, profile):
         self.plugin_parent = plugin_parent