Merge branch 'factor_find_identities' into 'master'
Factor find identities See merge request poezio/slixmpp!2
This commit is contained in:
commit
2fc2a88970
@ -6,6 +6,7 @@
|
|||||||
See the file LICENSE for copying permission.
|
See the file LICENSE for copying permission.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from slixmpp import Iq
|
from slixmpp import Iq
|
||||||
@ -123,6 +124,8 @@ class XEP_0030(BasePlugin):
|
|||||||
for op in self._disco_ops:
|
for op in self._disco_ops:
|
||||||
self.api.register(getattr(self.static, op), op, default=True)
|
self.api.register(getattr(self.static, op), op, default=True)
|
||||||
|
|
||||||
|
self.domain_infos = {}
|
||||||
|
|
||||||
def session_bind(self, jid):
|
def session_bind(self, jid):
|
||||||
self.add_feature('http://jabber.org/protocol/disco#info')
|
self.add_feature('http://jabber.org/protocol/disco#info')
|
||||||
|
|
||||||
@ -295,6 +298,31 @@ class XEP_0030(BasePlugin):
|
|||||||
'cached': cached}
|
'cached': cached}
|
||||||
return self.api['has_identity'](jid, node, ifrom, data)
|
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):
|
||||||
|
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)]
|
||||||
|
iq_items = await self.get_items(
|
||||||
|
domain, timeout=timeout, **kwargs)
|
||||||
|
items = iq_items['disco_items']['items']
|
||||||
|
infos += [
|
||||||
|
self.get_info(item[0], timeout=timeout, **kwargs)
|
||||||
|
for item in items]
|
||||||
|
info_futures, _ = await asyncio.wait(infos, timeout=timeout)
|
||||||
|
|
||||||
|
self.domain_infos[domain] = [
|
||||||
|
future.result() for future in info_futures]
|
||||||
|
|
||||||
|
results = self.domain_infos[domain]
|
||||||
|
|
||||||
|
if callback is not None:
|
||||||
|
callback(results)
|
||||||
|
return results
|
||||||
|
|
||||||
@future_wrapper
|
@future_wrapper
|
||||||
def get_info(self, jid=None, node=None, local=None,
|
def get_info(self, jid=None, node=None, local=None,
|
||||||
cached=None, **kwargs):
|
cached=None, **kwargs):
|
||||||
|
@ -68,16 +68,10 @@ class XEP_0363(BasePlugin):
|
|||||||
def _handle_request(self, iq):
|
def _handle_request(self, iq):
|
||||||
self.xmpp.event('http_upload_request', iq)
|
self.xmpp.event('http_upload_request', iq)
|
||||||
|
|
||||||
async def find_upload_service(self, ifrom=None, timeout=None, callback=None,
|
async def find_upload_service(self, timeout=None):
|
||||||
timeout_callback=None):
|
results = await self.xmpp['xep_0030'].get_info_from_domain()
|
||||||
infos = [self.xmpp['xep_0030'].get_info(self.xmpp.boundjid.domain)]
|
|
||||||
iq_items = await self.xmpp['xep_0030'].get_items(
|
for info in results:
|
||||||
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']:
|
for identity in info['disco_info']['identities']:
|
||||||
if identity[0] == 'store' and identity[1] == 'file':
|
if identity[0] == 'store' and identity[1] == 'file':
|
||||||
return info
|
return info
|
||||||
@ -100,7 +94,7 @@ class XEP_0363(BasePlugin):
|
|||||||
callback=None, timeout_callback=None):
|
callback=None, timeout_callback=None):
|
||||||
''' Helper function which does all of the uploading process. '''
|
''' Helper function which does all of the uploading process. '''
|
||||||
if self.upload_service is None:
|
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:
|
if info_iq is None:
|
||||||
raise UploadServiceNotFound()
|
raise UploadServiceNotFound()
|
||||||
self.upload_service = info_iq['from']
|
self.upload_service = info_iq['from']
|
||||||
|
Loading…
Reference in New Issue
Block a user