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

@ -26,7 +26,7 @@ from sat_frontends.tools import jid
import xml.etree.ElementTree as ET # FIXME: used temporarily to manage XMLUI
from functools import partial
import socket
import SocketServer
import socketserver
import errno
__commands__ = ["Pipe"]
@ -41,7 +41,7 @@ class PipeOut(base.CommandBase):
def add_parser_options(self):
self.parser.add_argument(
"jid", type=base.unicode_decoder, help=_("the destination jid")
"jid", help=_("the destination jid")
)
def streamOutCb(self, port):
@ -69,13 +69,13 @@ class PipeOut(base.CommandBase):
callback=self.streamOutCb,
errback=partial(
self.errback,
msg=_(u"can't start stream: {}"),
msg=_("can't start stream: {}"),
exit_code=C.EXIT_BRIDGE_ERRBACK,
),
)
class StreamServer(SocketServer.BaseRequestHandler):
class StreamServer(socketserver.BaseRequestHandler):
def handle(self):
while True:
data = self.request.recv(4096)
@ -100,7 +100,6 @@ class PipeIn(base.CommandAnswering):
def add_parser_options(self):
self.parser.add_argument(
"jids",
type=base.unicode_decoder,
nargs="*",
help=_('Jids accepted (none means "accept everything")'),
)
@ -112,12 +111,12 @@ class PipeIn(base.CommandAnswering):
try:
xml_ui = action_data["xmlui"]
except KeyError:
self.disp(_(u"Action has no XMLUI"), 1)
self.disp(_("Action has no XMLUI"), 1)
else:
ui = ET.fromstring(xml_ui.encode("utf-8"))
xmlui_id = ui.get("submit")
if not xmlui_id:
self.disp(_(u"Invalid XMLUI received"), error=True)
self.disp(_("Invalid XMLUI received"), error=True)
return xmlui_id
def onStreamAction(self, action_data, action_id, security_limit, profile):
@ -127,14 +126,14 @@ class PipeIn(base.CommandAnswering):
try:
from_jid = jid.JID(action_data["meta_from_jid"])
except KeyError:
self.disp(_(u"Ignoring action without from_jid data"), 1)
self.disp(_("Ignoring action without from_jid data"), 1)
return
if not self.bare_jids or from_jid.bare in self.bare_jids:
host, port = "localhost", START_PORT
while True:
try:
server = SocketServer.TCPServer((host, port), StreamServer)
server = socketserver.TCPServer((host, port), StreamServer)
except socket.error as e:
if e.errno == errno.EADDRINUSE:
port += 1
@ -142,7 +141,7 @@ class PipeIn(base.CommandAnswering):
raise e
else:
break
xmlui_data = {"answer": C.BOOL_TRUE, "port": unicode(port)}
xmlui_data = {"answer": C.BOOL_TRUE, "port": str(port)}
self.host.bridge.launchAction(xmlui_id, xmlui_data, profile_key=profile)
server.serve_forever()
self.host.quitFromSignal()