annotate idavoll/memory_backend.py @ 41:ea3d3544a52e

Rewrite using separated backend interfaces. The backend also uses a separate class for the actual storage.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 31 Oct 2004 21:11:03 +0000
parents b9e7b3b6c687
children 9685b7e291ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
1 from twisted.application import service
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
2 from twisted.internet import defer
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
3 from twisted.protocols.jabber import jid
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
4 import backend
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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 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
40 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
41 raise backend.NoInstantNodes
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
42
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
43 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
44 raise backend.NodeExists
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 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
47 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
48 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
49
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
50 return defer.succeed({'node_id': node.id})
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
51
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
52 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
53 try:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
54 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
55 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
56 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
57 except KeyError:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
58 raise backend.NodeNotFound
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
59
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
60 try:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
61 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
62 ['owner', 'publisher']:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
63 raise backend.NotAuthorized
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
64 except KeyError:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
65 raise backend.NotAuthorized
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
66
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
67 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
68 raise backend.NoPayloadAllowed
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
69 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
70 raise backend.PayloadExpected
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
71
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
72 print "publish by %s to %s" % (requestor.full(), node_id)
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
73
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
74 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
75 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
76 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
77 item["id"] = 'random' # FIXME
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
78
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
79 if persist_items:
40
b9e7b3b6c687 Moved get_supported_affiliations() to super class.
Ralph Meijer <ralphm@ik.nu>
parents: 37
diff changeset
80 self.store_items(node_id, items, requestor.full())
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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 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
83 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
84 item.children = []
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
85
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
86 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
87 '//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
88 return defer.succeed(None)
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
89
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
90 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
91 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
92
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
93 try:
37
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
94 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
95 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
96 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
97 except:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
98 d = defer.fail()
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
99
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
100 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
101
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
102 return d
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
103
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
104 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
105 list = {}
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
106 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
107 list[subscriber] = items
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
108
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
109 return list
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
110
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
111 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
112 # 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
113 try:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
114 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
115 except KeyError:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
116 raise backend.NodeNotFound
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
117
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
118 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
119 raise backend.NotAuthorized
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
120
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
121 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
122
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
123 if affiliation == 'outcast':
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
124 raise backend.NotAuthorized
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
125
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
126 try:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
127 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
128 except KeyError:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
129 subscription = Subscription('subscribed')
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
130 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
131
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
132 print node.subscriptions
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
133
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
134 return defer.succeed({
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
135 'affiliation': affiliation,
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
136 'node': node_id,
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
137 'jid': subscriber,
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
138 'subscription': subscription.state})
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
139
37
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
140 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
141 try:
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
142 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
143 except KeyError:
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
144 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
145
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
146 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
147 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
148
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
149 try:
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
150 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
151 except KeyError:
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
152 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
153
9aa20efac203 Fix get_notification_list() to only return JIDs for subscriptions in the
Ralph Meijer <ralphm@ik.nu>
parents: 30
diff changeset
154 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
155
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
156 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
157 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
158 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
159 print self.nodes[node_id].items
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
160
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
161 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
162
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
163 __implements__ = backend.INodeCreationService,
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
164
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
165 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
166 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
167
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
168 class PublishService(service.Service):
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
169
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
170 __implements__ = backend.IPublishService,
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
171
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
172 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
173 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
174
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
175 class NotificationService(backend.NotificationService):
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
176
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
177 __implements__ = backend.INotificationService,
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
178
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
179 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
180 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
181
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
182 class SubscriptionService(service.Service):
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
183
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
184 __implements__ = backend.ISubscriptionService,
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
185
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
186 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
187 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
188
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
189 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
190 return self.parent.unsubscribe(node_id, subscriber, requestor)
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
191
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
192 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
193
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
194 __implements__ = backend.IPersistenceService,
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
195
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
196 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
197 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
198