diff options
author | Florian Klien <flowolf@klienux.org> | 2018-10-27 21:38:50 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-10-27 22:51:04 +0200 |
commit | d4d542b7411c9f2d099d17bae0acfe327318442c (patch) | |
tree | bba4b9b86ce0237d3f7f50cc7283b5694a85c671 | |
parent | 897610d819425a84a232e26f239482b66a09dd8b (diff) | |
download | slixmpp-d4d542b7411c9f2d099d17bae0acfe327318442c.tar.gz slixmpp-d4d542b7411c9f2d099d17bae0acfe327318442c.tar.bz2 slixmpp-d4d542b7411c9f2d099d17bae0acfe327318442c.tar.xz slixmpp-d4d542b7411c9f2d099d17bae0acfe327318442c.zip |
fixing uncaught async exceptions due to missing await
fixes uncaught exceptions in the event loop.
passing timeout and timeout_callback through.
-rwxr-xr-x | examples/http_upload.py | 5 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0363/http_upload.py | 9 |
2 files changed, 9 insertions, 5 deletions
diff --git a/examples/http_upload.py b/examples/http_upload.py index 2e5476c0..f2c292a2 100755 --- a/examples/http_upload.py +++ b/examples/http_upload.py @@ -34,7 +34,10 @@ class HttpUpload(slixmpp.ClientXMPP): async def start(self, event): log.info('Uploading file %s...', self.filename) - url = await self['xep_0363'].upload_file(self.filename) + def timeout_callback(arg): + raise TimeoutError("could not send message in time") + url = await self['xep_0363'].upload_file( + self.filename, timeout=10, timeout_callback=timeout_callback) log.info('Upload success!') log.info('Sending file to %s', self.recipient) diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py index 65894975..50cdc5a9 100644 --- a/slixmpp/plugins/xep_0363/http_upload.py +++ b/slixmpp/plugins/xep_0363/http_upload.py @@ -6,7 +6,6 @@ See the file LICENSE for copying permission. """ -import asyncio import logging import os.path @@ -68,8 +67,9 @@ class XEP_0363(BasePlugin): def _handle_request(self, iq): self.xmpp.event('http_upload_request', iq) - async def find_upload_service(self, timeout=None): - results = await self.xmpp['xep_0030'].get_info_from_domain() + async def find_upload_service(self, timeout=None, timeout_callback=None): + results = await self.xmpp['xep_0030'].get_info_from_domain( + timeout=timeout, timeout_callback=timeout_callback) for info in results: for identity in info['disco_info']['identities']: @@ -94,7 +94,8 @@ class XEP_0363(BasePlugin): callback=None, timeout_callback=None): ''' Helper function which does all of the uploading process. ''' if self.upload_service is None: - info_iq = await self.find_upload_service(timeout=timeout) + info_iq = await self.find_upload_service( + timeout=timeout, timeout_callback=timeout_callback) if info_iq is None: raise UploadServiceNotFound() self.upload_service = info_iq['from'] |