2011-08-26 19:14:57 +00:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
|
|
|
Copyright (C) 2011 Nathanael C. Fritz
|
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
|
|
|
See the file LICENSE for copying permission.
|
|
|
|
"""
|
|
|
|
|
2011-08-04 06:56:24 +00:00
|
|
|
import logging
|
2011-08-26 19:14:57 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
from sleekxmpp.xmlstream import JID
|
2011-08-26 19:14:57 +00:00
|
|
|
from sleekxmpp.plugins.base import base_plugin
|
2011-08-04 06:56:24 +00:00
|
|
|
from sleekxmpp.plugins.xep_0060 import stanza
|
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2011-08-26 19:14:57 +00:00
|
|
|
class xep_0060(base_plugin):
|
|
|
|
|
2011-08-12 23:35:36 +00:00
|
|
|
"""
|
|
|
|
XEP-0060 Publish Subscribe
|
|
|
|
"""
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-08-12 23:35:36 +00:00
|
|
|
def plugin_init(self):
|
|
|
|
self.xep = '0060'
|
|
|
|
self.description = 'Publish-Subscribe'
|
2011-08-26 19:14:57 +00:00
|
|
|
self.stanza = stanza
|
|
|
|
|
|
|
|
def create_node(self, jid, node, config=None, ntype=None, ifrom=None,
|
|
|
|
block=True, callback=None, timeout=None):
|
|
|
|
"""
|
|
|
|
Create and configure a new pubsub node.
|
|
|
|
|
|
|
|
A server MAY use a different name for the node than the one provided,
|
|
|
|
so be sure to check the result stanza for a server assigned name.
|
|
|
|
|
|
|
|
If no configuration form is provided, the node will be created using
|
|
|
|
the server's default configuration. To get the default configuration
|
|
|
|
use get_node_config().
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
jid -- The JID of the pubsub service.
|
|
|
|
node -- Optional name of the node to create. If no name is
|
|
|
|
provided, the server MAY generate a node ID for you.
|
|
|
|
The server can also assign a different name than the
|
|
|
|
one you provide; check the result stanza to see if
|
|
|
|
the server assigned a name.
|
|
|
|
config -- Optional XEP-0004 data form of configuration settings.
|
|
|
|
ntype -- The type of node to create. Servers typically default
|
|
|
|
to using 'leaf' if no type is provided.
|
|
|
|
ifrom -- Specify the sender's JID.
|
|
|
|
block -- Specify if the send call will block until a response
|
|
|
|
is received, or a timeout occurs. Defaults to True.
|
|
|
|
timeout -- The length of time (in seconds) to wait for a response
|
|
|
|
before exiting the send call if blocking is used.
|
|
|
|
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
|
|
|
callback -- Optional reference to a stream handler function. Will
|
|
|
|
be executed when a reply stanza is received.
|
|
|
|
"""
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub']['create']['node'] = node
|
2011-08-26 19:14:57 +00:00
|
|
|
|
2011-08-12 23:32:09 +00:00
|
|
|
if config is not None:
|
2011-08-26 19:14:57 +00:00
|
|
|
form_type = 'http://jabber.org/protocol/pubsub#node_config'
|
|
|
|
if 'FORM_TYPE' in config['fields']:
|
|
|
|
config.field['FORM_TYPE']['value'] = form_type
|
2011-08-12 23:35:36 +00:00
|
|
|
else:
|
2011-08-26 19:14:57 +00:00
|
|
|
config.add_field(var='FORM_TYPE',
|
|
|
|
ftype='hidden',
|
|
|
|
value=form_type)
|
|
|
|
if ntype:
|
|
|
|
if 'pubsub#node_type' in config['fields']:
|
|
|
|
config.field['pubsub#node_type']['value'] = ntype
|
|
|
|
else:
|
|
|
|
config.add_field(var='pubsub#node_type', value=ntype)
|
|
|
|
iq['pubsub']['configure'].append(config)
|
|
|
|
|
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-30 04:38:41 +00:00
|
|
|
def subscribe(self, jid, node, bare=True, subscribee=None, options=None,
|
|
|
|
ifrom=None, block=True, callback=None, timeout=None):
|
2011-08-26 23:57:37 +00:00
|
|
|
"""
|
|
|
|
Subscribe to updates from a pubsub node.
|
|
|
|
|
|
|
|
The rules for determining the JID that is subscribing to the node are:
|
|
|
|
1. If subscribee is given, use that as provided.
|
|
|
|
2. If ifrom was given, use the bare or full version based on bare.
|
|
|
|
3. Otherwise, use self.xmpp.boundjid based on bare.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
jid -- The pubsub service JID.
|
|
|
|
node -- The node to subscribe to.
|
|
|
|
bare -- Indicates if the subscribee is a bare or full JID.
|
|
|
|
Defaults to True for a bare JID.
|
|
|
|
subscribee -- The JID that is subscribing to the node.
|
2011-08-30 04:38:41 +00:00
|
|
|
options --
|
2011-08-26 23:57:37 +00:00
|
|
|
ifrom -- Specify the sender's JID.
|
|
|
|
block -- Specify if the send call will block until a response
|
|
|
|
is received, or a timeout occurs. Defaults to True.
|
|
|
|
timeout -- The length of time (in seconds) to wait for a response
|
|
|
|
before exiting the send call if blocking is used.
|
|
|
|
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
|
|
|
callback -- Optional reference to a stream handler function. Will
|
|
|
|
be executed when a reply stanza is received.
|
|
|
|
"""
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub']['subscribe']['node'] = node
|
2011-08-26 23:57:37 +00:00
|
|
|
|
2011-08-12 23:32:09 +00:00
|
|
|
if subscribee is None:
|
2011-08-26 23:57:37 +00:00
|
|
|
if ifrom:
|
|
|
|
if bare:
|
|
|
|
subscribee = JID(ifrom).bare
|
|
|
|
else:
|
|
|
|
subscribee = ifrom
|
2011-08-12 23:32:09 +00:00
|
|
|
else:
|
2011-08-26 23:57:37 +00:00
|
|
|
if bare:
|
|
|
|
subscribee = self.xmpp.boundjid.bare
|
|
|
|
else:
|
|
|
|
subscribee = self.xmpp.boundjid
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
iq['pubsub']['subscribe']['jid'] = subscribee
|
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
|
|
|
|
|
|
|
def unsubscribe(self, jid, node, subid=None, bare=True, subscribee=None,
|
|
|
|
ifrom=None, block=True, callback=None, timeout=None):
|
|
|
|
"""
|
|
|
|
Unubscribe from updates from a pubsub node.
|
|
|
|
|
|
|
|
The rules for determining the JID that is unsubscribing
|
|
|
|
from the node are:
|
|
|
|
1. If subscribee is given, use that as provided.
|
|
|
|
2. If ifrom was given, use the bare or full version based on bare.
|
|
|
|
3. Otherwise, use self.xmpp.boundjid based on bare.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
jid -- The pubsub service JID.
|
|
|
|
node -- The node to subscribe to.
|
|
|
|
subid -- The specific subscription, if multiple subscriptions
|
|
|
|
exist for this JID/node combination.
|
|
|
|
bare -- Indicates if the subscribee is a bare or full JID.
|
|
|
|
Defaults to True for a bare JID.
|
|
|
|
subscribee -- The JID that is subscribing to the node.
|
|
|
|
ifrom -- Specify the sender's JID.
|
|
|
|
block -- Specify if the send call will block until a response
|
|
|
|
is received, or a timeout occurs. Defaults to True.
|
|
|
|
timeout -- The length of time (in seconds) to wait for a response
|
|
|
|
before exiting the send call if blocking is used.
|
|
|
|
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
|
|
|
callback -- Optional reference to a stream handler function. Will
|
|
|
|
be executed when a reply stanza is received.
|
|
|
|
"""
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub']['unsubscribe']['node'] = node
|
2011-08-26 23:57:37 +00:00
|
|
|
|
2011-08-12 23:32:09 +00:00
|
|
|
if subscribee is None:
|
2011-08-26 23:57:37 +00:00
|
|
|
if ifrom:
|
|
|
|
if bare:
|
|
|
|
subscribee = JID(ifrom).bare
|
|
|
|
else:
|
|
|
|
subscribee = ifrom
|
2011-08-12 23:32:09 +00:00
|
|
|
else:
|
2011-08-26 23:57:37 +00:00
|
|
|
if bare:
|
|
|
|
subscribee = self.xmpp.boundjid.bare
|
|
|
|
else:
|
|
|
|
subscribee = self.xmpp.boundjid
|
|
|
|
|
|
|
|
iq['pubsub']['unsubscribe']['jid'] = subscribee
|
|
|
|
iq['pubsub']['unsubscribe']['subid'] = subid
|
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
|
|
|
|
2011-08-31 05:27:21 +00:00
|
|
|
def get_subscription_options(self, jid, node, user_jid, ifrom=None,
|
|
|
|
block=True, callback=None, timeout=None):
|
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
|
|
|
iq['pubsub']['options']['node'] = node
|
|
|
|
iq['pubsub']['options']['jid'] = user_jid
|
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-30 04:38:41 +00:00
|
|
|
|
2011-08-31 05:27:21 +00:00
|
|
|
def set_subscription_options(self, jid, node, user_jid, options,
|
|
|
|
ifrom=None, block=True, callback=None,
|
|
|
|
timeout=None):
|
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
|
|
|
iq['pubsub']['options']['node'] = node
|
|
|
|
iq['pubsub']['options']['jid'] = user_jid
|
|
|
|
iq['pubsub']['options'].append(options)
|
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-30 04:38:41 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
def get_node_config(self, jid, node=None, ifrom=None, block=None,
|
|
|
|
callback=None, timeout=None):
|
|
|
|
"""
|
|
|
|
Retrieve the configuration for a node, or the pubsub service's
|
|
|
|
default configuration for new nodes.
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
Arguments:
|
|
|
|
jid -- The JID of the pubsub service.
|
|
|
|
node -- The node to retrieve the configuration for. If None,
|
|
|
|
the default configuration for new nodes will be
|
|
|
|
requested. Defaults to None.
|
|
|
|
ifrom -- Specify the sender's JID.
|
|
|
|
block -- Specify if the send call will block until a response
|
|
|
|
is received, or a timeout occurs. Defaults to True.
|
|
|
|
timeout -- The length of time (in seconds) to wait for a response
|
|
|
|
before exiting the send call if blocking is used.
|
|
|
|
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
|
|
|
callback -- Optional reference to a stream handler function. Will
|
|
|
|
be executed when a reply stanza is received.
|
|
|
|
"""
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
2011-08-31 17:43:33 +00:00
|
|
|
iq['pubsub_owner']['default']['node'] = node
|
2011-08-26 23:57:37 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
|
|
|
|
|
|
|
def get_node_subscriptions(self, jid, node, ifrom=None, block=True,
|
|
|
|
callback=None, timeout=None):
|
|
|
|
"""
|
|
|
|
Retrieve the subscriptions associated with a given node.
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
Arguments:
|
|
|
|
jid -- The JID of the pubsub service.
|
|
|
|
node -- The node to retrieve subscriptions from.
|
|
|
|
ifrom -- Specify the sender's JID.
|
|
|
|
block -- Specify if the send call will block until a response
|
|
|
|
is received, or a timeout occurs. Defaults to True.
|
|
|
|
timeout -- The length of time (in seconds) to wait for a response
|
|
|
|
before exiting the send call if blocking is used.
|
|
|
|
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
|
|
|
callback -- Optional reference to a stream handler function. Will
|
|
|
|
be executed when a reply stanza is received.
|
|
|
|
"""
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub_owner']['subscriptions']['node'] = node
|
2011-08-26 23:57:37 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
def get_node_affiliations(self, jid, node, ifrom=None, block=True,
|
|
|
|
callback=None, timeout=None):
|
|
|
|
"""
|
|
|
|
Retrieve the affiliations associated with a given node.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
jid -- The JID of the pubsub service.
|
|
|
|
node -- The node to retrieve affiliations from.
|
|
|
|
ifrom -- Specify the sender's JID.
|
|
|
|
block -- Specify if the send call will block until a response
|
|
|
|
is received, or a timeout occurs. Defaults to True.
|
|
|
|
timeout -- The length of time (in seconds) to wait for a response
|
|
|
|
before exiting the send call if blocking is used.
|
|
|
|
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
|
|
|
callback -- Optional reference to a stream handler function. Will
|
|
|
|
be executed when a reply stanza is received.
|
|
|
|
"""
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub_owner']['affiliations']['node'] = node
|
2011-08-26 23:57:37 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
def delete_node(self, jid, node, ifrom=None, block=True,
|
|
|
|
callback=None, timeout=None):
|
2011-08-27 05:04:06 +00:00
|
|
|
"""
|
|
|
|
Delete a a pubsub node.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
jid -- The JID of the pubsub service.
|
|
|
|
node -- The node to delete.
|
|
|
|
ifrom -- Specify the sender's JID.
|
|
|
|
block -- Specify if the send call will block until a response
|
|
|
|
is received, or a timeout occurs. Defaults to True.
|
|
|
|
timeout -- The length of time (in seconds) to wait for a response
|
|
|
|
before exiting the send call if blocking is used.
|
|
|
|
Defaults to sleekxmpp.xmlstream.RESPONSE_TIMEOUT
|
|
|
|
callback -- Optional reference to a stream handler function. Will
|
|
|
|
be executed when a reply stanza is received.
|
|
|
|
"""
|
2011-08-31 04:57:11 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub_owner']['delete']['node'] = node
|
2011-08-26 23:57:37 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
def set_node_config(self, jid, node, config, ifrom=None, block=True,
|
|
|
|
callback=None, timeout=None):
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub_owner']['configure']['node'] = node
|
|
|
|
iq['pubsub_owner']['configure']['config'] = config
|
2011-08-26 23:57:37 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-30 06:05:14 +00:00
|
|
|
def publish(self, jid, node, item_id=None, payload=None, items=None,
|
|
|
|
ifrom=None, block=True, callback=None, timeout=None):
|
|
|
|
"""
|
|
|
|
Add or edit items in a node.
|
|
|
|
|
|
|
|
You may publish an individual item using the item_id and payload
|
|
|
|
parameters, or you may batch publish by using the items parameter
|
|
|
|
which accepts a list of id/payload tuples.
|
|
|
|
"""
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub']['publish']['node'] = node
|
2011-08-30 06:05:14 +00:00
|
|
|
|
|
|
|
if items is None:
|
|
|
|
items = []
|
|
|
|
if item_id is not None:
|
|
|
|
items.insert(0, (item_id, payload))
|
2011-08-12 23:32:09 +00:00
|
|
|
for id, payload in items:
|
|
|
|
item = stanza.pubsub.Item()
|
|
|
|
if id is not None:
|
|
|
|
item['id'] = id
|
|
|
|
item['payload'] = payload
|
|
|
|
iq['pubsub']['publish'].append(item)
|
2011-08-26 23:57:37 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
def retract(self, jid, node, item, ifrom=None, block=True,
|
|
|
|
callback=None, timeout=None):
|
2011-08-30 06:05:14 +00:00
|
|
|
"""
|
|
|
|
Delete a single item from a node.
|
|
|
|
"""
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
|
|
|
|
2011-08-12 23:32:09 +00:00
|
|
|
iq['pubsub']['retract']['node'] = node
|
|
|
|
item = stanza.pubsub.Item()
|
|
|
|
item['id'] = item
|
|
|
|
iq['pubsub']['retract'].append(item)
|
2011-08-26 23:57:37 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-30 04:38:41 +00:00
|
|
|
def purge(self, jid, node, ifrom=None, block=True, callback=None,
|
|
|
|
timeout=None):
|
2011-08-30 06:05:14 +00:00
|
|
|
"""
|
|
|
|
Remove all items from a node.
|
|
|
|
"""
|
2011-08-30 04:38:41 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
2011-08-30 06:05:14 +00:00
|
|
|
iq['pubsub_owner']['purge']['node'] = node
|
2011-08-30 04:38:41 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
|
|
|
|
|
|
|
def get_nodes(self, *args, **kwargs):
|
2011-08-30 06:05:14 +00:00
|
|
|
"""
|
|
|
|
Discover the nodes provided by a Pubsub service, using disco.
|
|
|
|
"""
|
|
|
|
return self.xmpp.plugin['xep_0030'].get_items(*args, **kwargs)
|
2011-08-30 04:38:41 +00:00
|
|
|
|
2011-08-30 16:24:46 +00:00
|
|
|
def get_item(self, jid, node, item_id, ifrom=None, block=True,
|
2011-08-30 06:05:14 +00:00
|
|
|
callback=None, timeout=None):
|
|
|
|
"""
|
|
|
|
Retrieve the content of an individual item.
|
|
|
|
"""
|
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
|
|
|
item = self.stanza.Item()
|
|
|
|
item['id'] = item_id
|
|
|
|
iq['pubsub']['items'].append(item)
|
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
|
|
|
|
|
|
|
def get_items(self, jid, node, item_ids=None, max_items=None,
|
|
|
|
iterator=False, ifrom=None, block=False,
|
|
|
|
callback=None, timeout=None):
|
|
|
|
"""
|
|
|
|
Request the contents of a node's items.
|
|
|
|
|
|
|
|
The desired items can be specified, or a query for the last
|
|
|
|
few published items can be used.
|
2011-08-04 06:56:24 +00:00
|
|
|
|
2011-08-30 06:05:14 +00:00
|
|
|
Pubsub services may use result set management for nodes with
|
|
|
|
many items, so an iterator can be returned if needed.
|
|
|
|
"""
|
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='get')
|
|
|
|
iq['pubsub']['items']['max_items'] = max_items
|
|
|
|
|
|
|
|
for item_id in item_ids:
|
|
|
|
item = self.stanza.Item()
|
|
|
|
item['id'] = item_id
|
|
|
|
iq['pubsub']['items'].append(item)
|
|
|
|
|
|
|
|
if iterator:
|
|
|
|
return self.xmpp['xep_0059'].iterate(iq, 'pubsub')
|
|
|
|
else:
|
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
|
|
|
|
|
|
|
def get_item_ids(self, jid, node, ifrom=None, block=True,
|
|
|
|
callback=None, timeout=None, iterator=False):
|
|
|
|
"""
|
|
|
|
Retrieve the ItemIDs hosted by a given node, using disco.
|
|
|
|
"""
|
2011-08-26 23:57:37 +00:00
|
|
|
return self.xmpp.plugin['xep_0030'].get_items(jid, node,
|
|
|
|
ifrom=ifrom,
|
|
|
|
block=block,
|
|
|
|
callback=callback,
|
|
|
|
timeout=timeout,
|
|
|
|
iterator=iterator)
|
2011-08-12 23:32:09 +00:00
|
|
|
|
2011-08-30 06:05:14 +00:00
|
|
|
def modify_affiliations(self, jid, node, affiliations=None, ifrom=None,
|
|
|
|
block=True, callback=None, timeout=None):
|
2011-08-27 05:04:06 +00:00
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
2011-08-30 06:05:14 +00:00
|
|
|
iq['pubsub_owner']['affiliations']['node'] = node
|
2011-08-27 05:04:06 +00:00
|
|
|
|
2011-08-30 06:05:14 +00:00
|
|
|
if affiliations is None:
|
|
|
|
affiliations = []
|
|
|
|
|
|
|
|
for jid, affiliation in affiliations:
|
|
|
|
aff = stanza.pubsub.Affiliation()
|
2011-08-12 23:32:09 +00:00
|
|
|
aff['jid'] = user_jid
|
2011-08-30 06:05:14 +00:00
|
|
|
aff['affiliation'] = affiliation
|
|
|
|
iq['pubsub_owner']['affiliations'].append(aff)
|
|
|
|
|
2011-08-26 23:57:37 +00:00
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|
2011-08-30 04:38:41 +00:00
|
|
|
|
2011-08-30 06:05:14 +00:00
|
|
|
def modify_subscriptions(self, jid, node, subscriptions=None, ifrom=None,
|
|
|
|
block=True, callback=None, timeout=None):
|
|
|
|
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
|
|
|
|
iq['pubsub_owner']['subscriptions']['node'] = node
|
2011-08-30 04:38:41 +00:00
|
|
|
|
2011-08-30 06:05:14 +00:00
|
|
|
if subscriptions is None:
|
|
|
|
subscriptions = []
|
|
|
|
|
|
|
|
for jid, subscription in subscriptions:
|
|
|
|
sub = self.stanza.Subscription()
|
|
|
|
sub['jid'] = user_jid
|
|
|
|
sub['subscription'] = subscription
|
|
|
|
iq['pubsub_owner']['subscriptions'].append(sub)
|
|
|
|
|
|
|
|
return iq.send(block=block, callback=callback, timeout=timeout)
|