jp: jp asyncio port:

/!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\

This patch implements the port of jp to asyncio, so it is now correctly using the bridge
asynchronously, and it can be used with bridges like `pb`. This also simplify the code,
notably for things which were previously implemented with many callbacks (like pagination
with RSM).

During the process, some behaviours have been modified/fixed, in jp and backends, check
diff for details.
This commit is contained in:
Goffi 2019-09-25 08:56:41 +02:00
commit 76aadbb3fb

View file

@ -64,7 +64,7 @@ class ImportPlugin(object):
@param name(unicode): import handler name
"""
assert name == name.lower().strip()
log.info(_("initializing {name} import handler").format(name=name))
log.info(_(f"initializing {name} import handler"))
import_handler.name = name
import_handler.register = partial(self.register, import_handler)
import_handler.unregister = partial(self.unregister, import_handler)
@ -139,16 +139,8 @@ class ImportPlugin(object):
else:
return importer.short_desc, importer.long_desc
def _doImport(
self,
import_handler,
name,
location,
options,
pubsub_service="",
pubsub_node="",
profile=C.PROF_KEY_NONE,
):
def _doImport(self, import_handler, name, location, options, pubsub_service="",
pubsub_node="", profile=C.PROF_KEY_NONE):
client = self.host.getClient(profile)
options = {key: str(value) for key, value in options.items()}
for option in import_handler.BOOL_OPTIONS:
@ -159,9 +151,11 @@ class ImportPlugin(object):
for option in import_handler.JSON_OPTIONS:
try:
options[option] = json.loads(options[option])
except KeyError:
pass
except ValueError:
raise exceptions.DataError(
_("invalid json option: {name}").format(name=option)
_(f"invalid json option: {option}")
)
pubsub_service = jid.JID(pubsub_service) if pubsub_service else None
return self.doImport(
@ -175,16 +169,8 @@ class ImportPlugin(object):
)
@defer.inlineCallbacks
def doImport(
self,
client,
import_handler,
name,
location,
options=None,
pubsub_service=None,
pubsub_node=None,
):
def doImport(self, client, import_handler, name, location, options=None,
pubsub_service=None, pubsub_node=None,):
"""Import data
@param import_handler(object): instance of the import handler
@ -193,7 +179,8 @@ class ImportPlugin(object):
can be an url, a file path, or anything which make sense
check importer description for more details
@param options(dict, None): extra options.
@param pubsub_service(jid.JID, None): jid of the PubSub service where data must be imported
@param pubsub_service(jid.JID, None): jid of the PubSub service where data must be
imported.
None to use profile's server
@param pubsub_node(unicode, None): PubSub node to use
None to use importer's default node