Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0199.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/plugins/plugin_xep_0199.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat/plugins/plugin_xep_0199.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 Delayed Delivery (XEP-0199) @@ -25,21 +25,21 @@ from sat.core.constants import Const as C from wokkel import disco, iwokkel from twisted.words.protocols.jabber import xmlstream, jid -from zope.interface import implements +from zope.interface import implementer import time PLUGIN_INFO = { - C.PI_NAME: u"XMPP PING", - C.PI_IMPORT_NAME: u"XEP-0199", - C.PI_TYPE: u"XEP", - C.PI_PROTOCOLS: [u"XEP-199"], + C.PI_NAME: "XMPP PING", + C.PI_IMPORT_NAME: "XEP-0199", + C.PI_TYPE: "XEP", + C.PI_PROTOCOLS: ["XEP-199"], C.PI_MAIN: "XEP_0199", - C.PI_HANDLER: u"yes", - C.PI_DESCRIPTION: D_(u"""Implementation of XMPP Ping"""), + C.PI_HANDLER: "yes", + C.PI_DESCRIPTION: D_("""Implementation of XMPP Ping"""), } -NS_PING = u"urn:xmpp:ping" +NS_PING = "urn:xmpp:ping" PING_REQUEST = C.IQ_GET + '/ping[@xmlns="' + NS_PING + '"]' @@ -49,11 +49,11 @@ log.info(_("XMPP Ping plugin initialization")) self.host = host host.bridge.addMethod( - "ping", ".plugin", in_sign='ss', out_sign='d', method=self._ping, async=True) + "ping", ".plugin", in_sign='ss', out_sign='d', method=self._ping, async_=True) try: self.text_cmds = self.host.plugins[C.TEXT_CMDS] except KeyError: - log.info(_(u"Text commands not available")) + log.info(_("Text commands not available")) else: self.text_cmds.registerTextCommands(self) @@ -62,7 +62,7 @@ def _pingRaiseIfFailure(self, pong): """If ping didn't succeed, raise the failure, else return pong delay""" - if pong[0] != u"PONG": + if pong[0] != "PONG": raise pong[0] return pong[1] @@ -75,7 +75,7 @@ def _pingCb(self, iq_result, send_time): receive_time = time.time() - return (u"PONG", receive_time - send_time) + return ("PONG", receive_time - send_time) def _pingEb(self, failure_, send_time): receive_time = time.time() @@ -102,11 +102,11 @@ """Send feedback to client when pong data is received""" txt_cmd = self.host.plugins[C.TEXT_CMDS] - if pong[0] == u"PONG": - txt_cmd.feedBack(client, u"PONG ({time} s)".format(time=pong[1]), mess_data) + if pong[0] == "PONG": + txt_cmd.feedBack(client, "PONG ({time} s)".format(time=pong[1]), mess_data) else: txt_cmd.feedBack( - client, _(u"ping error ({err_msg}). Response time: {time} s") + client, _("ping error ({err_msg}). Response time: {time} s") .format(err_msg=pong[0], time=pong[1]), mess_data) def cmd_ping(self, client, mess_data): @@ -120,7 +120,7 @@ entity_jid = jid.JID(mess_data["unparsed"].strip()) except RuntimeError: txt_cmd = self.host.plugins[C.TEXT_CMDS] - txt_cmd.feedBack(client, _(u'Invalid jid: "{entity_jid}"').format( + txt_cmd.feedBack(client, _('Invalid jid: "{entity_jid}"').format( entity_jid=mess_data["unparsed"].strip()), mess_data) return False else: @@ -131,15 +131,15 @@ return False def onPingRequest(self, iq_elt, client): - log.info(_(u"XMPP PING received from {from_jid} [{profile}]").format( + log.info(_("XMPP PING received from {from_jid} [{profile}]").format( from_jid=iq_elt["from"], profile=client.profile)) iq_elt.handled = True iq_result_elt = xmlstream.toResponse(iq_elt, "result") client.send(iq_result_elt) +@implementer(iwokkel.IDisco) class XEP_0199_handler(xmlstream.XMPPHandler): - implements(iwokkel.IDisco) def __init__(self, plugin_parent): self.plugin_parent = plugin_parent