summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2021-02-24 20:47:45 +0100
committermathieui <mathieui@mathieui.net>2021-02-24 20:47:45 +0100
commitb8b57960f1ba2a5468b0ed76e6442f89fe98e0b4 (patch)
tree526c48d9e28e3aa0393c1ed0438eb26384a9a517
parent73814605565df02ae534b5d0b57868b6cafa58f7 (diff)
parent5764ef7ff73ba76f08936ffa3cf4cdba0d09c33e (diff)
downloadslixmpp-b8b57960f1ba2a5468b0ed76e6442f89fe98e0b4.tar.gz
slixmpp-b8b57960f1ba2a5468b0ed76e6442f89fe98e0b4.tar.bz2
slixmpp-b8b57960f1ba2a5468b0ed76e6442f89fe98e0b4.tar.xz
slixmpp-b8b57960f1ba2a5468b0ed76e6442f89fe98e0b4.zip
Merge branch 'httpupload-add-oob' into 'master'
examples: add oob to httpupload example See merge request poezio/slixmpp!140
-rwxr-xr-xexamples/http_upload.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/examples/http_upload.py b/examples/http_upload.py
index f74b5b10..a926fd47 100755
--- a/examples/http_upload.py
+++ b/examples/http_upload.py
@@ -10,6 +10,7 @@ from getpass import getpass
from argparse import ArgumentParser
import slixmpp
+from slixmpp.exceptions import IqTimeout
log = logging.getLogger(__name__)
@@ -31,15 +32,22 @@ class HttpUpload(slixmpp.ClientXMPP):
async def start(self, event):
log.info('Uploading file %s...', 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)
+ try:
+ url = await self['xep_0363'].upload_file(
+ self.filename, domain=self.domain, timeout=10
+ )
+ except IqTimeout:
+ raise TimeoutError('Could not send message in time')
log.info('Upload success!')
log.info('Sending file to %s', self.recipient)
- html = '<body xmlns="http://www.w3.org/1999/xhtml"><a href="%s">%s</a></body>' % (url, url)
- self.send_message(self.recipient, url, mhtml=html)
+ html = (
+ f'<body xmlns="http://www.w3.org/1999/xhtml">'
+ f'<a href="{url}">{url}</a></body>'
+ )
+ message = self.make_message(mto=self.recipient, mbody=url, mhtml=html)
+ message['oob']['url'] = url
+ message.send()
self.disconnect()
@@ -83,6 +91,7 @@ if __name__ == '__main__':
args.password = getpass("Password: ")
xmpp = HttpUpload(args.jid, args.password, args.recipient, args.file, args.domain)
+ xmpp.register_plugin('xep_0066')
xmpp.register_plugin('xep_0071')
xmpp.register_plugin('xep_0128')
xmpp.register_plugin('xep_0363')