changeset 18:7937d6fbbe2a

Small code cleanups
author Ralph Meijer <ralphm@ik.nu>
date Mon, 30 Aug 2004 17:41:18 +0000
parents 0861c0f2e3b5
children 53b1bea9289b
files idavoll/backend.py idavoll/pubsub.py
diffstat 2 files changed, 9 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/backend.py	Mon Jul 26 11:40:52 2004 +0000
+++ b/idavoll/backend.py	Mon Aug 30 17:41:18 2004 +0000
@@ -57,6 +57,7 @@
 
 		node = Node("ralphm/mood/ralphm@ik.nu")
 		node.subscriptions["ralphm@doe.ik.nu"] = Subscription("subscribed")
+		node.subscriptions["notify@ik.nu/mood_monitor"] = Subscription("subscribed")
 		node.affiliations["ralphm@ik.nu"] = "owner"
 		node.affiliations["ralphm@doe.ik.nu"] = "publisher"
 		node.configuration.persist_items = True
@@ -78,10 +79,6 @@
 			except KeyError:
 				raise NotAuthorized()
 
-			# the following is under the assumption that the publisher
-			# has to provide an item when the node is persistent, but
-			# an empty notification is to be sent.
-
 			if items and not persist_items and not deliver_payloads:
 				raise NoPayloadAllowed
 			elif not items and (persist_items or deliver_payloads):
@@ -107,8 +104,7 @@
 
 			return defer.succeed(None)
 		except:
-			f = failure.Failure()
-			return defer.fail(f)
+			return defer.fail(failure.Failure())
 
 	def do_subscribe(self, node_id, subscriber, requestor):
 		# expect subscriber and requestor to be a jid.JID 
@@ -144,8 +140,7 @@
 					'jid': subscriber,
 					'subscription': subscription.state})
 		except:
-			f = failure.Failure()
-			return defer.fail(f)
+			return defer.fail(failure.Failure)
 
 		
 	def magic_filter(self, subscribers, node_id, items):
--- a/idavoll/pubsub.py	Mon Jul 26 11:40:52 2004 +0000
+++ b/idavoll/pubsub.py	Mon Aug 30 17:41:18 2004 +0000
@@ -74,7 +74,7 @@
 	def success(self, result, iq):
 		iq.swapAttributeValues("to", "from")
 		iq["type"] = 'result'
-		iq.children = []
+		iq.children = result or []
 		return iq
 
 	def notImplemented(self, iq):
@@ -114,18 +114,19 @@
 		subscriber = jid.JID(iq.pubsub.subscribe["jid"])
 		requestor = jid.JID(iq["from"]).userhostJID()
 		d = self.backend.do_subscribe(node_id, subscriber, requestor)
-		d.addCallback(self.return_subscription, iq)
+		d.addCallback(self.return_subscription)
+		d.addCallback(self.succeed, iq)
 		d.addErrback(self.error, iq)
 		d.addCallback(self.send)
 
-	def return_subscription(self, result, iq):
-		reply = self.success(result, iq)
+	def return_subscription(self, result):
+		reply = domish.Element("pubsub", NS_PUBSUB)
 		entity = reply.addElement("entity")
 		entity["node"] = result["node"]
 		entity["jid"] = result["jid"].full()
 		entity["affiliation"] = result["affiliation"]
 		entity["subscription"] = result["subscription"]
-		return iq
+		return reply
 
 	def do_notification(self, list, node):