changeset 20:eddea65d1032

Added two exceptions: NoInstantNodes and NodeExists. Renamed 'name' attribute of Node to 'id'. Added create_node() method.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 06 Oct 2004 21:05:42 +0000
parents 53b1bea9289b
children e01bbbfa8a46
files idavoll/backend.py
diffstat 1 files changed, 27 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/backend.py	Wed Oct 06 21:01:13 2004 +0000
+++ b/idavoll/backend.py	Wed Oct 06 21:05:42 2004 +0000
@@ -31,6 +31,12 @@
 	def __init__(self, msg = 'No payload allowed'):
 		BackendException.__init__(self, msg)
 
+class NoInstantNodes(BackendException):
+	pass
+
+class NodeExists(BackendException):
+	pass
+
 class Subscription:
 	def __init__(self, state):
 		self.state = state
@@ -41,8 +47,8 @@
 		self.deliver_payloads = False
 
 class Node:
-	def __init__(self, name):
-		self.name = name
+	def __init__(self, id):
+		self.id = id
 		self.configuration = NodeConfiguration()
 		self.subscriptions = {}
 		self.affiliations = {}
@@ -62,7 +68,7 @@
 		node.affiliations["ralphm@doe.ik.nu"] = "publisher"
 		node.configuration.persist_items = True
 		node.configuration.deliver_payloads = True
-		self.nodes[node.name] = node
+		self.nodes[node.id] = node
 
 	def do_publish(self, node_id, publisher, items):
 		try:
@@ -89,7 +95,7 @@
 			if persist_items or deliver_payloads:
 				for item in items:
 					if item["id"] is None:
-						item["id"] = 'random'
+						item["id"] = 'random'	# FIXME
 
 			if persist_items:
 				self.storeItems(node_id, publisher, items)
@@ -167,3 +173,20 @@
 			self.nodes[node_id].items[item["id"]] = item
 
 		print self.nodes[node_id].items
+
+	def create_node(node_id, owner):
+		result = {}
+
+		try:
+			if not node_id:
+				raise NoInstantNodes
+
+			if node_id in self.nodes:
+				raise NodeExists
+			
+			self.nodes[node_id] = Node(node_id)
+			node.affiliations[owner.full()] = 'owner'
+			return defer.succeed({'node_id': node.id})
+		except:
+			return defer.fail(failure.Failure)
+