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:
parent
d21a6a660f
commit
fbfe96c505
11 changed files with 6336 additions and 6398 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -53,7 +53,7 @@ class DbusXmlConstructor(base_constructor.Constructor):
|
|||
sections.sort()
|
||||
for section in sections:
|
||||
function = self.getValues(section)
|
||||
print("Adding %s %s" % (section, function["type"]))
|
||||
print(("Adding %s %s" % (section, function["type"])))
|
||||
new_elt = doc.createElement(
|
||||
"method" if function["type"] == "method" else "signal"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -114,5 +114,5 @@ class DbusConstructor(base_constructor.Constructor):
|
|||
% completion
|
||||
)
|
||||
completion["result"] = (
|
||||
"unicode(%s)" if self.args.unicode and function["sig_out"] == "s" else "%s"
|
||||
"str(%s)" if self.args.unicode and function["sig_out"] == "s" else "%s"
|
||||
) % result
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT: a jabber client
|
||||
|
|
@ -101,11 +101,11 @@ class DbusObject(dbus.service.Object):
|
|||
raise InternalError
|
||||
callback = kwargs.pop("callback")
|
||||
errback = kwargs.pop("errback")
|
||||
async = True
|
||||
async_ = True
|
||||
else:
|
||||
async = False
|
||||
async_ = False
|
||||
result = self.cb[name](*args, **kwargs)
|
||||
if async:
|
||||
if async_:
|
||||
if not isinstance(result, Deferred):
|
||||
log.error("Asynchronous method [%s] does not return a Deferred." % name)
|
||||
raise AsyncNotDeferred
|
||||
|
|
@ -170,9 +170,9 @@ class DbusObject(dbus.service.Object):
|
|||
i += 1
|
||||
return attr
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False):
|
||||
"""Dynamically add a method to Dbus Bridge"""
|
||||
inspect_args = inspect.getargspec(method)
|
||||
inspect_args = inspect.getfullargspec(method)
|
||||
|
||||
_arguments = inspect_args.args
|
||||
_defaults = list(inspect_args.defaults or [])
|
||||
|
|
@ -186,12 +186,12 @@ class DbusObject(dbus.service.Object):
|
|||
[repr(name)]
|
||||
+ (
|
||||
(_arguments + ["callback=callback", "errback=errback"])
|
||||
if async
|
||||
if async_
|
||||
else _arguments
|
||||
)
|
||||
)
|
||||
|
||||
if async:
|
||||
if async_:
|
||||
_arguments.extend(["callback", "errback"])
|
||||
_defaults.extend([None, None])
|
||||
|
||||
|
|
@ -213,7 +213,7 @@ class DbusObject(dbus.service.Object):
|
|||
)
|
||||
exec(code) # FIXME: to the same thing in a cleaner way, without compile/exec
|
||||
method = locals()[name]
|
||||
async_callbacks = ("callback", "errback") if async else None
|
||||
async_callbacks = ("callback", "errback") if async_ else None
|
||||
setattr(
|
||||
DbusObject,
|
||||
name,
|
||||
|
|
@ -265,7 +265,7 @@ class Bridge(object):
|
|||
if e._dbus_error_name == "org.freedesktop.DBus.Error.NotSupported":
|
||||
log.error(
|
||||
_(
|
||||
u"D-Bus is not launched, please see README to see instructions on how to launch it"
|
||||
"D-Bus is not launched, please see README to see instructions on how to launch it"
|
||||
)
|
||||
)
|
||||
raise BridgeInitError
|
||||
|
|
@ -277,11 +277,11 @@ class Bridge(object):
|
|||
log.debug("registering DBus bridge method [%s]" % name)
|
||||
self.dbus_bridge.register_method(name, callback)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
"""Dynamically add a method to Dbus Bridge"""
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method [%s] to DBus bridge" % name)
|
||||
self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async)
|
||||
self.dbus_bridge.addMethod(name, int_suffix, in_sign, out_sign, method, async_)
|
||||
self.register_method(name, method)
|
||||
|
||||
def addSignal(self, name, int_suffix, signature, doc={}):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
#-*- coding: utf-8 -*-
|
||||
|
||||
# SAT communication bridge
|
||||
|
|
@ -70,12 +70,12 @@ class Bridge(object):
|
|||
dbus_interface=const_INT_PREFIX + const_CORE_SUFFIX)
|
||||
self.db_plugin_iface = dbus.Interface(self.db_object,
|
||||
dbus_interface=const_INT_PREFIX + const_PLUGIN_SUFFIX)
|
||||
except dbus.exceptions.DBusException, e:
|
||||
except dbus.exceptions.DBusException as e:
|
||||
if e._dbus_error_name in ('org.freedesktop.DBus.Error.ServiceUnknown',
|
||||
'org.freedesktop.DBus.Error.Spawn.ExecFailed'):
|
||||
errback(BridgeExceptionNoService())
|
||||
elif e._dbus_error_name == 'org.freedesktop.DBus.Error.NotSupported':
|
||||
log.error(_(u"D-Bus is not launched, please see README to see instructions on how to launch it"))
|
||||
log.error(_("D-Bus is not launched, please see README to see instructions on how to launch it"))
|
||||
errback(BridgeInitError)
|
||||
else:
|
||||
errback(e)
|
||||
|
|
@ -102,14 +102,14 @@ class Bridge(object):
|
|||
# - if we have the 'callback' and 'errback' keyword arguments
|
||||
# - or if the last two arguments are callable
|
||||
|
||||
async = False
|
||||
async_ = False
|
||||
args = list(args)
|
||||
|
||||
if kwargs:
|
||||
if 'callback' in kwargs:
|
||||
async = True
|
||||
async_ = True
|
||||
_callback = kwargs.pop('callback')
|
||||
_errback = kwargs.pop('errback', lambda failure: log.error(unicode(failure)))
|
||||
_errback = kwargs.pop('errback', lambda failure: log.error(str(failure)))
|
||||
try:
|
||||
args.append(kwargs.pop('profile'))
|
||||
except KeyError:
|
||||
|
|
@ -119,15 +119,15 @@ class Bridge(object):
|
|||
pass
|
||||
# at this point, kwargs should be empty
|
||||
if kwargs:
|
||||
log.warnings(u"unexpected keyword arguments, they will be ignored: {}".format(kwargs))
|
||||
log.warnings("unexpected keyword arguments, they will be ignored: {}".format(kwargs))
|
||||
elif len(args) >= 2 and callable(args[-1]) and callable(args[-2]):
|
||||
async = True
|
||||
async_ = True
|
||||
_errback = args.pop()
|
||||
_callback = args.pop()
|
||||
|
||||
method = getattr(self.db_plugin_iface, name)
|
||||
|
||||
if async:
|
||||
if async_:
|
||||
kwargs['timeout'] = const_TIMEOUT
|
||||
kwargs['reply_handler'] = _callback
|
||||
kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -25,7 +25,7 @@ from sat.core import exceptions
|
|||
|
||||
class _Bridge(object):
|
||||
def __init__(self):
|
||||
log.debug(u"Init embedded bridge...")
|
||||
log.debug("Init embedded bridge...")
|
||||
self._methods_cbs = {}
|
||||
self._signals_cbs = {"core": {}, "plugin": {}}
|
||||
|
||||
|
|
@ -33,16 +33,16 @@ class _Bridge(object):
|
|||
callback()
|
||||
|
||||
def register_method(self, name, callback):
|
||||
log.debug(u"registering embedded bridge method [{}]".format(name))
|
||||
log.debug("registering embedded bridge method [{}]".format(name))
|
||||
if name in self._methods_cbs:
|
||||
raise exceptions.ConflictError(u"method {} is already regitered".format(name))
|
||||
raise exceptions.ConflictError("method {} is already regitered".format(name))
|
||||
self._methods_cbs[name] = callback
|
||||
|
||||
def register_signal(self, functionName, handler, iface="core"):
|
||||
iface_dict = self._signals_cbs[iface]
|
||||
if functionName in iface_dict:
|
||||
raise exceptions.ConflictError(
|
||||
u"signal {name} is already regitered for interface {iface}".format(
|
||||
"signal {name} is already regitered for interface {iface}".format(
|
||||
name=functionName, iface=iface
|
||||
)
|
||||
)
|
||||
|
|
@ -81,11 +81,11 @@ class _Bridge(object):
|
|||
try:
|
||||
cb = self._signals_cbs["plugin"][name]
|
||||
except KeyError:
|
||||
log.debug(u"ignoring signal {}: no callback registered".format(name))
|
||||
log.debug("ignoring signal {}: no callback registered".format(name))
|
||||
else:
|
||||
cb(*args, **kwargs)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method [{}] to embedded bridge".format(name))
|
||||
self.register_method(name, method)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
@ -85,7 +85,7 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
sections.sort()
|
||||
for section in sections:
|
||||
function = self.getValues(section)
|
||||
print("Adding %s %s" % (section, function["type"]))
|
||||
print(("Adding %s %s" % (section, function["type"])))
|
||||
async_msg = """<br />'''This method is asynchronous'''"""
|
||||
deprecated_msg = """<br />'''<font color="#FF0000">/!\ WARNING /!\ : This method is deprecated, please don't use it !</font>'''"""
|
||||
signature_signal = (
|
||||
|
|
@ -161,7 +161,7 @@ class MediawikiConstructor(base_constructor.Constructor):
|
|||
else:
|
||||
core_bridge.append(line.replace("\n", ""))
|
||||
except IOError:
|
||||
print("Can't open template file [%s]" % template_path)
|
||||
print(("Can't open template file [%s]" % template_path))
|
||||
sys.exit(1)
|
||||
|
||||
# now we write to final file
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SàT: a XMPP client
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT: a jabber client
|
||||
|
|
@ -46,11 +46,11 @@ class PBRoot(pb.Root):
|
|||
|
||||
def remote_initBridge(self, signals_handler):
|
||||
self.signals_handlers.append(signals_handler)
|
||||
log.info(u"registered signal handler")
|
||||
log.info("registered signal handler")
|
||||
|
||||
def sendSignalEb(self, failure, signal_name):
|
||||
log.error(
|
||||
u"Error while sending signal {name}: {msg}".format(
|
||||
"Error while sending signal {name}: {msg}".format(
|
||||
name=signal_name, msg=failure
|
||||
)
|
||||
)
|
||||
|
|
@ -66,27 +66,27 @@ class PBRoot(pb.Root):
|
|||
d.addErrback(self.sendSignalEb, name)
|
||||
if to_remove:
|
||||
for handler in to_remove:
|
||||
log.debug(u"Removing signal handler for dead frontend")
|
||||
log.debug("Removing signal handler for dead frontend")
|
||||
self.signals_handlers.remove(handler)
|
||||
|
||||
def _bridgeDeactivateSignals(self):
|
||||
if hasattr(self, "signals_paused"):
|
||||
log.warning(u"bridge signals already deactivated")
|
||||
log.warning("bridge signals already deactivated")
|
||||
if self.signals_handler:
|
||||
self.signals_paused.extend(self.signals_handler)
|
||||
else:
|
||||
self.signals_paused = self.signals_handlers
|
||||
self.signals_handlers = []
|
||||
log.debug(u"bridge signals have been deactivated")
|
||||
log.debug("bridge signals have been deactivated")
|
||||
|
||||
def _bridgeReactivateSignals(self):
|
||||
try:
|
||||
self.signals_handlers = self.signals_paused
|
||||
except AttributeError:
|
||||
log.debug(u"signals were already activated")
|
||||
log.debug("signals were already activated")
|
||||
else:
|
||||
del self.signals_paused
|
||||
log.debug(u"bridge signals have been reactivated")
|
||||
log.debug("bridge signals have been reactivated")
|
||||
|
||||
##METHODS_PART##
|
||||
|
||||
|
|
@ -102,14 +102,14 @@ class Bridge(object):
|
|||
|
||||
def remote_initBridge(self, signals_handler):
|
||||
self.signals_handlers.append(signals_handler)
|
||||
log.info(u"registered signal handler")
|
||||
log.info("registered signal handler")
|
||||
|
||||
def register_method(self, name, callback):
|
||||
log.debug("registering PB bridge method [%s]" % name)
|
||||
setattr(self.root, "remote_" + name, callback)
|
||||
# self.root.register_method(name, callback)
|
||||
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async=False, doc={}):
|
||||
def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
|
||||
"""Dynamically add a method to PB Bridge"""
|
||||
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
|
||||
log.debug("Adding method {name} to PB bridge".format(name=name))
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT communication bridge
|
||||
|
|
@ -28,7 +28,7 @@ from twisted.internet import reactor
|
|||
class SignalsHandler(pb.Referenceable):
|
||||
def __getattr__(self, name):
|
||||
if name.startswith("remote_"):
|
||||
log.debug(u"calling an unregistered signal: {name}".format(name=name[7:]))
|
||||
log.debug("calling an unregistered signal: {name}".format(name=name[7:]))
|
||||
return lambda *args, **kwargs: None
|
||||
|
||||
else:
|
||||
|
|
@ -43,7 +43,7 @@ class SignalsHandler(pb.Referenceable):
|
|||
pass
|
||||
else:
|
||||
raise exceptions.InternalError(
|
||||
u"{name} signal handler has been registered twice".format(
|
||||
"{name} signal handler has been registered twice".format(
|
||||
name=method_name
|
||||
)
|
||||
)
|
||||
|
|
@ -99,7 +99,7 @@ class Bridge(object):
|
|||
d.addErrback(errback)
|
||||
|
||||
def _initBridgeEb(self, failure):
|
||||
log.error(u"Can't init bridge: {msg}".format(msg=failure))
|
||||
log.error("Can't init bridge: {msg}".format(msg=failure))
|
||||
|
||||
def _set_root(self, root):
|
||||
"""set remote root object
|
||||
|
|
@ -112,7 +112,7 @@ class Bridge(object):
|
|||
return d
|
||||
|
||||
def _generic_errback(self, failure):
|
||||
log.error(u"bridge failure: {}".format(failure))
|
||||
log.error("bridge failure: {}".format(failure))
|
||||
|
||||
def bridgeConnect(self, callback, errback):
|
||||
factory = pb.PBClientFactory()
|
||||
|
|
|
|||
Loading…
Reference in a new issue