Mercurial > libervia-backend
diff sat/plugins/plugin_xep_0234.py @ 3333:ac9342f359e9
plugin XEP-0329: download thumbnails:
- thumbnails are now downloaded directly when BoB is used, `filename` is then filled
- `utils.asDeferred` is now used for Jingle methods, so `async` coroutines can be used
- (XEP-0231): fixed `dumpData`
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 13 Aug 2020 23:46:18 +0200 |
parents | 5887fb414758 |
children | 3dc8835d96cc |
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0234.py Thu Aug 13 23:46:18 2020 +0200 +++ b/sat/plugins/plugin_xep_0234.py Thu Aug 13 23:46:18 2020 +0200 @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# SAT plugin for Jingle File Transfer (XEP-0234) +# SàT plugin for Jingle File Transfer (XEP-0234) # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) # This program is free software: you can redistribute it and/or modify @@ -181,7 +181,7 @@ file_data.update(kwargs) return self.buildFileElement(client, **file_data) - def parseFileElement( + async def parseFileElement( self, client, file_elt, file_data=None, given=False, parent_elt=None, keep_empty_range=False): """Parse a <file> element and file dictionary accordingly @@ -451,7 +451,9 @@ return desc_elt - def jingleRequestConfirmation(self, client, action, session, content_name, desc_elt): + async def jingleRequestConfirmation( + self, client, action, session, content_name, desc_elt + ): """This method request confirmation for a jingle session""" content_data = session["contents"][content_name] senders = content_data["senders"] @@ -467,21 +469,20 @@ if senders == self._j.ROLE_RESPONDER: # we send the file - return self._fileSendingRequestConf( + return await self._fileSendingRequestConf( client, session, content_data, content_name, file_data, file_elt ) else: # we receive the file - return self._fileReceivingRequestConf( + return await self._fileReceivingRequestConf( client, session, content_data, content_name, file_data, file_elt ) - @defer.inlineCallbacks - def _fileSendingRequestConf( + async def _fileSendingRequestConf( self, client, session, content_data, content_name, file_data, file_elt ): """parse file_elt, and handle file retrieving/permission checking""" - self.parseFileElement(client, file_elt, file_data) + await self.parseFileElement(client, file_elt, file_data) content_data["application_data"]["file_data"] = file_data finished_d = content_data["finished_d"] = defer.Deferred() @@ -496,22 +497,22 @@ file_elt, ) if not cont: - confirmed = yield confirmed_d + confirmed = await confirmed_d if confirmed: args = [client, session, content_name, content_data] finished_d.addCallbacks( self._finishedCb, self._finishedEb, args, None, args ) - defer.returnValue(confirmed) + return confirmed log.warning(_("File continue is not implemented yet")) - defer.returnValue(False) + return False - def _fileReceivingRequestConf( + async def _fileReceivingRequestConf( self, client, session, content_data, content_name, file_data, file_elt ): """parse file_elt, and handle user permission/file opening""" - self.parseFileElement(client, file_elt, file_data, given=True) + await self.parseFileElement(client, file_elt, file_data, given=True) try: hash_algo, file_data["given_file_hash"] = self._hash.parseHashElt(file_elt) except exceptions.NotFound: @@ -540,21 +541,18 @@ content_data["application_data"]["file_data"] = file_data # now we actualy request permission to user - def gotConfirmation(confirmed): - if confirmed: - args = [client, session, content_name, content_data] - finished_d.addCallbacks( - self._finishedCb, self._finishedEb, args, None, args - ) - return confirmed # deferred to track end of transfer finished_d = content_data["finished_d"] = defer.Deferred() - d = self._f.getDestDir( + confirmed = await self._f.getDestDir( client, session["peer_jid"], content_data, file_data, stream_object=True ) - d.addCallback(gotConfirmation) - return d + if confirmed: + args = [client, session, content_name, content_data] + finished_d.addCallbacks( + self._finishedCb, self._finishedEb, args, None, args + ) + return confirmed @defer.inlineCallbacks def jingleHandler(self, client, action, session, content_name, desc_elt):