summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xexamples/http_upload.py5
-rw-r--r--slixmpp/plugins/xep_0363/http_upload.py9
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']