summaryrefslogtreecommitdiff
path: root/examples/http_upload.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/http_upload.py')
-rwxr-xr-xexamples/http_upload.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/examples/http_upload.py b/examples/http_upload.py
index e34b7b01..268a22dc 100755
--- a/examples/http_upload.py
+++ b/examples/http_upload.py
@@ -14,7 +14,6 @@ from getpass import getpass
from argparse import ArgumentParser
import slixmpp
-from slixmpp import asyncio
log = logging.getLogger(__name__)
@@ -25,18 +24,21 @@ class HttpUpload(slixmpp.ClientXMPP):
A basic client asking an entity if they confirm the access to an HTTP URL.
"""
- def __init__(self, jid, password, recipient, filename):
+ def __init__(self, jid, password, recipient, filename, domain=None):
slixmpp.ClientXMPP.__init__(self, jid, password)
self.recipient = recipient
self.filename = filename
+ self.domain = domain
self.add_event_handler("session_start", self.start)
- @asyncio.coroutine
- def start(self, event):
+ async def start(self, event):
log.info('Uploading file %s...', self.filename)
- url = yield from 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, domain=self.domain, timeout=10, timeout_callback=timeout_callback)
log.info('Upload success!')
log.info('Sending file to %s', self.recipient)
@@ -70,6 +72,8 @@ if __name__ == '__main__':
help="Recipient JID")
parser.add_argument("-f", "--file", required=True,
help="File to send")
+ parser.add_argument("--domain",
+ help="Domain to use for HTTP File Upload (leave out for your own server’s)")
args = parser.parse_args()
@@ -82,7 +86,7 @@ if __name__ == '__main__':
if args.password is None:
args.password = getpass("Password: ")
- xmpp = HttpUpload(args.jid, args.password, args.recipient, args.file)
+ xmpp = HttpUpload(args.jid, args.password, args.recipient, args.file, args.domain)
xmpp.register_plugin('xep_0071')
xmpp.register_plugin('xep_0128')
xmpp.register_plugin('xep_0363')