merge bookmark @
This commit is contained in:
commit
50d7cb2a51
8 changed files with 277 additions and 150 deletions
|
|
@ -140,7 +140,21 @@ class Bridge:
|
|||
kwargs['reply_handler'] = _callback
|
||||
kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
|
||||
|
||||
return method(*args, **kwargs)
|
||||
try:
|
||||
return method(*args, **kwargs)
|
||||
except ValueError as e:
|
||||
if e.args[0].startswith("Unable to guess signature"):
|
||||
# XXX: if frontend is started too soon after backend, the
|
||||
# inspection misses methods (notably plugin dynamically added
|
||||
# methods). The following hack works around that by redoing the
|
||||
# cache of introspected methods signatures.
|
||||
log.debug("using hack to work around inspection issue")
|
||||
proxy = self.db_plugin_iface.proxy_object
|
||||
IN_PROGRESS = proxy.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS
|
||||
proxy._introspect_state = IN_PROGRESS
|
||||
proxy._Introspect()
|
||||
return self.db_plugin_iface.get_dbus_method(name)(*args, **kwargs)
|
||||
raise e
|
||||
|
||||
return getPluginMethod
|
||||
|
||||
|
|
@ -167,13 +181,32 @@ class AIOBridge(Bridge):
|
|||
fut.set_result, ret)
|
||||
error_handler = lambda err: loop.call_soon_threadsafe(
|
||||
fut.set_exception, dbus_to_bridge_exception(err))
|
||||
method(
|
||||
*args,
|
||||
**kwargs,
|
||||
timeout=const_TIMEOUT,
|
||||
reply_handler=reply_handler,
|
||||
error_handler=error_handler
|
||||
)
|
||||
try:
|
||||
method(
|
||||
*args,
|
||||
**kwargs,
|
||||
timeout=const_TIMEOUT,
|
||||
reply_handler=reply_handler,
|
||||
error_handler=error_handler
|
||||
)
|
||||
except ValueError as e:
|
||||
if e.args[0].startswith("Unable to guess signature"):
|
||||
# same hack as for Bridge.__getattribute__
|
||||
log.warning("using hack to work around inspection issue")
|
||||
proxy = self.db_plugin_iface.proxy_object
|
||||
IN_PROGRESS = proxy.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS
|
||||
proxy._introspect_state = IN_PROGRESS
|
||||
proxy._Introspect()
|
||||
self.db_plugin_iface.get_dbus_method(name)(
|
||||
*args,
|
||||
**kwargs,
|
||||
timeout=const_TIMEOUT,
|
||||
reply_handler=reply_handler,
|
||||
error_handler=error_handler
|
||||
)
|
||||
|
||||
else:
|
||||
raise e
|
||||
return fut
|
||||
|
||||
return getPluginMethod
|
||||
|
|
|
|||
|
|
@ -228,11 +228,7 @@ class SAT(service.Service):
|
|||
ui_contact_list.ContactList(self)
|
||||
ui_profile_manager.ProfileManager(self)
|
||||
except Exception as e:
|
||||
log.error(
|
||||
_("Could not initialize backend: {reason}").format(
|
||||
reason=str(e).decode("utf-8", "ignore")
|
||||
)
|
||||
)
|
||||
log.error(f"Could not initialize backend: {e}")
|
||||
sys.exit(1)
|
||||
self._addBaseMenus()
|
||||
|
||||
|
|
@ -344,6 +340,12 @@ class SAT(service.Service):
|
|||
plugin_modes = plugin_info["modes"] = set(
|
||||
plugin_info.setdefault("modes", C.PLUG_MODE_DEFAULT)
|
||||
)
|
||||
if not plugin_modes.intersection(C.PLUG_MODE_BOTH):
|
||||
log.error(
|
||||
f"Can't import plugin at {plugin_path}, invalid {C.PI_MODES!r} "
|
||||
f"value: {plugin_modes!r}"
|
||||
)
|
||||
continue
|
||||
|
||||
# if the plugin is an entry point, it must work in component mode
|
||||
if plugin_info["type"] == C.PLUG_TYPE_ENTRY_POINT:
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ class LazyPersistentBinaryDict(PersistentBinaryDict):
|
|||
))
|
||||
|
||||
def __repr__(self):
|
||||
raise NotImplementedError
|
||||
return self.__str__()
|
||||
|
||||
def __str__(self):
|
||||
return "LazyPersistentBinaryDict (namespace: {})".format(self.namespace)
|
||||
|
|
|
|||
|
|
@ -309,9 +309,11 @@ class AndroidPlugin(object):
|
|||
# "XXX has no attribute 'invoke'" error (looks like the same issue as
|
||||
# https://github.com/kivy/pyjnius/issues/59)
|
||||
self.br = BroadcastReceiver(
|
||||
callback=lambda *args, **kwargs: reactor.callLater(0,
|
||||
self.onConnectivityChange),
|
||||
actions=["android.net.conn.CONNECTIVITY_CHANGE"])
|
||||
callback=lambda *args, **kwargs: reactor.callFromThread(
|
||||
self.onConnectivityChange
|
||||
),
|
||||
actions=["android.net.conn.CONNECTIVITY_CHANGE"]
|
||||
)
|
||||
self.br.start()
|
||||
|
||||
@property
|
||||
|
|
|
|||
|
|
@ -237,8 +237,8 @@ class FilePlugin:
|
|||
data_cb=file_data.get("data_cb"),
|
||||
)
|
||||
|
||||
def _gotConfirmation(
|
||||
self, data, client, peer_jid, transfer_data, file_data, stream_object
|
||||
async def _gotConfirmation(
|
||||
self, client, data, peer_jid, transfer_data, file_data, stream_object
|
||||
):
|
||||
"""Called when the permission and dest path have been received
|
||||
|
||||
|
|
@ -258,19 +258,7 @@ class FilePlugin:
|
|||
|
||||
# we manage case where file already exists
|
||||
if os.path.exists(file_path):
|
||||
|
||||
def check_overwrite(overwrite):
|
||||
if overwrite:
|
||||
self.openFileWrite(
|
||||
client, file_path, transfer_data, file_data, stream_object
|
||||
)
|
||||
return True
|
||||
else:
|
||||
return defer.ensureDeferred(
|
||||
self.getDestDir(client, peer_jid, transfer_data, file_data)
|
||||
)
|
||||
|
||||
exists_d = xml_tools.deferConfirm(
|
||||
overwrite = await xml_tools.deferConfirm(
|
||||
self.host,
|
||||
_(CONFIRM_OVERWRITE).format(file_path),
|
||||
_(CONFIRM_OVERWRITE_TITLE),
|
||||
|
|
@ -282,8 +270,9 @@ class FilePlugin:
|
|||
security_limit=SECURITY_LIMIT,
|
||||
profile=client.profile,
|
||||
)
|
||||
exists_d.addCallback(check_overwrite)
|
||||
return exists_d
|
||||
|
||||
if not overwrite:
|
||||
return await self.getDestDir(client, peer_jid, transfer_data, file_data)
|
||||
|
||||
self.openFileWrite(client, file_path, transfer_data, file_data, stream_object)
|
||||
return True
|
||||
|
|
@ -315,7 +304,7 @@ class FilePlugin:
|
|||
"size_human" will also be added with human readable file size
|
||||
@param stream_object(bool): if True, a stream_object will be used instead of file_obj
|
||||
a stream.FileStreamObject will be used
|
||||
return (defer.Deferred): True if transfer is accepted
|
||||
return: True if transfer is accepted
|
||||
"""
|
||||
cont, ret_value = await self.host.trigger.asyncReturnPoint(
|
||||
"FILE_getDestDir", client, peer_jid, transfer_data, file_data, stream_object
|
||||
|
|
@ -327,7 +316,7 @@ class FilePlugin:
|
|||
assert PROGRESS_ID_KEY in file_data
|
||||
# human readable size
|
||||
file_data["size_human"] = common_utils.getHumanSize(file_data["size"])
|
||||
d = xml_tools.deferDialog(
|
||||
resp_data = await xml_tools.deferDialog(
|
||||
self.host,
|
||||
_(CONFIRM).format(peer=peer_jid.full(), **file_data),
|
||||
_(CONFIRM_TITLE),
|
||||
|
|
@ -341,12 +330,13 @@ class FilePlugin:
|
|||
security_limit=SECURITY_LIMIT,
|
||||
profile=client.profile,
|
||||
)
|
||||
d.addCallback(
|
||||
self._gotConfirmation,
|
||||
|
||||
accepted = await self._gotConfirmation(
|
||||
client,
|
||||
resp_data,
|
||||
peer_jid,
|
||||
transfer_data,
|
||||
file_data,
|
||||
stream_object,
|
||||
)
|
||||
return d
|
||||
return accepted
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
import time
|
||||
import dateutil
|
||||
import calendar
|
||||
import urllib.parse
|
||||
from secrets import token_urlsafe
|
||||
from typing import Optional
|
||||
from functools import partial
|
||||
|
|
@ -1032,13 +1031,12 @@ class XEP_0277(object):
|
|||
will return(JID(u'sat-pubsub.example.net'), 'urn:xmpp:comments:_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:somebody@example.net')
|
||||
@return (tuple[jid.JID, unicode]): service and node
|
||||
"""
|
||||
parsed_url = urllib.parse.urlparse(node_url, "xmpp")
|
||||
service = jid.JID(parsed_url.path)
|
||||
parsed_queries = urllib.parse.parse_qs(parsed_url.query)
|
||||
node = parsed_queries.get("node", [""])[0]
|
||||
|
||||
if not node:
|
||||
raise exceptions.DataError("Invalid comments link")
|
||||
try:
|
||||
parsed_url = xmpp_uri.parseXMPPUri(node_url)
|
||||
service = jid.JID(parsed_url["path"])
|
||||
node = parsed_url["node"]
|
||||
except Exception as e:
|
||||
raise exceptions.DataError(f"Invalid comments link: {e}")
|
||||
|
||||
return (service, node)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
from zope.interface import implementer
|
||||
from twisted.internet import defer
|
||||
from twisted.internet import reactor
|
||||
from twisted.words.protocols.jabber import xmlstream, jid
|
||||
from twisted.words.protocols.jabber import xmlstream, jid, error
|
||||
from twisted.words.xish import domish
|
||||
from wokkel import disco, iwokkel
|
||||
from sat.core.i18n import _, D_
|
||||
|
|
@ -38,7 +38,7 @@ PLUGIN_INFO = {
|
|||
C.PI_NAME: "Jingle Message Initiation",
|
||||
C.PI_IMPORT_NAME: "XEP-0353",
|
||||
C.PI_TYPE: "XEP",
|
||||
C.PI_MODES: C.PLUG_MODE_CLIENT,
|
||||
C.PI_MODES: [C.PLUG_MODE_CLIENT],
|
||||
C.PI_PROTOCOLS: ["XEP-0353"],
|
||||
C.PI_DEPENDENCIES: ["XEP-0166"],
|
||||
C.PI_MAIN: "XEP_0353",
|
||||
|
|
@ -85,8 +85,15 @@ class XEP_0353:
|
|||
if peer_jid.resource:
|
||||
return True
|
||||
|
||||
infos = await self.host.memory.disco.getInfos(client, peer_jid)
|
||||
categories = {c for c, __ in infos.identities}
|
||||
try:
|
||||
infos = await self.host.memory.disco.getInfos(client, peer_jid)
|
||||
except error.StanzaError as e:
|
||||
if e.condition == "service-unavailable":
|
||||
categories = {}
|
||||
else:
|
||||
raise e
|
||||
else:
|
||||
categories = {c for c, __ in infos.identities}
|
||||
if "component" in categories:
|
||||
# we don't use message initiation with components
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
""" XMPP uri parsing tools """
|
||||
|
||||
import sys
|
||||
import urllib.parse
|
||||
import urllib.request, urllib.parse, urllib.error
|
||||
|
||||
|
|
@ -53,7 +54,13 @@ def parseXMPPUri(uri):
|
|||
if query_end == -1 or "=" in query_type:
|
||||
raise ValueError("no query type, invalid XMPP URI")
|
||||
|
||||
pairs = urllib.parse.parse_qs(uri_split.geturl())
|
||||
if sys.version_info >= (3, 9):
|
||||
# parse_qs behaviour has been modified in Python 3.9, ";" is not understood as a
|
||||
# parameter separator anymore but the "separator" argument has been added to
|
||||
# change it.
|
||||
pairs = urllib.parse.parse_qs(uri_split.geturl(), separator=";")
|
||||
else:
|
||||
pairs = urllib.parse.parse_qs(uri_split.geturl())
|
||||
for k, v in list(pairs.items()):
|
||||
if len(v) != 1:
|
||||
raise NotImplementedError("multiple values not managed")
|
||||
|
|
|
|||
Loading…
Reference in a new issue