summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/conf.py13
-rwxr-xr-xexamples/http_upload.py12
-rw-r--r--slixmpp/plugins/xep_0030/disco.py10
-rw-r--r--slixmpp/plugins/xep_0363/http_upload.py19
4 files changed, 37 insertions, 17 deletions
diff --git a/docs/conf.py b/docs/conf.py
index 8f711a16..208c0cdf 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -12,12 +12,17 @@
# serve to show the default.
import sys, os
+import datetime
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))
+# get version automagically from source tree
+from slixmpp.version import __version__ as version
+release = ".".join(version.split(".")[0:2])
+
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
@@ -41,16 +46,18 @@ master_doc = 'index'
# General information about the project.
project = u'Slixmpp'
-copyright = u'2011, Nathan Fritz, Lance Stout'
+year = datetime.datetime.now().year
+copyright = u'{}, Nathan Fritz, Lance Stout'.format(year)
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
+# auto imported from code!
# The short X.Y version.
-version = '1.1'
+# version = '1.4'
# The full version, including alpha/beta/rc tags.
-release = '1.1'
+# release = '1.4.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/examples/http_upload.py b/examples/http_upload.py
index 2e5476c0..268a22dc 100755
--- a/examples/http_upload.py
+++ b/examples/http_upload.py
@@ -24,17 +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)
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, domain=self.domain, timeout=10, timeout_callback=timeout_callback)
log.info('Upload success!')
log.info('Sending file to %s', self.recipient)
@@ -68,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()
@@ -80,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')
diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py
index 460a9134..59b1e0cc 100644
--- a/slixmpp/plugins/xep_0030/disco.py
+++ b/slixmpp/plugins/xep_0030/disco.py
@@ -299,18 +299,18 @@ class XEP_0030(BasePlugin):
return self.api['has_identity'](jid, node, ifrom, data)
async def get_info_from_domain(self, domain=None, timeout=None,
- cached=True, callback=None, **kwargs):
+ cached=True, callback=None):
if domain is None:
domain = self.xmpp.boundjid.domain
if not cached or domain not in self.domain_infos:
infos = [self.get_info(
- domain, timeout=timeout, **kwargs)]
+ domain, timeout=timeout)]
iq_items = await self.get_items(
- domain, timeout=timeout, **kwargs)
+ domain, timeout=timeout)
items = iq_items['disco_items']['items']
infos += [
- self.get_info(item[0], timeout=timeout, **kwargs)
+ self.get_info(item[0], timeout=timeout)
for item in items]
info_futures, _ = await asyncio.wait(
infos,
@@ -319,7 +319,7 @@ class XEP_0030(BasePlugin):
)
self.domain_infos[domain] = [
- future.result() for future in info_futures]
+ future.result() for future in info_futures if not future.exception()]
results = self.domain_infos[domain]
diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py
index 65894975..2228ca8b 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,12 +67,18 @@ 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, domain=None, timeout=None):
+ results = await self.xmpp['xep_0030'].get_info_from_domain(
+ domain=domain, timeout=timeout)
+ candidates = []
for info in results:
for identity in info['disco_info']['identities']:
if identity[0] == 'store' and identity[1] == 'file':
+ candidates.append(info)
+ for info in candidates:
+ for feature in info['disco_info']['features']:
+ if feature == Request.namespace:
return info
def request_slot(self, jid, filename, size, content_type=None, ifrom=None,
@@ -90,11 +95,12 @@ class XEP_0363(BasePlugin):
timeout_callback=timeout_callback)
async def upload_file(self, filename, size=None, content_type=None, *,
- input_file=None, ifrom=None, timeout=None,
+ input_file=None, ifrom=None, domain=None, timeout=None,
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(
+ domain=domain, timeout=timeout)
if info_iq is None:
raise UploadServiceNotFound()
self.upload_service = info_iq['from']
@@ -125,7 +131,8 @@ class XEP_0363(BasePlugin):
basename = os.path.basename(filename)
slot_iq = await self.request_slot(self.upload_service, basename, size,
- content_type, ifrom, timeout)
+ content_type, ifrom, timeout,
+ timeout_callback=timeout_callback)
slot = slot_iq['http_upload_slot']
headers = {