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 managing xep-0115
@ -25,7 +25,7 @@ log = getLogger(__name__)
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid
from twisted.internet import defer, error
from zope.interface import implements
from zope.interface import implementer
from wokkel import disco, iwokkel
try:
@ -70,10 +70,10 @@ class XEP_0115(object):
# optimize check
client._caps_optimize = yield self.host.hasFeature(client, NS_CAPS_OPTIMIZE)
if client._caps_optimize:
log.info(_(u"Caps optimisation enabled"))
log.info(_("Caps optimisation enabled"))
client._caps_sent = False
else:
log.warning(_(u"Caps optimisation not available"))
log.warning(_("Caps optimisation not available"))
# hash generation
_infos = yield client.discoHandler.info(client.jid, client.jid, "")
@ -82,11 +82,11 @@ class XEP_0115(object):
disco_infos.append(item)
cap_hash = client._caps_hash = self.host.memory.disco.generateHash(disco_infos)
log.info(
u"Our capability hash has been generated: [{cap_hash}]".format(
"Our capability hash has been generated: [{cap_hash}]".format(
cap_hash=cap_hash
)
)
log.debug(u"Generating capability domish.Element")
log.debug("Generating capability domish.Element")
c_elt = domish.Element((NS_ENTITY_CAPABILITY, "c"))
c_elt["hash"] = "sha-1"
c_elt["node"] = C.APP_URL
@ -115,8 +115,8 @@ class XEP_0115(object):
return True
@implementer(iwokkel.IDisco)
class XEP_0115_handler(XMPPHandler):
implements(iwokkel.IDisco)
def __init__(self, plugin_parent, profile):
self.plugin_parent = plugin_parent
@ -142,19 +142,19 @@ class XEP_0115_handler(XMPPHandler):
Check if we know the version of this capabilities and get the capabilities if necessary
"""
from_jid = jid.JID(presence["from"])
c_elem = presence.elements(NS_ENTITY_CAPABILITY, "c").next()
c_elem = next(presence.elements(NS_ENTITY_CAPABILITY, "c"))
try:
c_ver = c_elem["ver"]
c_hash = c_elem["hash"]
c_node = c_elem["node"]
except KeyError:
log.warning(_(u"Received invalid capabilities tag: %s") % c_elem.toXml())
log.warning(_("Received invalid capabilities tag: %s") % c_elem.toXml())
return
if c_ver in self.host.memory.disco.hashes:
# we already know the hash, we update the jid entity
log.debug(
u"hash [%(hash)s] already in cache, updating entity [%(jid)s]"
"hash [%(hash)s] already in cache, updating entity [%(jid)s]"
% {"hash": c_ver, "jid": from_jid.full()}
)
self.host.memory.updateEntityData(
@ -165,8 +165,8 @@ class XEP_0115_handler(XMPPHandler):
if c_hash != "sha-1": # unknown hash method
log.warning(
_(
u"Unknown hash method for entity capabilities: [{hash_method}] "
u"(entity: {entity_jid}, node: {node})"
"Unknown hash method for entity capabilities: [{hash_method}] "
"(entity: {entity_jid}, node: {node})"
)
.format(hash_method = c_hash, entity_jid = from_jid, node = c_node)
)
@ -178,10 +178,10 @@ class XEP_0115_handler(XMPPHandler):
if computed_hash != c_ver:
log.warning(
_(
u"Computed hash differ from given hash:\n"
u"given: [{given}]\n"
u"computed: [{computed}]\n"
u"(entity: {entity_jid}, node: {node})"
"Computed hash differ from given hash:\n"
"given: [{given}]\n"
"computed: [{computed}]\n"
"(entity: {entity_jid}, node: {node})"
).format(
given = c_ver,
computed = computed_hash,
@ -199,7 +199,7 @@ class XEP_0115_handler(XMPPHandler):
else failure.getErrorMessage()
)
log.error(
_(u"Couldn't retrieve disco info for {jid}: {error}").format(
_("Couldn't retrieve disco info for {jid}: {error}").format(
jid=from_jid.full(), error=msg
)
)