changeset 84:34be83a0bd2e

Implement instant nodes. Fix generation of item ids when not provided on publish.
author Ralph Meijer <ralphm@ik.nu>
date Tue, 09 Nov 2004 15:58:06 +0000
parents f3f31aa491df
children ec557449d1aa
files idavoll/backend.py
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/backend.py	Tue Nov 09 15:57:23 2004 +0000
+++ b/idavoll/backend.py	Tue Nov 09 15:58:06 2004 +0000
@@ -3,6 +3,8 @@
 from twisted.application import service
 from twisted.xish import utility
 from twisted.internet import defer
+import sha
+import time
 
 class Error(Exception):
     msg = ''
@@ -185,8 +187,9 @@
 
         if persist_items or deliver_payloads:
             for item in items:
-                if item["id"] is None:
-                    item["id"] = 'random'   # FIXME
+                if not item.getAttribute("id"):
+                    item["id"] = sha.new(str(time.time()) +
+                                         requestor.full()).hexdigest()
 
         if persist_items:
             d = self.parent.storage.store_items(node_id, items,
@@ -271,11 +274,12 @@
     __implements__ = INodeCreationService,
 
     def supports_instant_nodes(self):
-        return False
+        return True
 
     def create_node(self, node_id, requestor):
         if not node_id:
-            raise NoInstantNodes
+            node_id = 'generic/%s' % sha.new(str(time.time()) +
+                                             requestor.full()).hexdigest()
 
         d = self.parent.storage.create_node(node_id, requestor)
         d.addCallback(lambda _: node_id)