Mercurial > libervia-pubsub
annotate idavoll/memory_backend.py @ 37:9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
'subscribed' state.
Implement unsubscribe().
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sun, 31 Oct 2004 15:59:40 +0000 |
parents | ff7c73b253bf |
children | b9e7b3b6c687 |
rev | line source |
---|---|
27 | 1 from twisted.application import service |
2 from twisted.internet import defer | |
3 from twisted.protocols.jabber import jid | |
4 import backend | |
5 | |
6 class Subscription: | |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
7 def __init__(self, state): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
8 self.state = state |
27 | 9 |
10 class NodeConfiguration: | |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
11 def __init__(self): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
12 self.persist_items = False |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
13 self.deliver_payloads = False |
27 | 14 |
15 class Node: | |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
16 def __init__(self, id): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
17 self.id = id |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
18 self.configuration = NodeConfiguration() |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
19 self.subscriptions = {} |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
20 self.affiliations = {} |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
21 self.items = {} |
27 | 22 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
23 class BackendService(backend.BackendService): |
27 | 24 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
25 def __init__(self): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
26 backend.BackendService.__init__(self) |
27 | 27 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
28 self.nodes = {} |
27 | 29 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
30 node = Node("ralphm/mood/ralphm@ik.nu") |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
31 node.subscriptions["ralphm@doe.ik.nu"] = Subscription("subscribed") |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
32 node.subscriptions["notify@ik.nu/mood_monitor"] = Subscription("subscribed") |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
33 node.affiliations["ralphm@ik.nu"] = "owner" |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
34 node.affiliations["ralphm@doe.ik.nu"] = "publisher" |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
35 node.configuration.persist_items = True |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
36 node.configuration.deliver_payloads = True |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
37 self.nodes[node.id] = node |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
38 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
39 def get_supported_affiliations(self): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
40 return ['none', 'owner', 'outcast', 'publisher'] |
27 | 41 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
42 def create_node(self, node_id, requestor): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
43 if not node_id: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
44 raise backend.NoInstantNodes |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
45 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
46 if node_id in self.nodes: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
47 raise backend.NodeExists |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
48 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
49 node = Node(node_id) |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
50 node.affiliations[requestor.full()] = 'owner' |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
51 self.nodes[node_id] = node |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
52 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
53 return defer.succeed({'node_id': node.id}) |
27 | 54 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
55 def publish(self, node_id, items, requestor): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
56 try: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
57 node = self.nodes[node_id] |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
58 persist_items = node.configuration.persist_items |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
59 deliver_payloads = node.configuration.deliver_payloads |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
60 except KeyError: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
61 raise backend.NodeNotFound |
27 | 62 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
63 try: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
64 if node.affiliations[requestor.full()] not in \ |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
65 ['owner', 'publisher']: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
66 raise backend.NotAuthorized |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
67 except KeyError: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
68 raise backend.NotAuthorized |
27 | 69 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
70 if items and not persist_items and not deliver_payloads: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
71 raise backend.NoPayloadAllowed |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
72 elif not items and (persist_items or deliver_payloads): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
73 raise backend.PayloadExpected |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
74 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
75 print "publish by %s to %s" % (requestor.full(), node_id) |
27 | 76 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
77 if persist_items or deliver_payloads: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
78 for item in items: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
79 if item["id"] is None: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
80 item["id"] = 'random' # FIXME |
27 | 81 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
82 if persist_items: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
83 self.store_items(node_id, items, requestor) |
27 | 84 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
85 if items and not deliver_payloads: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
86 for item in items: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
87 item.children = [] |
27 | 88 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
89 self.dispatch({ 'items': items, 'node_id': node_id }, |
37
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
90 '//event/pubsub/notify') |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
91 return defer.succeed(None) |
27 | 92 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
93 def get_notification_list(self, node_id, items): |
37
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
94 subscriptions = self.nodes[node_id].subscriptions |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
95 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
96 try: |
37
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
97 subscribers = [s for s in subscriptions |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
98 if subscriptions[s].state == 'subscribed'] |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
99 d = defer.succeed(subscribers) |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
100 except: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
101 d = defer.fail() |
27 | 102 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
103 d.addCallback(self._magic_filter, node_id, items) |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
104 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
105 return d |
27 | 106 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
107 def _magic_filter(self, subscribers, node_id, items): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
108 list = {} |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
109 for subscriber in subscribers: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
110 list[subscriber] = items |
27 | 111 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
112 return list |
27 | 113 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
114 def subscribe(self, node_id, subscriber, requestor): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
115 # expect subscriber and requestor to be a jid.JID |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
116 try: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
117 node = self.nodes[node_id] |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
118 except KeyError: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
119 raise backend.NodeNotFound |
27 | 120 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
121 if subscriber.userhostJID() != requestor: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
122 raise backend.NotAuthorized |
27 | 123 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
124 affiliation = node.affiliations.get(subscriber.full(), 'none') |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
125 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
126 if affiliation == 'outcast': |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
127 raise backend.NotAuthorized |
27 | 128 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
129 try: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
130 subscription = node.subscriptions[subscriber.full()] |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
131 except KeyError: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
132 subscription = Subscription('subscribed') |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
133 node.subscriptions[subscriber.full()] = subscription |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
134 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
135 print node.subscriptions |
27 | 136 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
137 return defer.succeed({ |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
138 'affiliation': affiliation, |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
139 'node': node_id, |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
140 'jid': subscriber, |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
141 'subscription': subscription.state}) |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
142 |
37
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
143 def unsubscribe(self, node_id, subscriber, requestor): |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
144 try: |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
145 node = self.nodes[node_id] |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
146 except KeyError: |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
147 raise backend.NodeNotFound |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
148 |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
149 if subscriber.userhostJID() != requestor: |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
150 raise backend.NotAuthorized |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
151 |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
152 try: |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
153 del node.subscriptions[subscriber.full()] |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
154 except KeyError: |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
155 raise backend.NotSubscribed |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
156 |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
157 return defer.succeed(None) |
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
158 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
159 def store_items(self, node_id, items, publisher): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
160 for item in items: |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
161 self.nodes[node_id].items[item["id"]] = item |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
162 print self.nodes[node_id].items |
27 | 163 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
164 class NodeCreationService(service.Service): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
165 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
166 __implements__ = backend.INodeCreationService, |
27 | 167 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
168 def create_node(self, node_id, requestor): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
169 return self.parent.create_node(node_id, requestor) |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
170 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
171 class PublishService(service.Service): |
27 | 172 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
173 __implements__ = backend.IPublishService, |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
174 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
175 def publish(self, node_id, items, requestor): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
176 return self.parent.publish(node_id, items, requestor) |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
177 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
178 class NotificationService(backend.NotificationService): |
27 | 179 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
180 __implements__ = backend.INotificationService, |
27 | 181 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
182 def get_notification_list(self, node_id, items): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
183 return self.parent.get_notification_list(node_id, items) |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
184 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
185 class SubscriptionService(service.Service): |
27 | 186 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
187 __implements__ = backend.ISubscriptionService, |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
188 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
189 def subscribe(self, node_id, subscriber, requestor): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
190 return self.parent.subscribe(node_id, subscriber, requestor) |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
191 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
192 def unsubscribe(self, node_id, subscriber, requestor): |
37
9aa20efac203
Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents:
30
diff
changeset
|
193 return self.parent.unsubscribe(node_id, subscriber, requestor) |
27 | 194 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
195 class PersistenceService(service.Service): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
196 |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
197 __implements__ = backend.IPersistenceService, |
27 | 198 |
30
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
199 def store_items(self, node_id, items, publisher): |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
200 return self.parent.store_items(node_id, items, publisher) |
ff7c73b253bf
Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents:
27
diff
changeset
|
201 |