Implement a few more static node handlers.

This commit is contained in:
Lance Stout 2010-12-15 19:22:21 -05:00
parent 2c5b77ae2e
commit 1ebc7f4d4b
2 changed files with 26 additions and 18 deletions

View file

@ -452,7 +452,7 @@ class xep_0030(base_plugin):
""" """
self._run_node_handler('del_features', jid, node, kwargs) self._run_node_handler('del_features', jid, node, kwargs)
def _run_node_handler(self, htype, jid, node, data=None): def _run_node_handler(self, htype, jid, node, data={}):
""" """
Execute the most specific node handler for the given Execute the most specific node handler for the given
JID/node combination. JID/node combination.

View file

@ -57,7 +57,7 @@ class StaticDisco(object):
self.nodes[(jid, node)]['info']['node'] = node self.nodes[(jid, node)]['info']['node'] = node
self.nodes[(jid, node)]['items']['node'] = node self.nodes[(jid, node)]['items']['node'] = node
def get_info(self, jid, node, data=None): def get_info(self, jid, node, data):
if (jid, node) not in self.nodes: if (jid, node) not in self.nodes:
if not node: if not node:
return DiscoInfo() return DiscoInfo()
@ -66,11 +66,11 @@ class StaticDisco(object):
else: else:
return self.nodes[(jid, node)]['info'] return self.nodes[(jid, node)]['info']
def del_info(self, jid, node, data=None): def del_info(self, jid, node, data):
if (jid, node) in self.nodes: if (jid, node) in self.nodes:
self.nodes[(jid, node)]['info'] = DiscoInfo() self.nodes[(jid, node)]['info'] = DiscoInfo()
def get_items(self, jid, node, data=None): def get_items(self, jid, node, data):
if (jid, node) not in self.nodes: if (jid, node) not in self.nodes:
if not node: if not node:
return DiscoInfo() return DiscoInfo()
@ -79,14 +79,16 @@ class StaticDisco(object):
else: else:
return self.nodes[(jid, node)]['items'] return self.nodes[(jid, node)]['items']
def set_items(self, jid, node, data=None): def set_items(self, jid, node, data):
pass items = data.get('items', set())
self.add_node(jid, node)
self.nodes[(jid, node)]['items']['items'] = items
def del_items(self, jid, node, data=None): def del_items(self, jid, node, data):
if (jid, node) in self.nodes: if (jid, node) in self.nodes:
self.nodes[(jid, node)]['items'] = DiscoItems() self.nodes[(jid, node)]['items'] = DiscoItems()
def add_identity(self, jid, node, data={}): def add_identity(self, jid, node, data):
self.add_node(jid, node) self.add_node(jid, node)
self.nodes[(jid, node)]['info'].add_identity( self.nodes[(jid, node)]['info'].add_identity(
data.get('category', ''), data.get('category', ''),
@ -94,10 +96,12 @@ class StaticDisco(object):
data.get('name', None), data.get('name', None),
data.get('lang', None)) data.get('lang', None))
def set_identities(self, jid, node, data=None): def set_identities(self, jid, node, data):
pass identities = data.get('identities', set())
self.add_node(jid, node)
self.nodes[(jid, node)]['info']['identities'] = identities
def del_identity(self, jid, node, data=None): def del_identity(self, jid, node, data):
if (jid, node) not in self.nodes: if (jid, node) not in self.nodes:
return return
self.nodes[(jid, node)]['info'].del_identity( self.nodes[(jid, node)]['info'].del_identity(
@ -106,25 +110,29 @@ class StaticDisco(object):
data.get('name', None), data.get('name', None),
data.get('lang', None)) data.get('lang', None))
def add_feature(self, jid, node, data=None): def add_feature(self, jid, node, data):
self.add_node(jid, node) self.add_node(jid, node)
self.nodes[(jid, node)]['info'].add_feature(data.get('feature', '')) self.nodes[(jid, node)]['info'].add_feature(data.get('feature', ''))
def set_features(self, jid, node, data=None): def set_features(self, jid, node, data):
pass features = data.get('features', set())
self.add_node(jid, node)
self.nodes[(jid, node)]['info']['features'] = features
def del_feature(self, jid, node, data=None): def del_feature(self, jid, node, data):
if (jid, node) not in self.nodes: if (jid, node) not in self.nodes:
return return
self.nodes[(jid, node)]['info'].del_feature(data.get('feature', '')) self.nodes[(jid, node)]['info'].del_feature(data.get('feature', ''))
def add_item(self, jid, node, data=None): def add_item(self, jid, node, data):
self.add_node(jid, node) self.add_node(jid, node)
self.nodes[(jid, node)]['items'].add_item( self.nodes[(jid, node)]['items'].add_item(
data.get('ijid', ''), data.get('ijid', ''),
node=data.get('inode', None), node=data.get('inode', None),
name=data.get('name', None)) name=data.get('name', None))
def del_item(self, jid, node, data=None): def del_item(self, jid, node, data):
if (jid, node) in self.nodes: if (jid, node) in self.nodes:
self.nodes[(jid, node)]['items'].del_item(**data) self.nodes[(jid, node)]['items'].del_item(
data.get('ijid', ''),
node=data.get('inode', None))