annotate idavoll/backend.py @ 205:e6b710bf2b24

Adjust node configuration to match wokkel API changes. Author: ralphm. Fixes #13.
author Ralph Meijer <ralphm@ik.nu>
date Mon, 04 Aug 2008 07:10:45 +0000
parents 77c61e2b8c75
children 274a45d2a5ab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
1 # -*- test-case-name: idavoll.test.test_backend -*-
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
2 #
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
3 # Copyright (c) 2003-2008 Ralph Meijer
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 153
diff changeset
4 # See LICENSE for details.
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 153
diff changeset
5
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
6 """
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
7 Generic publish-subscribe backend.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
8
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
9 This module implements a generic publish-subscribe backend service with
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
10 business logic as per
200
2189c663ba44 Epytext fixes.
Ralph Meijer <ralphm@ik.nu>
parents: 198
diff changeset
11 U{XEP-0060<http://www.xmpp.org/extensions/xep-0060.html>} that interacts with
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
12 a given storage facility. It also provides an adapter from the XMPP
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
13 publish-subscribe protocol.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
14 """
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
15
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
16 import uuid
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
17
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
18 from zope.interface import implements
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
19
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
20 from twisted.application import service
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
21 from twisted.python import components
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents: 181
diff changeset
22 from twisted.internet import defer, reactor
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
23 from twisted.words.protocols.jabber.error import StanzaError
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents: 181
diff changeset
24 from twisted.words.xish import domish, utility
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
25
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
26 from wokkel.iwokkel import IDisco, IPubSubService
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
27 from wokkel.pubsub import PubSubService, PubSubError
20
eddea65d1032 Added two exceptions: NoInstantNodes and NodeExists.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
28
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
29 from idavoll import error, iidavoll
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
30 from idavoll.iidavoll import IBackendService
15
46cd13c68ac0 Redone memory storage of nodes.
Ralph Meijer <ralphm@ik.nu>
parents: 5
diff changeset
31
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
32 def _getAffiliation(node, entity):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
33 d = node.getAffiliation(entity)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
34 d.addCallback(lambda affiliation: (node, affiliation))
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
35 return d
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 20
diff changeset
36
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
37
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
38
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
39 class BackendService(service.Service, utility.EventDispatcher):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
40 """
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
41 Generic publish-subscribe backend service.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
42
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
43 @cvar options: Node configuration form as a mapping from the field
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
44 name to a dictionary that holds the field's type,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
45 label and possible options to choose from.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
46 @type options: C{dict}.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
47 @cvar defaultConfig: The default node configuration.
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
48 """
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
49
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
50 implements(iidavoll.IBackendService)
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
51
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
52 options = {"pubsub#persist_items":
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
53 {"type": "boolean",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
54 "label": "Persist items to storage"},
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
55 "pubsub#deliver_payloads":
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
56 {"type": "boolean",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
57 "label": "Deliver payloads with event notifications"},
180
fc687620599b Properly add send_last_published_item configuration item.
Ralph Meijer <ralphm@ik.nu>
parents: 179
diff changeset
58 "pubsub#send_last_published_item":
fc687620599b Properly add send_last_published_item configuration item.
Ralph Meijer <ralphm@ik.nu>
parents: 179
diff changeset
59 {"type": "list-single",
181
Ralph Meijer <ralphm@ik.nu>
parents: 180
diff changeset
60 "label": "When to send the last published item",
Ralph Meijer <ralphm@ik.nu>
parents: 180
diff changeset
61 "options": {
Ralph Meijer <ralphm@ik.nu>
parents: 180
diff changeset
62 "never": "Never",
Ralph Meijer <ralphm@ik.nu>
parents: 180
diff changeset
63 "on_sub": "When a new subscription is processed",
Ralph Meijer <ralphm@ik.nu>
parents: 180
diff changeset
64 }
Ralph Meijer <ralphm@ik.nu>
parents: 180
diff changeset
65 },
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
66 }
159
6fe78048baf9 Rework error handling, depend on Twisted Words 0.4.0.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
67
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
68 defaultConfig = {"pubsub#persist_items": True,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
69 "pubsub#deliver_payloads": True,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
70 "pubsub#send_last_published_item": 'on_sub',
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
71 }
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
72
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
73 def __init__(self, storage):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
74 utility.EventDispatcher.__init__(self)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
75 self.storage = storage
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
76 self._callbackList = []
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
77
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
78
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
79 def supportsPublisherAffiliation(self):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
80 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
81
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
82
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
83 def supportsOutcastAffiliation(self):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
84 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
85
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
86
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
87 def supportsPersistentItems(self):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
88 return True
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
89
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
90
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
91 def getNodeType(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
92 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
93 d.addCallback(lambda node: node.getType())
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
94 return d
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
95
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
96
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
97 def getNodes(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
98 return self.storage.getNodeIds()
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
99
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
100
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
101 def getNodeMetaData(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
102 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
103 d.addCallback(lambda node: node.getMetaData())
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
104 d.addCallback(self._makeMetaData)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
105 return d
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
106
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
107
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
108 def _makeMetaData(self, metaData):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
109 options = []
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
110 for key, value in metaData.iteritems():
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
111 if self.options.has_key(key):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
112 option = {"var": key}
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
113 option.update(self.options[key])
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
114 option["value"] = value
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
115 options.append(option)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
116
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
117 return options
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
118
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
119
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
120 def _checkAuth(self, node, requestor):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
121 def check(affiliation, node):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
122 if affiliation not in ['owner', 'publisher']:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
123 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
124 return node
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
125
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
126 d = node.getAffiliation(requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
127 d.addCallback(check, node)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
128 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
129
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
130
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
131 def publish(self, nodeIdentifier, items, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
132 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
133 d.addCallback(self._checkAuth, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
134 d.addCallback(self._doPublish, items, requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
135 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
136
108
1c18759d2afb Moved two errors to storage.py.
Ralph Meijer <ralphm@ik.nu>
parents: 106
diff changeset
137
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
138 def _doPublish(self, node, items, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
139 configuration = node.getConfiguration()
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
140 persistItems = configuration["pubsub#persist_items"]
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
141 deliverPayloads = configuration["pubsub#deliver_payloads"]
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
142
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
143 if items and not persistItems and not deliverPayloads:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
144 raise error.ItemForbidden()
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
145 elif not items and (persistItems or deliverPayloads):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
146 raise error.ItemRequired()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
147
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
148 if persistItems or deliverPayloads:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
149 for item in items:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
150 if not item.getAttribute("id"):
168
e2c2c2baf483 Fix use of uuid module now shipping with Python 2.5.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
151 item["id"] = str(uuid.uuid4())
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
152
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
153 if persistItems:
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
154 d = node.storeItems(items, requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
155 else:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
156 d = defer.succeed(None)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
157
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
158 d.addCallback(self._doNotify, node.nodeIdentifier, items,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
159 deliverPayloads)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
160 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
161
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
162
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
163 def _doNotify(self, result, nodeIdentifier, items, deliverPayloads):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
164 if items and not deliverPayloads:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
165 for item in items:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
166 item.children = []
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
167
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
168 self.dispatch({'items': items, 'nodeIdentifier': nodeIdentifier},
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
169 '//event/pubsub/notify')
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
170
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
171
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
172 def getNotificationList(self, nodeIdentifier, items):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
173 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
174 d.addCallback(lambda node: node.getSubscribers())
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
175 d.addCallback(self._magicFilter, nodeIdentifier, items)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
176 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
177
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
178
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
179 def _magicFilter(self, subscribers, nodeIdentifier, items):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
180 list = []
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
181 for subscriber in subscribers:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
182 list.append((subscriber, items))
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
183 return list
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
184
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
185
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
186 def registerNotifier(self, observerfn, *args, **kwargs):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
187 self.addObserver('//event/pubsub/notify', observerfn, *args, **kwargs)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
188
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
189
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
190 def subscribe(self, nodeIdentifier, subscriber, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
191 subscriberEntity = subscriber.userhostJID()
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
192 if subscriberEntity != requestor:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
193 return defer.fail(error.Forbidden())
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
194
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
195 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
196 d.addCallback(_getAffiliation, subscriberEntity)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
197 d.addCallback(self._doSubscribe, subscriber)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
198 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
199
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
200
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
201 def _doSubscribe(self, result, subscriber):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
202 node, affiliation = result
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
203
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
204 if affiliation == 'outcast':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
205 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
206
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
207 d = node.addSubscription(subscriber, 'subscribed')
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
208 d.addCallback(lambda _: self._sendLastPublished(node, subscriber))
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
209 d.addCallback(lambda _: 'subscribed')
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
210 d.addErrback(self._getSubscription, node, subscriber)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
211 d.addCallback(self._returnSubscription, node.nodeIdentifier)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
212 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
213
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
214
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
215 def _getSubscription(self, failure, node, subscriber):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
216 failure.trap(error.SubscriptionExists)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
217 return node.getSubscription(subscriber)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
218
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
219
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
220 def _returnSubscription(self, result, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
221 return nodeIdentifier, result
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
222
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
223
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
224 def _sendLastPublished(self, node, subscriber):
183
c21b986cff30 Implement HTTP client to gateway and implement functional tests with it.
Ralph Meijer <ralphm@ik.nu>
parents: 181
diff changeset
225
202
77c61e2b8c75 Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents: 201
diff changeset
226 def notifyItem(items):
77c61e2b8c75 Use `domish.Element`s to represent items, instead of serialized XML.
Ralph Meijer <ralphm@ik.nu>
parents: 201
diff changeset
227 if not items:
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
228 return
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
229
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
230 reactor.callLater(0, self.dispatch,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
231 {'items': items,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
232 'nodeIdentifier': node.nodeIdentifier,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
233 'subscriber': subscriber},
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
234 '//event/pubsub/notify')
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
235
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
236 config = node.getConfiguration()
179
42e23a62b57f Guard against missing config for sending last published item on subscription.
Ralph Meijer <ralphm@ik.nu>
parents: 178
diff changeset
237 if config.get("pubsub#send_last_published_item", 'never') != 'on_sub':
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
238 return
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
239
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
240 d = self.getItems(node.nodeIdentifier, subscriber.userhostJID(), 1)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
241 d.addCallback(notifyItem)
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
242
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
243
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
244 def unsubscribe(self, nodeIdentifier, subscriber, requestor):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
245 if subscriber.userhostJID() != requestor:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
246 return defer.fail(error.Forbidden())
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
247
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
248 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
249 d.addCallback(lambda node: node.removeSubscription(subscriber))
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
250 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
251
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
252
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
253 def getSubscriptions(self, entity):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
254 return self.storage.getSubscriptions(entity)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
255
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
256
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
257 def supportsInstantNodes(self):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
258 return True
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
259
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
260
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
261 def createNode(self, nodeIdentifier, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
262 if not nodeIdentifier:
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
263 nodeIdentifier = 'generic/%s' % uuid.uuid4()
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
264 d = self.storage.createNode(nodeIdentifier, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
265 d.addCallback(lambda _: nodeIdentifier)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
266 return d
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
267
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
268
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
269 def getDefaultConfiguration(self):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
270 d = defer.succeed(self.defaultConfig)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
271 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
272
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
273
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
274 def getNodeConfiguration(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
275 if not nodeIdentifier:
196
00a6dbfbee42 Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
276 return defer.fail(error.NoRootNode())
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
277
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
278 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
279 d.addCallback(lambda node: node.getConfiguration())
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
280 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
281
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
282
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
283 def setNodeConfiguration(self, nodeIdentifier, options, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
284 if not nodeIdentifier:
196
00a6dbfbee42 Return deferreds on failure, instead of raising exceptions.
Ralph Meijer <ralphm@ik.nu>
parents: 183
diff changeset
285 return defer.fail(error.NoRootNode())
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
286
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
287 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
288 d.addCallback(_getAffiliation, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
289 d.addCallback(self._doSetNodeConfiguration, options)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
290 return d
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
291
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
292
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
293 def _doSetNodeConfiguration(self, result, options):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
294 node, affiliation = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
295
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
296 if affiliation != 'owner':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
297 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
298
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
299 return node.setConfiguration(options)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
300
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
301
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
302 def getAffiliations(self, entity):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
303 return self.storage.getAffiliations(entity)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
304
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
305
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
306 def getItems(self, nodeIdentifier, requestor, maxItems=None,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
307 itemIdentifiers=None):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
308 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
309 d.addCallback(_getAffiliation, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
310 d.addCallback(self._doGetItems, maxItems, itemIdentifiers)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
311 return d
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
312
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
313
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
314 def _doGetItems(self, result, maxItems, itemIdentifiers):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
315 node, affiliation = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
316
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
317 if affiliation == 'outcast':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
318 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
319
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
320 if itemIdentifiers:
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
321 return node.getItemsById(itemIdentifiers)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
322 else:
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
323 return node.getItems(maxItems)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
324
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
325
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
326 def retractItem(self, nodeIdentifier, itemIdentifiers, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
327 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
328 d.addCallback(_getAffiliation, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
329 d.addCallback(self._doRetract, itemIdentifiers)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
330 return d
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
331
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
332
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
333 def _doRetract(self, result, itemIdentifiers):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
334 node, affiliation = result
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
335 persistItems = node.getConfiguration()["pubsub#persist_items"]
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
336
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
337 if affiliation not in ['owner', 'publisher']:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
338 raise error.Forbidden()
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
339
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
340 if not persistItems:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
341 raise error.NodeNotPersistent()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
342
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
343 d = node.removeItems(itemIdentifiers)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
344 d.addCallback(self._doNotifyRetraction, node.nodeIdentifier)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
345 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
346
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
347
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
348 def _doNotifyRetraction(self, itemIdentifiers, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
349 self.dispatch({'itemIdentifiers': itemIdentifiers,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
350 'nodeIdentifier': nodeIdentifier },
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
351 '//event/pubsub/retract')
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
352
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
353
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
354 def purgeNode(self, nodeIdentifier, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
355 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
356 d.addCallback(_getAffiliation, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
357 d.addCallback(self._doPurge)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
358 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
359
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
360
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
361 def _doPurge(self, result):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
362 node, affiliation = result
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
363 persistItems = node.getConfiguration()["pubsub#persist_items"]
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
364
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
365 if affiliation != 'owner':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
366 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
367
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
368 if not persistItems:
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
369 raise error.NodeNotPersistent()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
370
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
371 d = node.purge()
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
372 d.addCallback(self._doNotifyPurge, node.nodeIdentifier)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
373 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
374
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
375
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
376 def _doNotifyPurge(self, result, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
377 self.dispatch(nodeIdentifier, '//event/pubsub/purge')
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
378
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
379
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
380 def registerPreDelete(self, preDeleteFn):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
381 self._callbackList.append(preDeleteFn)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
382
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
383
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
384 def getSubscribers(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
385 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
386 d.addCallback(lambda node: node.getSubscribers())
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
387 return d
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
388
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
389
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
390 def deleteNode(self, nodeIdentifier, requestor):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
391 d = self.storage.getNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
392 d.addCallback(_getAffiliation, requestor)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
393 d.addCallback(self._doPreDelete)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
394 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
395
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
396
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
397 def _doPreDelete(self, result):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
398 node, affiliation = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
399
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
400 if affiliation != 'owner':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
401 raise error.Forbidden()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
402
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
403 d = defer.DeferredList([cb(node.nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
404 for cb in self._callbackList],
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
405 consumeErrors=1)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
406 d.addCallback(self._doDelete, node.nodeIdentifier)
59
0fa161c00ed9 Use jid.JIDs everywhere in the backend.
Ralph Meijer <ralphm@ik.nu>
parents: 53
diff changeset
407
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
408
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
409 def _doDelete(self, result, nodeIdentifier):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
410 dl = []
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
411 for succeeded, r in result:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
412 if succeeded and r:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
413 dl.extend(r)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
414
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
415 d = self.storage.deleteNode(nodeIdentifier)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
416 d.addCallback(self._doNotifyDelete, dl)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
417
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
418 return d
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
419
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
420
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
421 def _doNotifyDelete(self, result, dl):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
422 for d in dl:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
423 d.callback(None)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
424
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
425
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
426
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
427 class PubSubServiceFromBackend(PubSubService):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
428 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
429 Adapts a backend to an xmpp publish-subscribe service.
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
430 """
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
431
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
432 implements(IDisco)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
433
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
434 _errorMap = {
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
435 error.NodeNotFound: ('item-not-found', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
436 error.NodeExists: ('conflict', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
437 error.Forbidden: ('forbidden', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
438 error.ItemForbidden: ('bad-request', 'item-forbidden', None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
439 error.ItemRequired: ('bad-request', 'item-required', None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
440 error.NoInstantNodes: ('not-acceptable',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
441 'unsupported',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
442 'instant-nodes'),
171
bc269696ef42 Reply with the correct error condition on subscription when not subscribed.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
443 error.NotSubscribed: ('unexpected-request', 'not-subscribed', None),
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
444 error.InvalidConfigurationOption: ('not-acceptable', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
445 error.InvalidConfigurationValue: ('not-acceptable', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
446 error.NodeNotPersistent: ('feature-not-implemented',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
447 'unsupported',
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
448 'persistent-node'),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
449 error.NoRootNode: ('bad-request', None, None),
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
450 }
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
451
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
452 def __init__(self, backend):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
453 PubSubService.__init__(self)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
454
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
455 self.backend = backend
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
456 self.hideNodes = False
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
457
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
458 self.pubSubFeatures = self._getPubSubFeatures()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
459
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
460 self.backend.registerNotifier(self._notify)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
461 self.backend.registerPreDelete(self._preDelete)
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
462
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
463
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
464 def _getPubSubFeatures(self):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
465 features = [
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
466 "config-node",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
467 "create-nodes",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
468 "delete-any",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
469 "delete-nodes",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
470 "item-ids",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
471 "meta-data",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
472 "publish",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
473 "purge-nodes",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
474 "retract-items",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
475 "retrieve-affiliations",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
476 "retrieve-default",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
477 "retrieve-items",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
478 "retrieve-subscriptions",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
479 "subscribe",
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
480 ]
153
753b8432460f Work towards JEP-0060 1.8
Ralph Meijer <ralphm@ik.nu>
parents: 108
diff changeset
481
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
482 if self.backend.supportsInstantNodes():
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
483 features.append("instant-nodes")
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
484
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
485 if self.backend.supportsOutcastAffiliation():
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
486 features.append("outcast-affiliation")
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
487
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
488 if self.backend.supportsPersistentItems():
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
489 features.append("persistent-items")
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
490
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
491 if self.backend.supportsPublisherAffiliation():
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
492 features.append("publisher-affiliation")
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
493
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
494 return features
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
495
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
496
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
497 def _notify(self, data):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
498 items = data['items']
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
499 nodeIdentifier = data['nodeIdentifier']
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
500 if 'subscriber' not in data:
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
501 d = self.backend.getNotificationList(nodeIdentifier, items)
178
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
502 else:
07114105885a Send last published item on subscription if node is so configured.
Ralph Meijer <ralphm@ik.nu>
parents: 174
diff changeset
503 d = defer.succeed([(data['subscriber'], items)])
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
504 d.addCallback(lambda notifications: self.notifyPublish(self.serviceJID,
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
505 nodeIdentifier,
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
506 notifications))
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
507
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
508
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
509 def _preDelete(self, nodeIdentifier):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
510 d = self.backend.getSubscribers(nodeIdentifier)
174
79d451d186b1 Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
511 d.addCallback(lambda subscribers: self.notifyDelete(self.serviceJID,
79d451d186b1 Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
512 nodeIdentifier,
79d451d186b1 Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
513 subscribers))
79d451d186b1 Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
514 return d
79d451d186b1 Send out node deletion notifications.
Ralph Meijer <ralphm@ik.nu>
parents: 172
diff changeset
515
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
516
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
517 def _mapErrors(self, failure):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
518 e = failure.trap(*self._errorMap.keys())
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
519
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
520 condition, pubsubCondition, feature = self._errorMap[e]
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
521 msg = failure.value.msg
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
522
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
523 if pubsubCondition:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
524 exc = PubSubError(condition, pubsubCondition, feature, msg)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
525 else:
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
526 exc = StanzaError(condition, text=msg)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
527
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
528 raise exc
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
529
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
530
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
531 def getNodeInfo(self, requestor, service, nodeIdentifier):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
532 info = {}
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
533
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
534 def saveType(result):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
535 info['type'] = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
536 return nodeIdentifier
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
537
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
538 def saveMetaData(result):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
539 info['meta-data'] = result
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
540 return info
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
541
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
542 d = defer.succeed(nodeIdentifier)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
543 d.addCallback(self.backend.getNodeType)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
544 d.addCallback(saveType)
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
545 d.addCallback(self.backend.getNodeMetaData)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
546 d.addCallback(saveMetaData)
172
9bfb00edd0cc Fix Backend's getNodeInfo so that it properly adds its errback.
Ralph Meijer <ralphm@ik.nu>
parents: 171
diff changeset
547 d.addErrback(self._mapErrors)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
548 return d
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
549
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
550
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
551 def getNodes(self, requestor, service):
169
96afb248df5e Fix typos in service creation. Make disco not respond when a resource is provided.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
552 if service.resource:
96afb248df5e Fix typos in service creation. Make disco not respond when a resource is provided.
Ralph Meijer <ralphm@ik.nu>
parents: 168
diff changeset
553 return defer.succeed([])
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
554 d = self.backend.getNodes()
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
555 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
556
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
557
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
558 def publish(self, requestor, service, nodeIdentifier, items):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
559 d = self.backend.publish(nodeIdentifier, items, requestor)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
560 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
561
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
562
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
563 def subscribe(self, requestor, service, nodeIdentifier, subscriber):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
564 d = self.backend.subscribe(nodeIdentifier, subscriber, requestor)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
565 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
566
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
567
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
568 def unsubscribe(self, requestor, service, nodeIdentifier, subscriber):
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
569 d = self.backend.unsubscribe(nodeIdentifier, subscriber, requestor)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
570 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
571
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
572
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
573 def subscriptions(self, requestor, service):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
574 d = self.backend.getSubscriptions(requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
575 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
576
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
577
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
578 def affiliations(self, requestor, service):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
579 d = self.backend.getAffiliations(requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
580 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
581
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
582
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
583 def create(self, requestor, service, nodeIdentifier):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
584 d = self.backend.createNode(nodeIdentifier, requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
585 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
586
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
587
205
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
588 def getConfigurationOptions(self):
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
589 return self.backend.options
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
590
e6b710bf2b24 Adjust node configuration to match wokkel API changes.
Ralph Meijer <ralphm@ik.nu>
parents: 202
diff changeset
591
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
592 def getDefaultConfiguration(self, requestor, service):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
593 d = self.backend.getDefaultConfiguration()
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
594 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
595
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
596
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
597 def getConfiguration(self, requestor, service, nodeIdentifier):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
598 d = self.backend.getNodeConfiguration(nodeIdentifier)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
599 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
600
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
601
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
602 def setConfiguration(self, requestor, service, nodeIdentifier, options):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
603 d = self.backend.setNodeConfiguration(nodeIdentifier, options,
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
604 requestor)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
605 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
606
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
607
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
608 def items(self, requestor, service, nodeIdentifier, maxItems,
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
609 itemIdentifiers):
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
610 d = self.backend.getItems(nodeIdentifier, requestor, maxItems,
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
611 itemIdentifiers)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
612 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
613
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
614
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
615 def retract(self, requestor, service, nodeIdentifier, itemIdentifiers):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
616 d = self.backend.retractItem(nodeIdentifier, itemIdentifiers,
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
617 requestor)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
618 return d.addErrback(self._mapErrors)
29
d4fc29bb5381 Define interfaces of blocks of functionality.
Ralph Meijer <ralphm@ik.nu>
parents: 24
diff changeset
619
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
620
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
621 def purge(self, requestor, service, nodeIdentifier):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
622 d = self.backend.purgeNode(nodeIdentifier, requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
623 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
624
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
625
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
626 def delete(self, requestor, service, nodeIdentifier):
198
e404775b12df Change naming and spacing conventions to match Twisted's.
Ralph Meijer <ralphm@ik.nu>
parents: 196
diff changeset
627 d = self.backend.deleteNode(nodeIdentifier, requestor)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
628 return d.addErrback(self._mapErrors)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
629
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
630 components.registerAdapter(PubSubServiceFromBackend,
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
631 IBackendService,
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 159
diff changeset
632 IPubSubService)