fixing uncaught async exceptions due to missing await

fixes uncaught exceptions in the event loop.
passing timeout and timeout_callback through.
This commit is contained in:
Florian Klien 2018-10-27 21:38:50 +02:00 committed by Emmanuel Gil Peyrot
parent 897610d819
commit d4d542b741
2 changed files with 9 additions and 5 deletions

View file

@ -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)

View file

@ -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']