comparison idavoll/backend.py @ 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 ec354aab3949
children ec557449d1aa
comparison
equal deleted inserted replaced
83:f3f31aa491df 84:34be83a0bd2e
1 from twisted.protocols.jabber import jid 1 from twisted.protocols.jabber import jid
2 from twisted.python import components 2 from twisted.python import components
3 from twisted.application import service 3 from twisted.application import service
4 from twisted.xish import utility 4 from twisted.xish import utility
5 from twisted.internet import defer 5 from twisted.internet import defer
6 import sha
7 import time
6 8
7 class Error(Exception): 9 class Error(Exception):
8 msg = '' 10 msg = ''
9 11
10 def __str__(self): 12 def __str__(self):
183 185
184 print "publish by %s to %s" % (requestor.full(), node_id) 186 print "publish by %s to %s" % (requestor.full(), node_id)
185 187
186 if persist_items or deliver_payloads: 188 if persist_items or deliver_payloads:
187 for item in items: 189 for item in items:
188 if item["id"] is None: 190 if not item.getAttribute("id"):
189 item["id"] = 'random' # FIXME 191 item["id"] = sha.new(str(time.time()) +
192 requestor.full()).hexdigest()
190 193
191 if persist_items: 194 if persist_items:
192 d = self.parent.storage.store_items(node_id, items, 195 d = self.parent.storage.store_items(node_id, items,
193 requestor) 196 requestor)
194 else: 197 else:
269 class NodeCreationService(service.Service): 272 class NodeCreationService(service.Service):
270 273
271 __implements__ = INodeCreationService, 274 __implements__ = INodeCreationService,
272 275
273 def supports_instant_nodes(self): 276 def supports_instant_nodes(self):
274 return False 277 return True
275 278
276 def create_node(self, node_id, requestor): 279 def create_node(self, node_id, requestor):
277 if not node_id: 280 if not node_id:
278 raise NoInstantNodes 281 node_id = 'generic/%s' % sha.new(str(time.time()) +
282 requestor.full()).hexdigest()
279 283
280 d = self.parent.storage.create_node(node_id, requestor) 284 d = self.parent.storage.create_node(node_id, requestor)
281 d.addCallback(lambda _: node_id) 285 d.addCallback(lambda _: node_id)
282 return d 286 return d
283 287