From 4fb77ac8787422169566d613562127acf75a427b Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Sat, 6 Nov 2010 01:28:59 -0400 Subject: Logging no longer uses root logger. Each module should now log into its own logger. --- sleekxmpp/plugins/xep_0060.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'sleekxmpp/plugins/xep_0060.py') 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("" % 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 -- cgit v1.2.3