comparison sat/plugins/plugin_xep_0234.py @ 3434:c84c54c6b046

plugin XEP-0234: make `fileJingleRequest` async to fix call of `initiate`
author Goffi <goffi@goffi.org>
date Fri, 04 Dec 2020 12:32:05 +0100
parents 26a0af6e32c1
children be6d91572633
comparison
equal deleted inserted replaced
3433:63d20854df3a 3434:c84c54c6b046
349 349
350 def _fileJingleRequest( 350 def _fileJingleRequest(
351 self, peer_jid, filepath, name="", file_hash="", hash_algo="", extra=None, 351 self, peer_jid, filepath, name="", file_hash="", hash_algo="", extra=None,
352 profile=C.PROF_KEY_NONE): 352 profile=C.PROF_KEY_NONE):
353 client = self.host.getClient(profile) 353 client = self.host.getClient(profile)
354 return self.fileJingleRequest( 354 return defer.ensureDeferred(self.fileJingleRequest(
355 client, 355 client,
356 jid.JID(peer_jid), 356 jid.JID(peer_jid),
357 filepath, 357 filepath,
358 name or None, 358 name or None,
359 file_hash or None, 359 file_hash or None,
360 hash_algo or None, 360 hash_algo or None,
361 extra or None, 361 extra or None,
362 ) 362 ))
363 363
364 @defer.inlineCallbacks 364 async def fileJingleRequest(
365 def fileJingleRequest(
366 self, client, peer_jid, filepath, name=None, file_hash=None, hash_algo=None, 365 self, client, peer_jid, filepath, name=None, file_hash=None, hash_algo=None,
367 extra=None): 366 extra=None):
368 """Request a file using jingle file transfer 367 """Request a file using jingle file transfer
369 368
370 @param peer_jid(jid.JID): destinee jid 369 @param peer_jid(jid.JID): destinee jid
382 extra["file_hash"] = file_hash 381 extra["file_hash"] = file_hash
383 extra["hash_algo"] = hash_algo 382 extra["hash_algo"] = hash_algo
384 else: 383 else:
385 if hash_algo is not None: 384 if hash_algo is not None:
386 raise ValueError(_("file_hash must be set if hash_algo is set")) 385 raise ValueError(_("file_hash must be set if hash_algo is set"))
387 yield self._j.initiate( 386 await self._j.initiate(
388 client, 387 client,
389 peer_jid, 388 peer_jid,
390 [ 389 [
391 { 390 {
392 "app_ns": NS_JINGLE_FT, 391 "app_ns": NS_JINGLE_FT,
398 "progress_id_d": progress_id_d, 397 "progress_id_d": progress_id_d,
399 }, 398 },
400 } 399 }
401 ], 400 ],
402 ) 401 )
403 progress_id = yield progress_id_d 402 return await progress_id_d
404 defer.returnValue(progress_id)
405 403
406 # jingle callbacks 404 # jingle callbacks
407 405
408 def jingleDescriptionElt( 406 def jingleDescriptionElt(
409 self, client, session, content_name, filepath, name, extra, progress_id_d 407 self, client, session, content_name, filepath, name, extra, progress_id_d