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
@ -56,7 +56,7 @@ class CommandProtocol(protocol.ProcessProtocol):
return os.path.splitext(os.path.basename(self.command))[0].decode('utf-8',
'ignore')
else:
return u''
return ''
def connectionMade(self):
if self._stdin is not None:
@ -74,22 +74,22 @@ class CommandProtocol(protocol.ProcessProtocol):
self.err_data.append(data)
def processEnded(self, reason):
data = ''.join(self.data)
data = b''.join(self.data)
if (reason.value.exitCode == 0):
log.debug(_(u'{name} command succeed').format(name=self.command_name))
log.debug(_('{name} command succeed').format(name=self.command_name))
# we don't use "replace" on purpose, we want an exception if decoding
# is not working properly
self._deferred.callback(data.encode('utf-8'))
self._deferred.callback(data)
else:
err_data = u''.join(self.err_data)
err_data = b''.join(self.err_data)
msg = (_(u"Can't complete {name} command (error code: {code}):\n"
u"stderr:\n{stderr}\n{stdout}\n")
msg = (_("Can't complete {name} command (error code: {code}):\n"
"stderr:\n{stderr}\n{stdout}\n")
.format(name = self.command_name,
code = reason.value.exitCode,
stderr= err_data.encode('utf-8', 'replace'),
stdout = "stdout: " + data.encode('utf-8', 'replace')
if data else u'',
stdout = "stdout: " + data.decode('utf-8', 'replace')
if data else '',
))
self._deferred.errback(Failure(exceptions.CommandException(
msg, data, err_data)))
@ -114,10 +114,10 @@ class CommandProtocol(protocol.ProcessProtocol):
if stdin is not None:
stdin = stdin.encode('utf-8')
verbose = kwargs.pop('verbose', False)
if u'path' in kwargs:
kwargs[u'path'] = kwargs[u'path'].encode('utf-8')
if 'path' in kwargs:
kwargs['path'] = kwargs['path'].encode('utf-8')
args = [a.encode('utf-8') for a in args]
kwargs = {k:v.encode('utf-8') for k,v in kwargs.items()}
kwargs = {k:v.encode('utf-8') for k,v in list(kwargs.items())}
d = defer.Deferred()
prot = cls(d, stdin=stdin)
if verbose:
@ -125,12 +125,12 @@ class CommandProtocol(protocol.ProcessProtocol):
if cls.command is None:
if not args:
raise ValueError(
u"You must either specify cls.command or use a full path to command "
u"to execute as first argument")
"You must either specify cls.command or use a full path to command "
"to execute as first argument")
command = args.pop(0)
if prot.name is None:
name = os.path.splitext(os.path.basename(command))[0]
prot.name = name.encode(u'utf-8', u'ignore')
prot.name = name
else:
command = cls.command
cmd_args = [os.path.basename(command)] + args