Mercurial > libervia-pubsub
comparison idavoll/pubsub.py @ 90:59378610b16e
Implement node purging and node deletion.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Wed, 17 Nov 2004 20:43:13 +0000 |
parents | ec557449d1aa |
children | ea3b2410c01c |
comparison
equal
deleted
inserted
replaced
89:ccf699adae5e | 90:59378610b16e |
---|---|
26 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure' | 26 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure' |
27 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure' | 27 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure' |
28 PUBSUB_AFFILIATIONS = PUBSUB_GET + '/affiliations' | 28 PUBSUB_AFFILIATIONS = PUBSUB_GET + '/affiliations' |
29 PUBSUB_ITEMS = PUBSUB_GET + '/items' | 29 PUBSUB_ITEMS = PUBSUB_GET + '/items' |
30 PUBSUB_RETRACT = PUBSUB_SET + '/retract' | 30 PUBSUB_RETRACT = PUBSUB_SET + '/retract' |
31 PUBSUB_PURGE = PUBSUB_SET + '/purge' | |
32 PUBSUB_DELETE = PUBSUB_SET + '/delete' | |
31 | 33 |
32 class Error(Exception): | 34 class Error(Exception): |
33 pubsub_error = None | 35 pubsub_error = None |
34 stanza_error = None | 36 stanza_error = None |
35 msg = '' | 37 msg = '' |
411 | 413 |
412 class ComponentServiceFromRetractionService(Service): | 414 class ComponentServiceFromRetractionService(Service): |
413 | 415 |
414 def componentConnected(self, xmlstream): | 416 def componentConnected(self, xmlstream): |
415 xmlstream.addObserver(PUBSUB_RETRACT, self.onRetract) | 417 xmlstream.addObserver(PUBSUB_RETRACT, self.onRetract) |
418 xmlstream.addObserver(PUBSUB_PURGE, self.onPurge) | |
416 | 419 |
417 def onRetract(self, iq): | 420 def onRetract(self, iq): |
418 self.handler_wrapper(self._onRetract, iq) | 421 self.handler_wrapper(self._onRetract, iq) |
419 | 422 |
420 def _onRetract(self, iq): | 423 def _onRetract(self, iq): |
434 print item_ids | 437 print item_ids |
435 | 438 |
436 return self.backend.retract_item(node, item_ids, | 439 return self.backend.retract_item(node, item_ids, |
437 jid.JID(iq["from"]).userhostJID()) | 440 jid.JID(iq["from"]).userhostJID()) |
438 | 441 |
442 def onPurge(self, iq): | |
443 self.handler_wrapper(self._onPurge, iq) | |
444 | |
445 def _onPurge(self, iq): | |
446 try: | |
447 node = iq.pubsub.purge["node"] | |
448 except KeyError: | |
449 raise BadRequest | |
450 | |
451 return self.backend.purge_node(node, jid.JID(iq["from"]).userhostJID()) | |
452 | |
439 components.registerAdapter(ComponentServiceFromRetractionService, backend.IRetractionService, component.IService) | 453 components.registerAdapter(ComponentServiceFromRetractionService, backend.IRetractionService, component.IService) |
454 | |
455 class ComponentServiceFromNodeDeletionService(Service): | |
456 | |
457 def __init__(self, backend): | |
458 Service.__init__(self, backend) | |
459 self.subscribers = [] | |
460 | |
461 def componentConnected(self, xmlstream): | |
462 self.backend.register_pre_delete(self._pre_delete) | |
463 xmlstream.addObserver(PUBSUB_DELETE, self.onDelete) | |
464 | |
465 def _pre_delete(self, node_id): | |
466 d = self.backend.get_subscribers(node_id) | |
467 d.addCallback(self._return_deferreds, node_id) | |
468 return d | |
469 | |
470 def _return_deferreds(self, subscribers, node_id): | |
471 d = defer.Deferred() | |
472 d.addCallback(self._notify, subscribers, node_id) | |
473 return [d] | |
474 | |
475 def _notify(self, result, subscribers, node_id): | |
476 message = domish.Element((NS_COMPONENT, "message")) | |
477 message["from"] = self.parent.jabberId | |
478 event = message.addElement((NS_PUBSUB_EVENT, "event")) | |
479 event.addElement("delete")["node"] = node_id | |
480 | |
481 for subscriber in subscribers: | |
482 message["to"] = subscriber | |
483 print message.toXml() | |
484 self.send(message) | |
485 | |
486 def onDelete(self, iq): | |
487 self.handler_wrapper(self._onDelete, iq) | |
488 | |
489 def _onDelete(self, iq): | |
490 try: | |
491 node = iq.pubsub.delete["node"] | |
492 except KeyError: | |
493 raise BadRequest | |
494 | |
495 return self.backend.delete_node(node, jid.JID(iq["from"]).userhostJID()) | |
496 | |
497 components.registerAdapter(ComponentServiceFromNodeDeletionService, backend.INodeDeletionService, component.IService) |