diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-03-31 00:25:28 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-03-31 00:25:28 +0200 |
commit | 128cc2eeb4b7f526d2af87d09129a1838061bb1e (patch) | |
tree | bdce8505c0c3ec4716dc23b16326315b2a2cce52 | |
parent | 037912ee89347919b9addffb1646b22469a40f85 (diff) | |
download | slixmpp-128cc2eeb4b7f526d2af87d09129a1838061bb1e.tar.gz slixmpp-128cc2eeb4b7f526d2af87d09129a1838061bb1e.tar.bz2 slixmpp-128cc2eeb4b7f526d2af87d09129a1838061bb1e.tar.xz slixmpp-128cc2eeb4b7f526d2af87d09129a1838061bb1e.zip |
XEP-0115: Use the new cache system.
-rw-r--r-- | slixmpp/plugins/xep_0115/caps.py | 7 | ||||
-rw-r--r-- | slixmpp/plugins/xep_0115/static.py | 8 |
2 files changed, 11 insertions, 4 deletions
diff --git a/slixmpp/plugins/xep_0115/caps.py b/slixmpp/plugins/xep_0115/caps.py index b7f29516..9b2d499e 100644 --- a/slixmpp/plugins/xep_0115/caps.py +++ b/slixmpp/plugins/xep_0115/caps.py @@ -15,6 +15,7 @@ from slixmpp.stanza import StreamFeatures, Presence, Iq from slixmpp.xmlstream import register_stanza_plugin, JID from slixmpp.xmlstream.handler import Callback from slixmpp.xmlstream.matcher import StanzaPath +from slixmpp.util import MemoryCache from slixmpp import asyncio from slixmpp.exceptions import XMPPError, IqError, IqTimeout from slixmpp.plugins import BasePlugin @@ -37,7 +38,8 @@ class XEP_0115(BasePlugin): default_config = { 'hash': 'sha-1', 'caps_node': None, - 'broadcast': True + 'broadcast': True, + 'cache': None, } def plugin_init(self): @@ -48,6 +50,9 @@ class XEP_0115(BasePlugin): if self.caps_node is None: self.caps_node = 'http://slixmpp.com/ver/%s' % __version__ + if self.cache is None: + self.cache = MemoryCache() + register_stanza_plugin(Presence, stanza.Capabilities) register_stanza_plugin(StreamFeatures, stanza.Capabilities) diff --git a/slixmpp/plugins/xep_0115/static.py b/slixmpp/plugins/xep_0115/static.py index d47c8fd8..6c2e910b 100644 --- a/slixmpp/plugins/xep_0115/static.py +++ b/slixmpp/plugins/xep_0115/static.py @@ -33,7 +33,6 @@ class StaticCaps(object): self.disco = self.xmpp['xep_0030'] self.caps = self.xmpp['xep_0115'] self.static = static - self.ver_cache = {} self.jid_vers = {} def supports(self, jid, node, ifrom, data): @@ -128,7 +127,7 @@ class StaticCaps(object): info = data.get('info', None) if not verstring or not info: return - self.ver_cache[verstring] = info + self.caps.cache.store(verstring, info) def assign_verstring(self, jid, node, ifrom, data): if isinstance(jid, JID): @@ -139,4 +138,7 @@ class StaticCaps(object): return self.jid_vers.get(jid, None) def get_caps(self, jid, node, ifrom, data): - return self.ver_cache.get(data.get('verstring', None), None) + verstring = data.get('verstring', None) + if verstring is None: + return None + return self.caps.cache.retrieve(verstring) |