comparison idavoll/iidavoll.py @ 167:ef22e4150caa

Move protocol implementations (pubsub, disco, forms) to and depend on wokkel. Author: ralphm Fixes: #4
author Ralph Meijer <ralphm@ik.nu>
date Wed, 03 Oct 2007 12:41:43 +0000
parents
children 246911bcb699
comparison
equal deleted inserted replaced
166:5abb017bd687 167:ef22e4150caa
1 # Copyright (c) 2003-2007 Ralph Meijer
2 # See LICENSE for details.
3
4 """
5 Interfaces for idavoll.
6 """
7
8 from zope.interface import Interface
9
10 class IBackendService(Interface):
11 """ Interface to a backend service of a pubsub service. """
12
13 def __init__(storage):
14 """
15 @param storage: L{storage} object.
16 """
17
18 def supports_publisher_affiliation():
19 """ Reports if the backend supports the publisher affiliation.
20
21 @rtype: C{bool}
22 """
23
24 def supports_outcast_affiliation():
25 """ Reports if the backend supports the publisher affiliation.
26
27 @rtype: C{bool}
28 """
29
30 def supports_persistent_items():
31 """ Reports if the backend supports persistent items.
32
33 @rtype: C{bool}
34 """
35
36 def get_node_type(node_id):
37 """ Return type of a node.
38
39 @return: a deferred that returns either 'leaf' or 'collection'
40 """
41
42 def get_nodes():
43 """ Returns list of all nodes.
44
45 @return: a deferred that returns a C{list} of node ids.
46 """
47
48 def get_node_meta_data(node_id):
49 """ Return meta data for a node.
50
51 @return: a deferred that returns a C{list} of C{dict}s with the
52 metadata.
53 """
54
55 def create_node(node_id, requestor):
56 """ Create a node.
57
58 @return: a deferred that fires when the node has been created.
59 """
60
61 def register_pre_delete(pre_delete_fn):
62 """ Register a callback that is called just before a node deletion.
63
64 The function C{pre_deleted_fn} is added to a list of functions
65 to be called just before deletion of a node. The callback
66 C{pre_delete_fn} is called with the C{node_id} that is about to be
67 deleted and should return a deferred that returns a list of deferreds
68 that are to be fired after deletion. The backend collects the lists
69 from all these callbacks before actually deleting the node in question.
70 After deletion all collected deferreds are fired to do post-processing.
71
72 The idea is that you want to be able to collect data from the
73 node before deleting it, for example to get a list of subscribers
74 that have to be notified after the node has been deleted. To do this,
75 C{pre_delete_fn} fetches the subscriber list and passes this
76 list to a callback attached to a deferred that it sets up. This
77 deferred is returned in the list of deferreds.
78 """
79
80 def delete_node(node_id, requestor):
81 """ Delete a node.
82
83 @return: a deferred that fires when the node has been deleted.
84 """
85
86 def purge_node(node_id, requestor):
87 """ Removes all items in node from persistent storage """
88
89 def subscribe(node_id, subscriber, requestor):
90 """ Request the subscription of an entity to a pubsub node.
91
92 Depending on the node's configuration and possible business rules, the
93 C{subscriber} is added to the list of subscriptions of the node with id
94 C{node_id}. The C{subscriber} might be different from the C{requestor},
95 and if the C{requestor} is not allowed to subscribe this entity an
96 exception should be raised.
97
98 @return: a deferred that returns the subscription state
99 """
100
101 def unsubscribe(node_id, subscriber, requestor):
102 """ Cancel the subscription of an entity to a pubsub node.
103
104 The subscription of C{subscriber} is removed from the list of
105 subscriptions of the node with id C{node_id}. If the C{requestor}
106 is not allowed to unsubscribe C{subscriber}, an an exception should
107 be raised.
108
109 @return: a deferred that fires when unsubscription is complete.
110 """
111
112 def get_subscribers(node_id):
113 """ Get node subscriber list.
114
115 @return: a deferred that fires with the list of subscribers.
116 """
117
118 def get_subscriptions(entity):
119 """ Report the list of current subscriptions with this pubsub service.
120
121 Report the list of the current subscriptions with all nodes within this
122 pubsub service, for the C{entity}.
123
124 @return: a deferred that returns the list of all current subscriptions
125 as tuples C{(node_id, subscriber, subscription)}.
126 """
127
128 def get_affiliations(entity):
129 """ Report the list of current affiliations with this pubsub service.
130
131 Report the list of the current affiliations with all nodes within this
132 pubsub service, for the C{entity}.
133
134 @return: a deferred that returns the list of all current affiliations
135 as tuples C{(node_id, affiliation)}.
136 """
137
138 def publish(node_id, items, requestor):
139 """ Publish items to a pubsub node.
140
141 @return: a deferred that fires when the items have been published.
142 """
143
144 def register_notifier(observerfn, *args, **kwargs):
145 """ Register callback which is called for notification. """
146
147 def get_notification_list(node_id, items):
148 """
149 Get list of entities to notify.
150 """
151
152 def get_items(node_id, requestor, max_items=None, item_ids=[]):
153 """ Retrieve items from persistent storage
154
155 If C{max_items} is given, return the C{max_items} last published
156 items, else if C{item_ids} is not empty, return the items requested.
157 If neither is given, return all items.
158
159 @return: a deferred that returns the requested items
160 """
161
162 def retract_item(node_id, item_id, requestor):
163 """ Removes item in node from persistent storage """
164
165
166 class IStorage(Interface):
167 """
168 Storage interface.
169 """
170
171 def get_node(node_id):
172 """
173 Get Node.
174
175 @param node_id: NodeID of the desired node.
176 @type node_id: L{str}
177 @return: deferred that returns a L{Node} object.
178 """
179
180 def get_node_ids():
181 """
182 Return all NodeIDs.
183
184 @return: deferred that returns a list of NodeIDs (L{str}).
185 """
186
187 def create_node(node_id, owner, config = None, type='leaf'):
188 """
189 Create new node.
190
191 The implementation should make sure, the passed owner JID is stripped
192 of the resource (e.g. using C{owner.userhostJID()}).
193
194 @param node_id: NodeID of the new node.
195 @type node_id: L{str}
196 @param owner: JID of the new nodes's owner.
197 @type owner: L{jid.JID}
198 @param config: Configuration
199 @param type: Node type. Can be either C{'leaf'} or C{'collection'}.
200 @return: deferred that fires on creation.
201 """
202
203 def delete_node(node_id):
204 """
205 Delete a node.
206
207 @param node_id: NodeID of the new node.
208 @type node_id: L{str}
209 @return: deferred that fires on deletion.
210 """
211
212 def get_affiliations(entity):
213 """
214 Get all affiliations for entity.
215
216 The implementation should make sure, the passed owner JID is stripped
217 of the resource (e.g. using C{owner.userhostJID()}).
218
219 @param entity: JID of the entity.
220 @type entity: L{jid.JID}
221 @return: deferred that returns a L{list} of tuples of the form
222 C{(node_id, affiliation)}, where C{node_id} is of the type
223 L{str} and C{affiliation} is one of C{'owner'}, C{'publisher'}
224 and C{'outcast'}.
225 """
226
227 def get_subscriptions(entity):
228 """
229 Get all subscriptions for an entity.
230
231 The implementation should make sure, the passed owner JID is stripped
232 of the resource (e.g. using C{owner.userhostJID()}).
233
234 @param entity: JID of the entity.
235 @type entity: L{jid.JID}
236 @return: deferred that returns a L{list} of tuples of the form
237 C{(node_id, subscriber, state)}, where C{node_id} is of the
238 type L{str}, C{subscriber} of the type {jid.JID}, and
239 C{state} is C{'subscribed'} or C{'pending'}.
240 """
241
242
243 class INode(Interface):
244 """
245 Interface to the class of objects that represent nodes.
246 """
247
248 def get_type():
249 """
250 Get node's type.
251
252 @return: C{'leaf'} or C{'collection'}.
253 """
254
255 def get_configuration():
256 """
257 Get node's configuration.
258
259 The configuration must at least have two options:
260 C{pubsub#persist_items}, and C{pubsub#deliver_payloads}.
261
262 @return: L{dict} of configuration options.
263 """
264
265 def get_meta_data():
266 """
267 Get node's meta data.
268
269 The meta data must be a superset of the configuration options, and
270 also at least should have a C{pubsub#node_type} entry.
271
272 @return: L{dict} of meta data.
273 """
274
275 def set_configuration(options):
276 """
277 Set node's configuration.
278
279 The elements of {options} will set the new values for those
280 configuration items. This means that only changing items have to
281 be given.
282
283 @param options: a dictionary of configuration options.
284 @returns: a deferred that fires upon success.
285 """
286
287 def get_affiliation(entity):
288 """
289 Get affiliation of entity with this node.
290
291 @param entity: JID of entity.
292 @type entity: L{jid.JID}
293 @return: deferred that returns C{'owner'}, C{'publisher'}, C{'outcast'}
294 or C{None}.
295 """
296
297 def get_subscription(subscriber):
298 """
299 Get subscription to this node of subscriber.
300
301 @param subscriber: JID of the new subscriptions' entity.
302 @type subscriber: L{jid.JID}
303 @return: deferred that returns the subscription state (C{'subscribed'},
304 C{'pending'} or C{None}).
305 """
306
307 def add_subscription(subscriber, state):
308 """
309 Add new subscription to this node with given state.
310
311 @param subscriber: JID of the new subscriptions' entity.
312 @type subscriber: L{jid.JID}
313 @param state: C{'subscribed'} or C{'pending'}
314 @type state: L{str}
315 @return: deferred that fires on subscription.
316 """
317
318 def remove_subscription(subscriber):
319 """
320 Remove subscription to this node.
321
322 @param subscriber: JID of the subscriptions' entity.
323 @type subscriber: L{jid.JID}
324 @return: deferred that fires on removal.
325 """
326
327 def get_subscribers():
328 """
329 Get list of subscribers to this node.
330
331 Retrieves the list of entities that have a subscription to this
332 node. That is, having the state C{'subscribed'}.
333
334 @return: a deferred that returns a L{list} of L{jid.JID}s.
335 """
336
337 def is_subscribed(entity):
338 """
339 Returns whether entity has any subscription to this node.
340
341 Only returns C{True} when the subscription state (if present) is
342 C{'subscribed'} for any subscription that matches the bare JID.
343
344 @param subscriber: bare JID of the subscriptions' entity.
345 @type subscriber: L{jid.JID}
346 @return: deferred that returns a L{bool}.
347 """
348
349 def get_affiliations():
350 """
351 Get affiliations of entities with this node.
352
353 @return: deferred that returns a L{list} of tuples (jid, affiliation),
354 where jid is a L(jid.JID) and affiliation is one of C{'owner'},
355 C{'publisher'}, C{'outcast'}.
356 """
357
358 class ILeafNode(Interface):
359 """
360 Interface to the class of objects that represent leaf nodes.
361 """
362
363 def store_items(items, publisher):
364 """
365 Store items in persistent storage for later retrieval.
366
367 @param items: The list of items to be stored. Each item is the
368 L{domish} representation of the XML fragment as defined
369 for C{<item/>} in the
370 C{http://jabber.org/protocol/pubsub} namespace.
371 @type items: L{list} of {domish.Element}
372 @param publisher: JID of the publishing entity.
373 @type publisher: L{jid.JID}
374 @return: deferred that fires upon success.
375 """
376
377 def remove_items(item_ids):
378 """
379 Remove items by id.
380
381 @param item_ids: L{list} of item ids.
382 @return: deferred that fires with a L{list} of ids of the items that
383 were deleted
384 """
385
386 def get_items(max_items=None):
387 """
388 Get items.
389
390 If C{max_items} is not given, all items in the node are returned,
391 just like C{get_items_by_id}. Otherwise, C{max_items} limits
392 the returned items to a maximum of that number of most recently
393 published items.
394
395 @param max_items: if given, a natural number (>0) that limits the
396 returned number of items.
397 @return: deferred that fires with a L{list} of found items.
398 """
399
400 def get_items_by_id(item_ids):
401 """
402 Get items by item id.
403
404 Each item in the returned list is a unicode string that
405 represent the XML of the item as it was published, including the
406 item wrapper with item id.
407
408 @param item_ids: L{list} of item ids.
409 @return: deferred that fires with a L{list} of found items.
410 """
411
412 def purge():
413 """
414 Purge node of all items in persistent storage.
415
416 @return: deferred that fires when the node has been purged.
417 """