Remove locking from static disco.
This commit is contained in:
parent
7cd1cf32ae
commit
125336aeee
@ -7,7 +7,6 @@
|
||||
"""
|
||||
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from slixmpp import Iq
|
||||
from slixmpp.exceptions import XMPPError, IqError, IqTimeout
|
||||
@ -48,7 +47,6 @@ class StaticDisco(object):
|
||||
self.nodes = {}
|
||||
self.xmpp = xmpp
|
||||
self.disco = disco
|
||||
self.lock = threading.RLock()
|
||||
|
||||
def add_node(self, jid=None, node=None, ifrom=None):
|
||||
"""
|
||||
@ -59,7 +57,6 @@ class StaticDisco(object):
|
||||
jid -- The JID that will own the new stanzas.
|
||||
node -- The node that will own the new stanzas.
|
||||
"""
|
||||
with self.lock:
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
@ -75,7 +72,6 @@ class StaticDisco(object):
|
||||
self.nodes[(jid, node, ifrom)]['items']['node'] = node
|
||||
|
||||
def get_node(self, jid=None, node=None, ifrom=None):
|
||||
with self.lock:
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
@ -89,7 +85,6 @@ class StaticDisco(object):
|
||||
return self.nodes[(jid, node, ifrom)]
|
||||
|
||||
def node_exists(self, jid=None, node=None, ifrom=None):
|
||||
with self.lock:
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
@ -199,7 +194,6 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if not self.node_exists(jid, node):
|
||||
if not node:
|
||||
return DiscoInfo()
|
||||
@ -214,7 +208,6 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is a disco#info substanza.
|
||||
"""
|
||||
with self.lock:
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'] = data
|
||||
|
||||
@ -224,7 +217,6 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'] = DiscoInfo()
|
||||
|
||||
@ -234,7 +226,6 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if not self.node_exists(jid, node):
|
||||
if not node:
|
||||
return DiscoItems()
|
||||
@ -250,7 +241,6 @@ class StaticDisco(object):
|
||||
The data parameter may provide:
|
||||
items -- A set of items in tuple format.
|
||||
"""
|
||||
with self.lock:
|
||||
items = data.get('items', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['items']['items'] = items
|
||||
@ -261,7 +251,6 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['items'] = DiscoItems()
|
||||
|
||||
@ -275,7 +264,6 @@ class StaticDisco(object):
|
||||
name -- Optional human readable name for this identity.
|
||||
lang -- Optional standard xml:lang value.
|
||||
"""
|
||||
with self.lock:
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'].add_identity(
|
||||
data.get('category', ''),
|
||||
@ -291,7 +279,6 @@ class StaticDisco(object):
|
||||
identities -- A list of identities in tuple form:
|
||||
(category, type, name, lang)
|
||||
"""
|
||||
with self.lock:
|
||||
identities = data.get('identities', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info']['identities'] = identities
|
||||
@ -306,7 +293,6 @@ class StaticDisco(object):
|
||||
name -- Optional human readable name for this identity.
|
||||
lang -- Optional, standard xml:lang value.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'].del_identity(
|
||||
data.get('category', ''),
|
||||
@ -320,7 +306,6 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
del self.get_node(jid, node)['info']['identities']
|
||||
|
||||
@ -331,7 +316,6 @@ class StaticDisco(object):
|
||||
The data parameter should include:
|
||||
feature -- The namespace of the supported feature.
|
||||
"""
|
||||
with self.lock:
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info'].add_feature(
|
||||
data.get('feature', ''))
|
||||
@ -343,7 +327,6 @@ class StaticDisco(object):
|
||||
The data parameter should include:
|
||||
features -- The new set of supported features.
|
||||
"""
|
||||
with self.lock:
|
||||
features = data.get('features', set())
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['info']['features'] = features
|
||||
@ -355,7 +338,6 @@ class StaticDisco(object):
|
||||
The data parameter should include:
|
||||
feature -- The namespace of the removed feature.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['info'].del_feature(
|
||||
data.get('feature', ''))
|
||||
@ -366,7 +348,6 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if not self.node_exists(jid, node):
|
||||
return
|
||||
del self.get_node(jid, node)['info']['features']
|
||||
@ -381,7 +362,6 @@ class StaticDisco(object):
|
||||
non-addressable items.
|
||||
name -- Optional human readable name for the item.
|
||||
"""
|
||||
with self.lock:
|
||||
self.add_node(jid, node)
|
||||
self.get_node(jid, node)['items'].add_item(
|
||||
data.get('ijid', ''),
|
||||
@ -396,7 +376,6 @@ class StaticDisco(object):
|
||||
ijid -- JID of the item to remove.
|
||||
inode -- Optional extra identifying information.
|
||||
"""
|
||||
with self.lock:
|
||||
if self.node_exists(jid, node):
|
||||
self.get_node(jid, node)['items'].del_item(
|
||||
data.get('ijid', ''),
|
||||
@ -410,7 +389,6 @@ class StaticDisco(object):
|
||||
containing the disco info to cache, or
|
||||
the disco#info substanza itself.
|
||||
"""
|
||||
with self.lock:
|
||||
if isinstance(data, Iq):
|
||||
data = data['disco_info']
|
||||
|
||||
@ -423,7 +401,6 @@ class StaticDisco(object):
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
with self.lock:
|
||||
if not self.node_exists(jid, node, ifrom):
|
||||
return None
|
||||
else:
|
||||
|
@ -124,7 +124,6 @@ class StaticCaps(object):
|
||||
return None
|
||||
|
||||
def cache_caps(self, jid, node, ifrom, data):
|
||||
with self.static.lock:
|
||||
verstring = data.get('verstring', None)
|
||||
info = data.get('info', None)
|
||||
if not verstring or not info:
|
||||
@ -132,15 +131,12 @@ class StaticCaps(object):
|
||||
self.ver_cache[verstring] = info
|
||||
|
||||
def assign_verstring(self, jid, node, ifrom, data):
|
||||
with self.static.lock:
|
||||
if isinstance(jid, JID):
|
||||
jid = jid.full
|
||||
self.jid_vers[jid] = data.get('verstring', None)
|
||||
|
||||
def get_verstring(self, jid, node, ifrom, data):
|
||||
with self.static.lock:
|
||||
return self.jid_vers.get(jid, None)
|
||||
|
||||
def get_caps(self, jid, node, ifrom, data):
|
||||
with self.static.lock:
|
||||
return self.ver_cache.get(data.get('verstring', None), None)
|
||||
|
Loading…
Reference in New Issue
Block a user