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: a jabber client
@ -28,7 +28,7 @@ getLogger().setLevel(logging.WARNING) # put this to DEBUG when needed
from sat.core import exceptions
from sat.tools import config as tools_config
from constants import Const as C
from .constants import Const as C
from wokkel.xmppim import RosterItem
from wokkel.generic import parseXml
from sat.core.xmpp import SatRosterProtocol
@ -49,7 +49,7 @@ def b2s(value):
@return: unicode conversion, according to bridge convention
"""
return u"True" if value else u"False"
return "True" if value else "False"
def muteLogging():
@ -232,11 +232,11 @@ class FakeBridge(object):
def checkCall(*args, **kwargs):
if args != check_args or kwargs != check_kwargs:
print "\n\n--------------------"
print "Args are not equals:"
print "args\n----\n%s (sent)\n%s (wanted)" % (args, check_args)
print "kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs)
print "--------------------\n\n"
print("\n\n--------------------")
print("Args are not equals:")
print("args\n----\n%s (sent)\n%s (wanted)" % (args, check_args))
print("kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs))
print("--------------------\n\n")
raise DifferentArgsException
delattr(self, name)
@ -248,7 +248,7 @@ class FakeBridge(object):
setattr(self, name, checkCall)
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc=None):
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc=None):
pass
def addSignal(self, name, int_suffix, signature):
@ -386,7 +386,7 @@ class FakeXmlStream(object):
@param obj (domish.Element, str or unicode): message to send
"""
if not isinstance(obj, domish.Element):
assert(isinstance(obj, str) or isinstance(obj, unicode))
assert(isinstance(obj, str) or isinstance(obj, str))
obj = parseXml(obj)
if obj.name == 'iq':
@ -432,21 +432,21 @@ class SatTestCase(unittest.TestCase):
value = None
setattr(elt, attr, value)
if (got_elt.tag != exp_elt.tag):
print "XML are not equals (elt %s/%s):" % (got_elt, exp_elt)
print "tag: got [%s] expected: [%s]" % (got_elt.tag, exp_elt.tag)
print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt))
print("tag: got [%s] expected: [%s]" % (got_elt.tag, exp_elt.tag))
return False
if (got_elt.attrib != exp_elt.attrib):
print "XML are not equals (elt %s/%s):" % (got_elt, exp_elt)
print "attribs: got %s expected %s" % (got_elt.attrib, exp_elt.attrib)
print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt))
print("attribs: got %s expected %s" % (got_elt.attrib, exp_elt.attrib))
return False
if (got_elt.tail != exp_elt.tail or got_elt.text != exp_elt.text):
print "XML are not equals (elt %s/%s):" % (got_elt, exp_elt)
print "text: got [%s] expected: [%s]" % (got_elt.text, exp_elt.text)
print "tail: got [%s] expected: [%s]" % (got_elt.tail, exp_elt.tail)
print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt))
print("text: got [%s] expected: [%s]" % (got_elt.text, exp_elt.text))
print("tail: got [%s] expected: [%s]" % (got_elt.tail, exp_elt.tail))
return False
if (len(got_elt) != len(exp_elt)):
print "XML are not equals (elt %s/%s):" % (got_elt, exp_elt)
print "children len: got %d expected: %d" % (len(got_elt), len(exp_elt))
print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt))
print("children len: got %d expected: %d" % (len(got_elt), len(exp_elt)))
return False
for idx, child in enumerate(got_elt):
if not equalElt(child, exp_elt[idx]):
@ -461,22 +461,22 @@ class SatTestCase(unittest.TestCase):
expected_elt = etree.fromstring(remove_blank(expected) if ignore_blank else expected)
if not equalElt(xml_elt, expected_elt):
print "---"
print "XML are not equals:"
print "got:\n-\n%s\n-\n\n" % etree.tostring(xml_elt, encoding='utf-8')
print "was expecting:\n-\n%s\n-\n\n" % etree.tostring(expected_elt, encoding='utf-8')
print "---"
print("---")
print("XML are not equals:")
print("got:\n-\n%s\n-\n\n" % etree.tostring(xml_elt, encoding='utf-8'))
print("was expecting:\n-\n%s\n-\n\n" % etree.tostring(expected_elt, encoding='utf-8'))
print("---")
raise DifferentXMLException
def assertEqualUnsortedList(self, a, b, msg):
counter_a = Counter(a)
counter_b = Counter(b)
if counter_a != counter_b:
print "---"
print "Unsorted lists are not equals:"
print "got : %s" % counter_a
print "was expecting: %s" % counter_b
print("---")
print("Unsorted lists are not equals:")
print("got : %s" % counter_a)
print("was expecting: %s" % counter_b)
if msg:
print msg
print "---"
print(msg)
print("---")
raise DifferentListException