Almost done with xep-30; added more docs.
This commit is contained in:
parent
0aee445e69
commit
53a5026301
2 changed files with 51 additions and 4 deletions
|
@ -230,7 +230,7 @@ class xep_0030(base_plugin):
|
|||
no stanzas need to be sent.
|
||||
Otherwise, a disco stanza must be sent to the
|
||||
remove JID to retrieve the info.
|
||||
dfrom -- Specifiy the sender's JID.
|
||||
ifrom -- Specifiy the sender's JID.
|
||||
block -- If true, block and wait for the stanzas' reply.
|
||||
timeout -- The time in seconds to block while waiting for
|
||||
a reply. If None, then wait indefinitely.
|
||||
|
@ -245,7 +245,7 @@ class xep_0030(base_plugin):
|
|||
return self._fix_default_info(info)
|
||||
|
||||
iq = self.xmpp.Iq()
|
||||
iq['from'] = kwargs.get('dfrom', '')
|
||||
iq['from'] = kwargs.get('ifrom', '')
|
||||
iq['to'] = jid
|
||||
iq['type'] = 'get'
|
||||
iq['disco_info']['node'] = node if node else ''
|
||||
|
@ -270,7 +270,7 @@ class xep_0030(base_plugin):
|
|||
no stanzas need to be sent.
|
||||
Otherwise, a disco stanza must be sent to the
|
||||
remove JID to retrieve the items.
|
||||
dfrom -- Specifiy the sender's JID.
|
||||
ifrom -- Specifiy the sender's JID.
|
||||
block -- If true, block and wait for the stanzas' reply.
|
||||
timeout -- The time in seconds to block while waiting for
|
||||
a reply. If None, then wait indefinitely.
|
||||
|
@ -282,7 +282,7 @@ class xep_0030(base_plugin):
|
|||
return self._run_node_handler('get_items', jid, node, kwargs)
|
||||
|
||||
iq = self.xmpp.Iq()
|
||||
iq['from'] = kwargs.get('dfrom', '')
|
||||
iq['from'] = kwargs.get('ifrom', '')
|
||||
iq['to'] = jid
|
||||
iq['type'] = 'get'
|
||||
iq['disco_items']['node'] = node if node else ''
|
||||
|
|
|
@ -31,6 +31,11 @@ class StaticDisco(object):
|
|||
|
||||
StaticDisco provides a set of node handlers that will store
|
||||
static sets of disco info and items in memory.
|
||||
|
||||
Attributes:
|
||||
nodes -- A dictionary mapping (JID, node) tuples to a dict
|
||||
containing a disco#info and a disco#items stanza.
|
||||
xmpp -- The main SleekXMPP object.
|
||||
"""
|
||||
|
||||
def __init__(self, xmpp):
|
||||
|
@ -47,6 +52,14 @@ class StaticDisco(object):
|
|||
self.xmpp = xmpp
|
||||
|
||||
def add_node(self, jid=None, node=None):
|
||||
"""
|
||||
Create a new set of stanzas for the provided
|
||||
JID and node combination.
|
||||
|
||||
Arguments:
|
||||
jid -- The JID that will own the new stanzas.
|
||||
node -- The node that will own the new stanzas.
|
||||
"""
|
||||
if jid is None:
|
||||
jid = self.xmpp.boundjid.full
|
||||
if node is None:
|
||||
|
@ -57,7 +70,21 @@ class StaticDisco(object):
|
|||
self.nodes[(jid, node)]['info']['node'] = node
|
||||
self.nodes[(jid, node)]['items']['node'] = node
|
||||
|
||||
# =================================================================
|
||||
# Node Handlers
|
||||
#
|
||||
# Each handler accepts three arguments: jid, node, and data.
|
||||
# The jid and node parameters together determine the set of
|
||||
# info and items stanzas that will be retrieved or added.
|
||||
# The data parameter is a dictionary with additional paramters
|
||||
# that will be passed to other calls.
|
||||
|
||||
def get_info(self, jid, node, data):
|
||||
"""
|
||||
Return the stored info data for the requested JID/node combination.
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
if (jid, node) not in self.nodes:
|
||||
if not node:
|
||||
return DiscoInfo()
|
||||
|
@ -67,10 +94,20 @@ class StaticDisco(object):
|
|||
return self.nodes[(jid, node)]['info']
|
||||
|
||||
def del_info(self, jid, node, data):
|
||||
"""
|
||||
Reset the info stanza for a given JID/node combination.
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
if (jid, node) in self.nodes:
|
||||
self.nodes[(jid, node)]['info'] = DiscoInfo()
|
||||
|
||||
def get_items(self, jid, node, data):
|
||||
"""
|
||||
Return the stored items data for the requested JID/node combination.
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
if (jid, node) not in self.nodes:
|
||||
if not node:
|
||||
return DiscoInfo()
|
||||
|
@ -80,11 +117,21 @@ class StaticDisco(object):
|
|||
return self.nodes[(jid, node)]['items']
|
||||
|
||||
def set_items(self, jid, node, data):
|
||||
"""
|
||||
Replace the stored items data for a JID/node combination.
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
items = data.get('items', set())
|
||||
self.add_node(jid, node)
|
||||
self.nodes[(jid, node)]['items']['items'] = items
|
||||
|
||||
def del_items(self, jid, node, data):
|
||||
"""
|
||||
Reset the items stanza for a given JID/node combination.
|
||||
|
||||
The data parameter is not used.
|
||||
"""
|
||||
if (jid, node) in self.nodes:
|
||||
self.nodes[(jid, node)]['items'] = DiscoItems()
|
||||
|
||||
|
|
Loading…
Reference in a new issue