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
This commit is contained in:
Goffi 2019-08-13 19:08:41 +02:00
commit fbfe96c505

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# SAT plugin for Explicit Message Encryption
@ -25,26 +25,26 @@ from sat.core.log import getLogger
log = getLogger(__name__)
PLUGIN_INFO = {
C.PI_NAME: u"Client State Indication",
C.PI_IMPORT_NAME: u"XEP-0352",
C.PI_NAME: "Client State Indication",
C.PI_IMPORT_NAME: "XEP-0352",
C.PI_TYPE: C.PLUG_TYPE_XEP,
C.PI_PROTOCOLS: [u"XEP-0352"],
C.PI_PROTOCOLS: ["XEP-0352"],
C.PI_DEPENDENCIES: [],
C.PI_MAIN: u"XEP_0352",
C.PI_HANDLER: u"no",
C.PI_DESCRIPTION: D_(u"Notify server when frontend is not actively used, to limit "
u"traffic and save bandwidth and battery life"),
C.PI_MAIN: "XEP_0352",
C.PI_HANDLER: "no",
C.PI_DESCRIPTION: D_("Notify server when frontend is not actively used, to limit "
"traffic and save bandwidth and battery life"),
}
NS_CSI = u"urn:xmpp:csi:0"
NS_CSI = "urn:xmpp:csi:0"
class XEP_0352(object):
def __init__(self, host):
log.info(_(u"Client State Indication plugin initialization"))
log.info(_("Client State Indication plugin initialization"))
self.host = host
host.registerNamespace(u"csi", NS_CSI)
host.registerNamespace("csi", NS_CSI)
def isActive(self, client):
try:
@ -54,30 +54,30 @@ class XEP_0352(object):
except AttributeError:
# _xep_0352_active can not be set if isActive is called before
# profileConnected has been called
log.debug(u"isActive called when XEP-0352 plugin has not yet set the "
u"attributes")
log.debug("isActive called when XEP-0352 plugin has not yet set the "
"attributes")
return True
def profileConnected(self, client):
if (NS_CSI, u'csi') in client.xmlstream.features:
log.info(_(u"Client State Indication is available on this server"))
if (NS_CSI, 'csi') in client.xmlstream.features:
log.info(_("Client State Indication is available on this server"))
client._xep_0352_enabled = True
client._xep_0352_active = True
else:
log.warning(_(u"Client State Indication is not available on this server, some"
u" bandwidth optimisations can't be used."))
log.warning(_("Client State Indication is not available on this server, some"
" bandwidth optimisations can't be used."))
client._xep_0352_enabled = False
def setInactive(self, client):
if self.isActive(client):
inactive_elt = domish.Element((NS_CSI, u'inactive'))
inactive_elt = domish.Element((NS_CSI, 'inactive'))
client.send(inactive_elt)
client._xep_0352_active = False
log.info(u"inactive state set")
log.info("inactive state set")
def setActive(self, client):
if not self.isActive(client):
active_elt = domish.Element((NS_CSI, u'active'))
active_elt = domish.Element((NS_CSI, 'active'))
client.send(active_elt)
client._xep_0352_active = True
log.info(u"active state set")
log.info("active state set")