Mercurial > libervia-pubsub
comparison idavoll/backend.py @ 105:8d8946e67fcb
Move to Twisted 2.0.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Fri, 08 Apr 2005 10:01:40 +0000 |
parents | b75fcc554358 |
children | dc36882d2620 |
comparison
equal
deleted
inserted
replaced
104:d42327839888 | 105:8d8946e67fcb |
---|---|
1 from twisted.protocols.jabber import jid | 1 from twisted.words.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 from zope.interface import implements | |
6 import sha | 7 import sha |
7 import time | 8 import time |
8 | 9 |
9 class Error(Exception): | 10 class Error(Exception): |
10 msg = '' | 11 msg = '' |
167 @return: a deferred that returns the requested items | 168 @return: a deferred that returns the requested items |
168 """ | 169 """ |
169 | 170 |
170 class BackendService(service.MultiService, utility.EventDispatcher): | 171 class BackendService(service.MultiService, utility.EventDispatcher): |
171 | 172 |
172 __implements__ = IBackendService, | 173 implements(IBackendService) |
173 | 174 |
174 options = {"pubsub#persist_items": | 175 options = {"pubsub#persist_items": |
175 {"type": "boolean", | 176 {"type": "boolean", |
176 "label": "Persist items to storage"}, | 177 "label": "Persist items to storage"}, |
177 "pubsub#deliver_payloads": | 178 "pubsub#deliver_payloads": |
220 | 221 |
221 return options | 222 return options |
222 | 223 |
223 class PublishService(service.Service): | 224 class PublishService(service.Service): |
224 | 225 |
225 __implements__ = IPublishService, | 226 implements(IPublishService) |
226 | 227 |
227 def publish(self, node_id, items, requestor): | 228 def publish(self, node_id, items, requestor): |
228 d1 = self.parent.storage.get_node_configuration(node_id) | 229 d1 = self.parent.storage.get_node_configuration(node_id) |
229 d2 = self.parent.storage.get_affiliation(node_id, requestor) | 230 d2 = self.parent.storage.get_affiliation(node_id, requestor) |
230 d = defer.DeferredList([d1, d2], fireOnOneErrback=1, consumeErrors=1) | 231 d = defer.DeferredList([d1, d2], fireOnOneErrback=1, consumeErrors=1) |
268 self.parent.dispatch({ 'items': items, 'node_id': node_id }, | 269 self.parent.dispatch({ 'items': items, 'node_id': node_id }, |
269 '//event/pubsub/notify') | 270 '//event/pubsub/notify') |
270 | 271 |
271 class NotificationService(service.Service): | 272 class NotificationService(service.Service): |
272 | 273 |
273 __implements__ = INotificationService, | 274 implements(INotificationService) |
274 | 275 |
275 def get_notification_list(self, node_id, items): | 276 def get_notification_list(self, node_id, items): |
276 d = self.parent.storage.get_subscribers(node_id) | 277 d = self.parent.storage.get_subscribers(node_id) |
277 d.addCallback(self._magic_filter, node_id, items) | 278 d.addCallback(self._magic_filter, node_id, items) |
278 return d | 279 return d |
287 self.parent.addObserver('//event/pubsub/notify', observerfn, | 288 self.parent.addObserver('//event/pubsub/notify', observerfn, |
288 *args, **kwargs) | 289 *args, **kwargs) |
289 | 290 |
290 class SubscriptionService(service.Service): | 291 class SubscriptionService(service.Service): |
291 | 292 |
292 __implements__ = ISubscriptionService, | 293 implements(ISubscriptionService) |
293 | 294 |
294 def subscribe(self, node_id, subscriber, requestor): | 295 def subscribe(self, node_id, subscriber, requestor): |
295 if subscriber.userhostJID() != requestor: | 296 if subscriber.userhostJID() != requestor: |
296 raise NotAuthorized | 297 raise NotAuthorized |
297 | 298 |
330 return self.parent.storage.remove_subscription(node_id, | 331 return self.parent.storage.remove_subscription(node_id, |
331 subscriber) | 332 subscriber) |
332 | 333 |
333 class NodeCreationService(service.Service): | 334 class NodeCreationService(service.Service): |
334 | 335 |
335 __implements__ = INodeCreationService, | 336 implements(INodeCreationService) |
336 | 337 |
337 def supports_instant_nodes(self): | 338 def supports_instant_nodes(self): |
338 return True | 339 return True |
339 | 340 |
340 def create_node(self, node_id, requestor): | 341 def create_node(self, node_id, requestor): |
382 | 383 |
383 return self.parent.storage.set_node_configuration(node_id, options) | 384 return self.parent.storage.set_node_configuration(node_id, options) |
384 | 385 |
385 class AffiliationsService(service.Service): | 386 class AffiliationsService(service.Service): |
386 | 387 |
387 __implements__ = IAffiliationsService, | 388 implements(IAffiliationsService) |
388 | 389 |
389 def get_affiliations(self, entity): | 390 def get_affiliations(self, entity): |
390 d1 = self.parent.storage.get_affiliations(entity) | 391 d1 = self.parent.storage.get_affiliations(entity) |
391 d2 = self.parent.storage.get_subscriptions(entity) | 392 d2 = self.parent.storage.get_subscriptions(entity) |
392 d = defer.DeferredList([d1, d2], fireOnOneErrback=1, consumeErrors=1) | 393 d = defer.DeferredList([d1, d2], fireOnOneErrback=1, consumeErrors=1) |
419 | 420 |
420 return new_affiliations.values() | 421 return new_affiliations.values() |
421 | 422 |
422 class ItemRetrievalService(service.Service): | 423 class ItemRetrievalService(service.Service): |
423 | 424 |
424 __implements__ = IItemRetrievalService | 425 implements(IItemRetrievalService) |
425 | 426 |
426 def get_items(self, node_id, requestor, max_items=None, item_ids=[]): | 427 def get_items(self, node_id, requestor, max_items=None, item_ids=[]): |
427 d = self.parent.storage.is_subscribed(node_id, requestor) | 428 d = self.parent.storage.is_subscribed(node_id, requestor) |
428 d.addCallback(self._do_get_items, node_id, max_items, item_ids) | 429 d.addCallback(self._do_get_items, node_id, max_items, item_ids) |
429 return d | 430 return d |
437 else: | 438 else: |
438 return self.parent.storage.get_items(node_id, max_items) | 439 return self.parent.storage.get_items(node_id, max_items) |
439 | 440 |
440 class RetractionService(service.Service): | 441 class RetractionService(service.Service): |
441 | 442 |
442 __implements__ = IRetractionService, | 443 implements(IRetractionService) |
443 | 444 |
444 def retract_item(self, node_id, item_ids, requestor): | 445 def retract_item(self, node_id, item_ids, requestor): |
445 d1 = self.parent.storage.get_node_configuration(node_id) | 446 d1 = self.parent.storage.get_node_configuration(node_id) |
446 d2 = self.parent.storage.get_affiliation(node_id, requestor) | 447 d2 = self.parent.storage.get_affiliation(node_id, requestor) |
447 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) | 448 d = defer.DeferredList([d1, d2], fireOnOneErrback=1) |
494 def _do_notify_purge(self, result, node_id): | 495 def _do_notify_purge(self, result, node_id): |
495 self.parent.dispatch(node_id, '//event/pubsub/purge') | 496 self.parent.dispatch(node_id, '//event/pubsub/purge') |
496 | 497 |
497 class NodeDeletionService(service.Service): | 498 class NodeDeletionService(service.Service): |
498 | 499 |
499 __implements__ = INodeDeletionService, | 500 implements(INodeDeletionService) |
500 | 501 |
501 def __init__(self): | 502 def __init__(self): |
502 self._callback_list = [] | 503 self._callback_list = [] |
503 | 504 |
504 def register_pre_delete(self, pre_delete_fn): | 505 def register_pre_delete(self, pre_delete_fn): |