summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0060.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-11-17 02:00:20 -0500
committerLance Stout <lancestout@gmail.com>2010-11-17 02:01:12 -0500
commit26aca2b789f62123819041229ba40ab10268f49e (patch)
tree20388fb0559ed85f7143eb3b8a669142cdc43f6b /sleekxmpp/plugins/xep_0060.py
parent4f69a03bb1a8caab7899bd04f97b7975a78f2f34 (diff)
parent5424ede413393db5b835686e8544a9b703fb113b (diff)
downloadslixmpp-26aca2b789f62123819041229ba40ab10268f49e.tar.gz
slixmpp-26aca2b789f62123819041229ba40ab10268f49e.tar.bz2
slixmpp-26aca2b789f62123819041229ba40ab10268f49e.tar.xz
slixmpp-26aca2b789f62123819041229ba40ab10268f49e.zip
Merge branch 'roster' of github.com:fritzy/SleekXMPP into roster
Conflicts: sleekxmpp/basexmpp.py sleekxmpp/roster.py sleekxmpp/test/sleektest.py tests/test_stream_presence.py tests/test_stream_roster.py
Diffstat (limited to 'sleekxmpp/plugins/xep_0060.py')
-rw-r--r--sleekxmpp/plugins/xep_0060.py40
1 files changed, 22 insertions, 18 deletions
diff --git a/sleekxmpp/plugins/xep_0060.py b/sleekxmpp/plugins/xep_0060.py
index 0b056f0b..a7c6d023 100644
--- a/sleekxmpp/plugins/xep_0060.py
+++ b/sleekxmpp/plugins/xep_0060.py
@@ -6,6 +6,10 @@ from .. xmlstream.stanzabase import registerStanzaPlugin, ElementBase, ET
from . import stanza_pubsub
from . xep_0004 import Form
+
+log = logging.getLogger(__name__)
+
+
class xep_0060(base.base_plugin):
"""
XEP-0060 Publish Subscribe
@@ -14,7 +18,7 @@ class xep_0060(base.base_plugin):
def plugin_init(self):
self.xep = '0060'
self.description = 'Publish-Subscribe'
-
+
def create_node(self, jid, node, config=None, collection=False, ntype=None):
pubsub = ET.Element('{http://jabber.org/protocol/pubsub}pubsub')
create = ET.Element('create')
@@ -52,7 +56,7 @@ class xep_0060(base.base_plugin):
result = iq.send()
if result is False or result is None or result['type'] == 'error': return False
return True
-
+
def subscribe(self, jid, node, bare=True, subscribee=None):
pubsub = ET.Element('{http://jabber.org/protocol/pubsub}pubsub')
subscribe = ET.Element('subscribe')
@@ -72,7 +76,7 @@ class xep_0060(base.base_plugin):
result = iq.send()
if result is False or result is None or result['type'] == 'error': return False
return True
-
+
def unsubscribe(self, jid, node, bare=True, subscribee=None):
pubsub = ET.Element('{http://jabber.org/protocol/pubsub}pubsub')
unsubscribe = ET.Element('unsubscribe')
@@ -92,7 +96,7 @@ class xep_0060(base.base_plugin):
result = iq.send()
if result is False or result is None or result['type'] == 'error': return False
return True
-
+
def getNodeConfig(self, jid, node=None): # if no node, then grab default
pubsub = ET.Element('{http://jabber.org/protocol/pubsub#owner}pubsub')
if node is not None:
@@ -110,17 +114,17 @@ class xep_0060(base.base_plugin):
#self.xmpp.add_handler("<iq id='%s'/>" % id, self.handlerCreateNodeResponse)
result = iq.send()
if result is None or result == False or result['type'] == 'error':
- logging.warning("got error instead of config")
+ log.warning("got error instead of config")
return False
if node is not None:
form = result.find('{http://jabber.org/protocol/pubsub#owner}pubsub/{http://jabber.org/protocol/pubsub#owner}configure/{jabber:x:data}x')
else:
form = result.find('{http://jabber.org/protocol/pubsub#owner}pubsub/{http://jabber.org/protocol/pubsub#owner}default/{jabber:x:data}x')
if not form or form is None:
- logging.error("No form found.")
+ log.error("No form found.")
return False
return Form(xml=form)
-
+
def getNodeSubscriptions(self, jid, node):
pubsub = ET.Element('{http://jabber.org/protocol/pubsub#owner}pubsub')
subscriptions = ET.Element('subscriptions')
@@ -133,7 +137,7 @@ class xep_0060(base.base_plugin):
id = iq['id']
result = iq.send()
if result is None or result == False or result['type'] == 'error':
- logging.warning("got error instead of config")
+ log.warning("got error instead of config")
return False
else:
results = result.findall('{http://jabber.org/protocol/pubsub#owner}pubsub/{http://jabber.org/protocol/pubsub#owner}subscriptions/{http://jabber.org/protocol/pubsub#owner}subscription')
@@ -156,7 +160,7 @@ class xep_0060(base.base_plugin):
id = iq['id']
result = iq.send()
if result is None or result == False or result['type'] == 'error':
- logging.warning("got error instead of config")
+ log.warning("got error instead of config")
return False
else:
results = result.findall('{http://jabber.org/protocol/pubsub#owner}pubsub/{http://jabber.org/protocol/pubsub#owner}affiliations/{http://jabber.org/protocol/pubsub#owner}affiliation')
@@ -181,8 +185,8 @@ class xep_0060(base.base_plugin):
return True
else:
return False
-
-
+
+
def setNodeConfig(self, jid, node, config):
pubsub = ET.Element('{http://jabber.org/protocol/pubsub#owner}pubsub')
configure = ET.Element('configure')
@@ -195,10 +199,10 @@ class xep_0060(base.base_plugin):
iq.attrib['from'] = self.xmpp.fulljid
id = iq['id']
result = iq.send()
- if result is None or result['type'] == 'error':
+ if result is None or result['type'] == 'error':
return False
return True
-
+
def setItem(self, jid, node, items=[]):
pubsub = ET.Element('{http://jabber.org/protocol/pubsub}pubsub')
publish = ET.Element('publish')
@@ -218,7 +222,7 @@ class xep_0060(base.base_plugin):
result = iq.send()
if result is None or result is False or result['type'] == 'error': return False
return True
-
+
def addItem(self, jid, node, items=[]):
return self.setItem(jid, node, items)
@@ -237,7 +241,7 @@ class xep_0060(base.base_plugin):
result = iq.send()
if result is None or result is False or result['type'] == 'error': return False
return True
-
+
def getNodes(self, jid):
response = self.xmpp.plugin['xep_0030'].getItems(jid)
items = response.findall('{http://jabber.org/protocol/disco#items}query/{http://jabber.org/protocol/disco#items}item')
@@ -246,7 +250,7 @@ class xep_0060(base.base_plugin):
for item in items:
nodes[item.get('node')] = item.get('name')
return nodes
-
+
def getItems(self, jid, node):
response = self.xmpp.plugin['xep_0030'].getItems(jid, node)
items = response.findall('{http://jabber.org/protocol/disco#items}query/{http://jabber.org/protocol/disco#items}item')
@@ -264,7 +268,7 @@ class xep_0060(base.base_plugin):
try:
config.field['pubsub#collection'].setValue(parent)
except KeyError:
- logging.warning("pubsub#collection doesn't exist in config, trying to add it")
+ log.warning("pubsub#collection doesn't exist in config, trying to add it")
config.addField('pubsub#collection', value=parent)
if not self.setNodeConfig(jid, child, config):
return False
@@ -298,7 +302,7 @@ class xep_0060(base.base_plugin):
try:
config.field['pubsub#collection'].setValue(parent)
except KeyError:
- logging.warning("pubsub#collection doesn't exist in config, trying to add it")
+ log.warning("pubsub#collection doesn't exist in config, trying to add it")
config.addField('pubsub#collection', value=parent)
if not self.setNodeConfig(jid, child, config):
return False