From b881c6729b79e37aba5ab2d99c3ba0fd79bc1b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 9 Jun 2018 15:51:50 +0100 Subject: xep_0363: Remove unused parameters to find_upload_services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp/plugins/xep_0030/disco.py | 1 + slixmpp/plugins/xep_0363/http_upload.py | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index 166ad981..b1c261a9 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -6,6 +6,7 @@ See the file LICENSE for copying permission. """ +import asyncio import logging from slixmpp import Iq diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py index 0cca2d08..073b3fc0 100644 --- a/slixmpp/plugins/xep_0363/http_upload.py +++ b/slixmpp/plugins/xep_0363/http_upload.py @@ -68,8 +68,7 @@ class XEP_0363(BasePlugin): def _handle_request(self, iq): self.xmpp.event('http_upload_request', iq) - async def find_upload_service(self, ifrom=None, timeout=None, callback=None, - timeout_callback=None): + async def find_upload_service(self, timeout=None): infos = [self.xmpp['xep_0030'].get_info(self.xmpp.boundjid.domain)] iq_items = await self.xmpp['xep_0030'].get_items( self.xmpp.boundjid.domain, timeout=timeout) @@ -100,7 +99,7 @@ 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(ifrom=ifrom, timeout=timeout) + info_iq = await self.find_upload_service(timeout=timeout) if info_iq is None: raise UploadServiceNotFound() self.upload_service = info_iq['from'] -- cgit v1.2.3 From 037706552c68ec900475633af0474a7cdac29814 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 9 Jun 2018 15:55:12 +0100 Subject: Factor out fetching of identities in xep_0363 to xep_0030 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp/plugins/xep_0030/disco.py | 27 +++++++++++++++++++++++++++ slixmpp/plugins/xep_0363/http_upload.py | 14 +++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index b1c261a9..daeee879 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -124,6 +124,8 @@ class XEP_0030(BasePlugin): for op in self._disco_ops: self.api.register(getattr(self.static, op), op, default=True) + self.domain_infos = {} + def session_bind(self, jid): self.add_feature('http://jabber.org/protocol/disco#info') @@ -296,6 +298,31 @@ class XEP_0030(BasePlugin): 'cached': cached} return self.api['has_identity'](jid, node, ifrom, data) + async def find_identities(category, type_, domain=None, timeout=None): + if domain is None: + domain = self.xmpp.boundjid.domain + + if domain not in self.domain_infos: + infos = [self.xmpp['xep_0030'].get_info( + domain, timeout=timeout)] + iq_items = await self.xmpp['xep_0030'].get_items( + domain, timeout=timeout) + items = iq_items['disco_items']['items'] + infos += [ + self.xmpp['xep_0030'].get_info(item[0], timeout=timeout) + for item in items] + info_futures, _ = await asyncio.wait(infos, timeout=timeout) + + self.domain_infos[domain] = [ + future.result() for future in info_futures] + + results = [] + for info in self.domain_infos[domain]: + for identity in info['disco_info']['identities']: + if identity[0] == category and identity[1] == type_: + results.append(info) + return results + @future_wrapper def get_info(self, jid=None, node=None, local=None, cached=None, **kwargs): diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py index 073b3fc0..3c0f2b3e 100644 --- a/slixmpp/plugins/xep_0363/http_upload.py +++ b/slixmpp/plugins/xep_0363/http_upload.py @@ -69,17 +69,9 @@ class XEP_0363(BasePlugin): self.xmpp.event('http_upload_request', iq) async def find_upload_service(self, timeout=None): - infos = [self.xmpp['xep_0030'].get_info(self.xmpp.boundjid.domain)] - iq_items = await self.xmpp['xep_0030'].get_items( - self.xmpp.boundjid.domain, timeout=timeout) - items = iq_items['disco_items']['items'] - infos += [self.xmpp['xep_0030'].get_info(item[0]) for item in items] - info_futures, _ = await asyncio.wait(infos, timeout=timeout) - for future in info_futures: - info = future.result() - for identity in info['disco_info']['identities']: - if identity[0] == 'store' and identity[1] == 'file': - return info + results = await self.xmpp['xep_0030'].find_identities('store', 'file') + if results: + return results[0] def request_slot(self, jid, filename, size, content_type=None, ifrom=None, timeout=None, callback=None, timeout_callback=None): -- cgit v1.2.3 From e7872aaa29258fb5c5abdfe441f0f9fab33f307c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 30 Jun 2018 22:47:04 +0100 Subject: xep_0030: Use self directly as we're already in disco MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp/plugins/xep_0030/disco.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index daeee879..d06c5c51 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -303,13 +303,13 @@ class XEP_0030(BasePlugin): domain = self.xmpp.boundjid.domain if domain not in self.domain_infos: - infos = [self.xmpp['xep_0030'].get_info( + infos = [self.get_info( domain, timeout=timeout)] - iq_items = await self.xmpp['xep_0030'].get_items( + iq_items = await self.get_items( domain, timeout=timeout) items = iq_items['disco_items']['items'] infos += [ - self.xmpp['xep_0030'].get_info(item[0], timeout=timeout) + self.get_info(item[0], timeout=timeout) for item in items] info_futures, _ = await asyncio.wait(infos, timeout=timeout) -- cgit v1.2.3 From 9740e93aeb3a8cd1403e7f920bd8ade93c47f9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 30 Jun 2018 23:03:47 +0100 Subject: xep_0030: Pass kwargs down in find_identities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp/plugins/xep_0030/disco.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index d06c5c51..b89c7258 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -298,18 +298,19 @@ class XEP_0030(BasePlugin): 'cached': cached} return self.api['has_identity'](jid, node, ifrom, data) - async def find_identities(category, type_, domain=None, timeout=None): + async def find_identities(category, type_, domain=None, timeout=None, + **kwargs): if domain is None: domain = self.xmpp.boundjid.domain if domain not in self.domain_infos: infos = [self.get_info( - domain, timeout=timeout)] + domain, timeout=timeout, **kwargs)] iq_items = await self.get_items( - domain, timeout=timeout) + domain, timeout=timeout, **kwargs) items = iq_items['disco_items']['items'] infos += [ - self.get_info(item[0], timeout=timeout) + self.get_info(item[0], timeout=timeout, **kwargs) for item in items] info_futures, _ = await asyncio.wait(infos, timeout=timeout) -- cgit v1.2.3 From c20f4bf5fa4c7391c833be46960760a883e85151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sat, 30 Jun 2018 23:05:25 +0100 Subject: xep_0030: Add cached parameter to find_identities, defaults to True MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp/plugins/xep_0030/disco.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index b89c7258..7a682676 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -299,11 +299,11 @@ class XEP_0030(BasePlugin): return self.api['has_identity'](jid, node, ifrom, data) async def find_identities(category, type_, domain=None, timeout=None, - **kwargs): + cached=True, **kwargs): if domain is None: domain = self.xmpp.boundjid.domain - if domain not in self.domain_infos: + if not cached or domain not in self.domain_infos: infos = [self.get_info( domain, timeout=timeout, **kwargs)] iq_items = await self.get_items( -- cgit v1.2.3 From df0198abfee83b2a070a7cc2f1a543837189a4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 1 Jul 2018 01:32:00 +0100 Subject: xep_0030: Add callback parameter to find_identities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp/plugins/xep_0030/disco.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index 7a682676..f16d36d2 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -299,7 +299,7 @@ class XEP_0030(BasePlugin): return self.api['has_identity'](jid, node, ifrom, data) async def find_identities(category, type_, domain=None, timeout=None, - cached=True, **kwargs): + cached=True, callback=None, **kwargs): if domain is None: domain = self.xmpp.boundjid.domain @@ -322,6 +322,9 @@ class XEP_0030(BasePlugin): for identity in info['disco_info']['identities']: if identity[0] == category and identity[1] == type_: results.append(info) + + if callback is not None: + callback(results) return results @future_wrapper -- cgit v1.2.3 From caae713dd63a045e28260df962e97e98fb1c0a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Sun, 1 Jul 2018 01:36:26 +0100 Subject: xep_0030: rename find_identities; return all domain infos and let caller filter itself MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- slixmpp/plugins/xep_0030/disco.py | 10 +++------- slixmpp/plugins/xep_0363/http_upload.py | 9 ++++++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/slixmpp/plugins/xep_0030/disco.py b/slixmpp/plugins/xep_0030/disco.py index f16d36d2..ea9a33f4 100644 --- a/slixmpp/plugins/xep_0030/disco.py +++ b/slixmpp/plugins/xep_0030/disco.py @@ -298,8 +298,8 @@ class XEP_0030(BasePlugin): 'cached': cached} return self.api['has_identity'](jid, node, ifrom, data) - async def find_identities(category, type_, domain=None, timeout=None, - cached=True, callback=None, **kwargs): + async def get_info_from_domain(self, domain=None, timeout=None, + cached=True, callback=None, **kwargs): if domain is None: domain = self.xmpp.boundjid.domain @@ -317,11 +317,7 @@ class XEP_0030(BasePlugin): self.domain_infos[domain] = [ future.result() for future in info_futures] - results = [] - for info in self.domain_infos[domain]: - for identity in info['disco_info']['identities']: - if identity[0] == category and identity[1] == type_: - results.append(info) + results = self.domain_infos[domain] if callback is not None: callback(results) diff --git a/slixmpp/plugins/xep_0363/http_upload.py b/slixmpp/plugins/xep_0363/http_upload.py index 3c0f2b3e..65894975 100644 --- a/slixmpp/plugins/xep_0363/http_upload.py +++ b/slixmpp/plugins/xep_0363/http_upload.py @@ -69,9 +69,12 @@ class XEP_0363(BasePlugin): self.xmpp.event('http_upload_request', iq) async def find_upload_service(self, timeout=None): - results = await self.xmpp['xep_0030'].find_identities('store', 'file') - if results: - return results[0] + results = await self.xmpp['xep_0030'].get_info_from_domain() + + for info in results: + for identity in info['disco_info']['identities']: + if identity[0] == 'store' and identity[1] == 'file': + return info def request_slot(self, jid, filename, size, content_type=None, ifrom=None, timeout=None, callback=None, timeout_callback=None): -- cgit v1.2.3