annotate idavoll/memory_backend.py @ 36:23b1dca64d06

More issues.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 31 Oct 2004 15:57:47 +0000
parents ff7c73b253bf
children 9aa20efac203
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 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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
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 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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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 },
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
90 '//event/pubsub/notify')
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
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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):
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
94
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
95 try:
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
96 d = defer.succeed(self.nodes[node_id].subscriptions.keys())
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
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
140 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
141 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
142 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
143 print self.nodes[node_id].items
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
144
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
145 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
146
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
147 __implements__ = backend.INodeCreationService,
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
148
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
149 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
150 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
151
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
152 class PublishService(service.Service):
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
153
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
154 __implements__ = backend.IPublishService,
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
155
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
156 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
157 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
158
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
159 class NotificationService(backend.NotificationService):
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 __implements__ = backend.INotificationService,
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
162
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
163 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
164 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
165
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
166 class SubscriptionService(service.Service):
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
167
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
168 __implements__ = backend.ISubscriptionService,
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
169
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
170 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
171 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
172
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
173 def unsubscribe(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
174 raise backend.NotImplemented
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
175
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
176 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
177
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
178 __implements__ = backend.IPersistenceService,
27
e6d62c93cd0a Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
179
30
ff7c73b253bf Recode backend to match interaces: one big Service that handles everything
Ralph Meijer <ralphm@ik.nu>
parents: 27
diff changeset
180 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
181 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
182