Mercurial > libervia-pubsub
comparison idavoll/backend.py @ 2:9701df89c534
First take at notifications
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Fri, 25 Jun 2004 20:31:14 +0000 |
parents | 4cc41776b7d7 |
children | 05a5d412e1b1 |
comparison
equal
deleted
inserted
replaced
1:4cc41776b7d7 | 2:9701df89c534 |
---|---|
2 from twisted.python import components, failure | 2 from twisted.python import components, failure |
3 from twisted.internet import defer, reactor | 3 from twisted.internet import defer, reactor |
4 | 4 |
5 class IBackendService(components.Interface): | 5 class IBackendService(components.Interface): |
6 """ Interface to a backend service of a pubsub service """ | 6 """ Interface to a backend service of a pubsub service """ |
7 | |
8 def do_publish(self, node, publisher, item): | |
9 """ Returns a deferred that returns """ | |
7 | 10 |
8 class BackendException(Exception): | 11 class BackendException(Exception): |
9 def __init__(self, msg = ''): | 12 def __init__(self, msg = ''): |
10 self.msg = msg | 13 self.msg = msg |
11 | 14 |
24 | 27 |
25 __implements__ = IBackendService, | 28 __implements__ = IBackendService, |
26 | 29 |
27 def __init__(self): | 30 def __init__(self): |
28 self.nodes = {"ralphm/test": 'test'} | 31 self.nodes = {"ralphm/test": 'test'} |
29 self.subscribers = {"ralphm/test": ["ralphm@ik.nu", "intosi@ik.nu"] } | 32 self.subscribers = {"ralphm/test": ["ralphm@ik.nu", "ralphm@doe.ik.nu"] } |
30 self.affiliations = {"ralphm/test": { "ralphm@ik.nu": "owner", "ralphm@se-135.se.wtb.tue.nl": 'publisher' } } | 33 self.affiliations = {"ralphm/test": { "ralphm@ik.nu": "owner", "ralphm@se-135.se.wtb.tue.nl": 'publisher', 'ralphm@doe.ik.nu': 'publisher' } } |
31 | 34 |
32 def do_publish(self, node, publisher, item): | 35 def do_publish(self, node, publisher, item): |
33 try: | 36 try: |
34 try: | 37 try: |
35 result = self.nodes[node] | 38 result = self.nodes[node] |
40 affiliation = self.affiliations[node][publisher] | 43 affiliation = self.affiliations[node][publisher] |
41 if affiliation not in ['owner', 'publisher']: | 44 if affiliation not in ['owner', 'publisher']: |
42 raise NotAuthorized | 45 raise NotAuthorized |
43 except KeyError: | 46 except KeyError: |
44 raise NotAuthorized() | 47 raise NotAuthorized() |
48 | |
45 print "publish by %s to %s" % (publisher, node) | 49 print "publish by %s to %s" % (publisher, node) |
50 | |
51 recipients = self.get_subscribers(node) | |
52 recipients.addCallback(self.magic_filter, node, item) | |
53 recipients.addCallback(self.pubsub_service.do_notification, node, item) | |
54 | |
46 return defer.succeed(result) | 55 return defer.succeed(result) |
47 except: | 56 except: |
48 f = failure.Failure() | 57 f = failure.Failure() |
49 return defer.fail(f) | 58 return defer.fail(f) |
59 | |
60 def magic_filter(self, subscribers, node, item): | |
61 return subscribers | |
50 | 62 |
51 def get_subscribers(self, node): | 63 def get_subscribers(self, node): |
52 d = defer.Deferred() | 64 d = defer.Deferred() |
53 try: | 65 try: |
54 result = self.subscribers[node] | 66 result = self.subscribers[node] |