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
1 changed files with 6336 additions and 6398 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# SAT plugin for Pubsub Hooks
|
||||
|
|
@ -43,17 +43,17 @@ PLUGIN_INFO = {
|
|||
}
|
||||
|
||||
# python module
|
||||
HOOK_TYPE_PYTHON = u"python"
|
||||
HOOK_TYPE_PYTHON = "python"
|
||||
# python file path
|
||||
HOOK_TYPE_PYTHON_FILE = u"python_file"
|
||||
HOOK_TYPE_PYTHON_FILE = "python_file"
|
||||
# python code directly
|
||||
HOOK_TYPE_PYTHON_CODE = u"python_code"
|
||||
HOOK_TYPE_PYTHON_CODE = "python_code"
|
||||
HOOK_TYPES = (HOOK_TYPE_PYTHON, HOOK_TYPE_PYTHON_FILE, HOOK_TYPE_PYTHON_CODE)
|
||||
|
||||
|
||||
class PubsubHook(object):
|
||||
def __init__(self, host):
|
||||
log.info(_(u"PubSub Hook initialization"))
|
||||
log.info(_("PubSub Hook initialization"))
|
||||
self.host = host
|
||||
self.node_hooks = {} # keep track of the number of hooks per node (for all profiles)
|
||||
host.bridge.addMethod(
|
||||
|
|
@ -90,7 +90,7 @@ class PubsubHook(object):
|
|||
|
||||
def _installNodeManager(self, client, node):
|
||||
if node in self.node_hooks:
|
||||
log.debug(_(u"node manager already set for {node}").format(node=node))
|
||||
log.debug(_("node manager already set for {node}").format(node=node))
|
||||
self.node_hooks[node] += 1
|
||||
else:
|
||||
# first hook on this node
|
||||
|
|
@ -98,29 +98,29 @@ class PubsubHook(object):
|
|||
node, items_cb=self._itemsReceived
|
||||
)
|
||||
self.node_hooks[node] = 0
|
||||
log.info(_(u"node manager installed on {node}").format(node=node))
|
||||
log.info(_("node manager installed on {node}").format(node=node))
|
||||
|
||||
def _removeNodeManager(self, client, node):
|
||||
try:
|
||||
self.node_hooks[node] -= 1
|
||||
except KeyError:
|
||||
log.error(_(u"trying to remove a {node} without hook").format(node=node))
|
||||
log.error(_("trying to remove a {node} without hook").format(node=node))
|
||||
else:
|
||||
if self.node_hooks[node] == 0:
|
||||
del self.node_hooks[node]
|
||||
self.host.plugins["XEP-0060"].removeManagedNode(node, self._itemsReceived)
|
||||
log.debug(_(u"hook removed"))
|
||||
log.debug(_("hook removed"))
|
||||
else:
|
||||
log.debug(_(u"node still needed for an other hook"))
|
||||
log.debug(_("node still needed for an other hook"))
|
||||
|
||||
def installHook(self, client, service, node, hook_type, hook_arg, persistent):
|
||||
if hook_type not in HOOK_TYPES:
|
||||
raise exceptions.DataError(
|
||||
_(u"{hook_type} is not handled").format(hook_type=hook_type)
|
||||
_("{hook_type} is not handled").format(hook_type=hook_type)
|
||||
)
|
||||
if hook_type != HOOK_TYPE_PYTHON_FILE:
|
||||
raise NotImplementedError(
|
||||
_(u"{hook_type} hook type not implemented yet").format(
|
||||
_("{hook_type} hook type not implemented yet").format(
|
||||
hook_type=hook_type
|
||||
)
|
||||
)
|
||||
|
|
@ -136,8 +136,8 @@ class PubsubHook(object):
|
|||
hooks_list.append(hook_data)
|
||||
|
||||
log.info(
|
||||
_(u"{persistent} hook installed on {node} for {profile}").format(
|
||||
persistent=_(u"persistent") if persistent else _(u"temporary"),
|
||||
_("{persistent} hook installed on {node} for {profile}").format(
|
||||
persistent=_("persistent") if persistent else _("temporary"),
|
||||
node=node,
|
||||
profile=client.profile,
|
||||
)
|
||||
|
|
@ -160,18 +160,18 @@ class PubsubHook(object):
|
|||
try:
|
||||
if hook_type == HOOK_TYPE_PYTHON_FILE:
|
||||
hook_globals = {}
|
||||
execfile(hook_data["arg"], hook_globals)
|
||||
exec(compile(open(hook_data["arg"], "rb").read(), hook_data["arg"], 'exec'), hook_globals)
|
||||
callback = hook_globals["hook"]
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
_(u"{hook_type} hook type not implemented yet").format(
|
||||
_("{hook_type} hook type not implemented yet").format(
|
||||
hook_type=hook_type
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
log.warning(
|
||||
_(
|
||||
u"Can't load Pubsub hook at node {node}, it will be removed: {reason}"
|
||||
"Can't load Pubsub hook at node {node}, it will be removed: {reason}"
|
||||
).format(node=node, reason=e)
|
||||
)
|
||||
hooks_list.remove(hook_data)
|
||||
|
|
@ -183,7 +183,7 @@ class PubsubHook(object):
|
|||
except Exception as e:
|
||||
log.warning(
|
||||
_(
|
||||
u"Error while running Pubsub hook for node {node}: {msg}"
|
||||
"Error while running Pubsub hook for node {node}: {msg}"
|
||||
).format(node=node, msg=e)
|
||||
)
|
||||
|
||||
|
|
@ -193,9 +193,9 @@ class PubsubHook(object):
|
|||
return self.addHook(
|
||||
client,
|
||||
service,
|
||||
unicode(node),
|
||||
unicode(hook_type),
|
||||
unicode(hook_arg),
|
||||
str(node),
|
||||
str(hook_type),
|
||||
str(hook_arg),
|
||||
persistent,
|
||||
)
|
||||
|
||||
|
|
@ -242,11 +242,11 @@ class PubsubHook(object):
|
|||
if node in hooks:
|
||||
for hook_data in hooks[node]:
|
||||
if (
|
||||
service != hook_data[u"service"]
|
||||
service != hook_data["service"]
|
||||
or hook_type is not None
|
||||
and hook_type != hook_data[u"type"]
|
||||
and hook_type != hook_data["type"]
|
||||
or hook_arg is not None
|
||||
and hook_arg != hook_data[u"arg"]
|
||||
and hook_arg != hook_data["arg"]
|
||||
):
|
||||
continue
|
||||
hooks[node].remove(hook_data)
|
||||
|
|
@ -263,8 +263,8 @@ class PubsubHook(object):
|
|||
def _listHooks(self, profile):
|
||||
hooks_list = self.listHooks(self.host.getClient(profile))
|
||||
for hook in hooks_list:
|
||||
hook[u"service"] = hook[u"service"].full()
|
||||
hook[u"persistent"] = C.boolConst(hook[u"persistent"])
|
||||
hook["service"] = hook["service"].full()
|
||||
hook["persistent"] = C.boolConst(hook["persistent"])
|
||||
return hooks_list
|
||||
|
||||
def listHooks(self, client):
|
||||
|
|
@ -272,15 +272,15 @@ class PubsubHook(object):
|
|||
hooks_list = []
|
||||
for hooks in (client._hooks, client._hooks_temporary):
|
||||
persistent = hooks is client._hooks
|
||||
for node, hooks_data in hooks.iteritems():
|
||||
for node, hooks_data in hooks.items():
|
||||
for hook_data in hooks_data:
|
||||
hooks_list.append(
|
||||
{
|
||||
u"service": hook_data[u"service"],
|
||||
u"node": node,
|
||||
u"type": hook_data[u"type"],
|
||||
u"arg": hook_data[u"arg"],
|
||||
u"persistent": persistent,
|
||||
"service": hook_data["service"],
|
||||
"node": node,
|
||||
"type": hook_data["type"],
|
||||
"arg": hook_data["arg"],
|
||||
"persistent": persistent,
|
||||
}
|
||||
)
|
||||
return hooks_list
|
||||
|
|
|
|||
Loading…
Reference in a new issue