Mercurial > libervia-pubsub
comparison idavoll/pubsub.py @ 153:753b8432460f
Work towards JEP-0060 1.8
- Remove subscription information from <affiliations/> result.
- Add handling of <subscriptions/> entity use case.
- Make <subscribe/> return <subscription/> instead of <entity/>.
- Move <purge/> and <delete/> to owner namespace.
- Don't use 'self' in interfaces.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sat, 06 May 2006 19:47:53 +0000 |
parents | ea8b4189ae3b |
children | bd8e58c73370 |
comparison
equal
deleted
inserted
replaced
152:ea8b4189ae3b | 153:753b8432460f |
---|---|
37 PUBSUB_UNSUBSCRIBE = PUBSUB_SET + '/unsubscribe' | 37 PUBSUB_UNSUBSCRIBE = PUBSUB_SET + '/unsubscribe' |
38 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options' | 38 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options' |
39 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options' | 39 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options' |
40 PUBSUB_CONFIGURE_GET = PUBSUB_OWNER_GET + '/configure' | 40 PUBSUB_CONFIGURE_GET = PUBSUB_OWNER_GET + '/configure' |
41 PUBSUB_CONFIGURE_SET = PUBSUB_OWNER_SET + '/configure' | 41 PUBSUB_CONFIGURE_SET = PUBSUB_OWNER_SET + '/configure' |
42 PUBSUB_SUBSCRIPTIONS = PUBSUB_GET + '/subscriptions' | |
42 PUBSUB_AFFILIATIONS = PUBSUB_GET + '/affiliations' | 43 PUBSUB_AFFILIATIONS = PUBSUB_GET + '/affiliations' |
43 PUBSUB_ITEMS = PUBSUB_GET + '/items' | 44 PUBSUB_ITEMS = PUBSUB_GET + '/items' |
44 PUBSUB_RETRACT = PUBSUB_SET + '/retract' | 45 PUBSUB_RETRACT = PUBSUB_SET + '/retract' |
45 PUBSUB_PURGE = PUBSUB_SET + '/purge' | 46 PUBSUB_PURGE = PUBSUB_OWNER_SET + '/purge' |
46 PUBSUB_DELETE = PUBSUB_SET + '/delete' | 47 PUBSUB_DELETE = PUBSUB_OWNER_SET + '/delete' |
47 | 48 |
48 class Error(Exception): | 49 class Error(Exception): |
49 pubsub_error = None | 50 pubsub_error = None |
50 stanza_error = None | 51 stanza_error = None |
51 msg = '' | 52 msg = '' |
268 def componentConnected(self, xmlstream): | 269 def componentConnected(self, xmlstream): |
269 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe) | 270 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe) |
270 xmlstream.addObserver(PUBSUB_UNSUBSCRIBE, self.onUnsubscribe) | 271 xmlstream.addObserver(PUBSUB_UNSUBSCRIBE, self.onUnsubscribe) |
271 xmlstream.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet) | 272 xmlstream.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet) |
272 xmlstream.addObserver(PUBSUB_OPTIONS_SET, self.onOptionsSet) | 273 xmlstream.addObserver(PUBSUB_OPTIONS_SET, self.onOptionsSet) |
274 xmlstream.addObserver(PUBSUB_SUBSCRIPTIONS, self.onSubscriptions) | |
273 | 275 |
274 def get_disco_info(self, node): | 276 def get_disco_info(self, node): |
275 info = [] | 277 info = [] |
276 | 278 |
277 if not node: | 279 if not node: |
278 info.append(disco.Feature(NS_PUBSUB + '#subscribe')) | 280 info.append(disco.Feature(NS_PUBSUB + '#subscribe')) |
281 info.append(disco.Feature(NS_PUBSUB + '#retrieve-subscriptions')) | |
279 | 282 |
280 return defer.succeed(info) | 283 return defer.succeed(info) |
281 | 284 |
282 def onSubscribe(self, iq): | 285 def onSubscribe(self, iq): |
283 self.handler_wrapper(self._onSubscribe, iq) | 286 self.handler_wrapper(self._onSubscribe, iq) |
293 d = self.backend.subscribe(node_id, subscriber, requestor) | 296 d = self.backend.subscribe(node_id, subscriber, requestor) |
294 d.addCallback(self.return_subscription, subscriber) | 297 d.addCallback(self.return_subscription, subscriber) |
295 return d | 298 return d |
296 | 299 |
297 def return_subscription(self, result, subscriber): | 300 def return_subscription(self, result, subscriber): |
301 node, state = result | |
302 | |
298 reply = domish.Element((NS_PUBSUB, "pubsub")) | 303 reply = domish.Element((NS_PUBSUB, "pubsub")) |
299 entity = reply.addElement("entity") | 304 subscription = reply.addElement("subscription") |
300 entity["node"] = result["node"] | 305 subscription["node"] = nod |
301 entity["jid"] = subscriber.full() | 306 subscription["jid"] = subscriber.full() |
302 entity["affiliation"] = result["affiliation"] or 'none' | 307 subscription["subscription"] = state |
303 entity["subscription"] = result["state"] | |
304 return [reply] | 308 return [reply] |
305 | 309 |
306 def onUnsubscribe(self, iq): | 310 def onUnsubscribe(self, iq): |
307 self.handler_wrapper(self._onUnsubscribe, iq) | 311 self.handler_wrapper(self._onUnsubscribe, iq) |
308 | 312 |
325 def onOptionsSet(self, iq): | 329 def onOptionsSet(self, iq): |
326 self.handler_wrapper(self._onOptionsSet, iq) | 330 self.handler_wrapper(self._onOptionsSet, iq) |
327 | 331 |
328 def _onOptionsSet(self, iq): | 332 def _onOptionsSet(self, iq): |
329 raise OptionsUnavailable | 333 raise OptionsUnavailable |
334 | |
335 def onSubscriptions(self, iq): | |
336 self.handler_wrapper(self._onSubscriptions, iq) | |
337 | |
338 def _onSubscriptions(self, iq): | |
339 entity = jid.internJID(iq["from"]).userhostJID() | |
340 d = self.backend.get_subscriptions(entity) | |
341 d.addCallback(self._return_subscriptions_response, iq) | |
342 return d | |
343 | |
344 def _return_subscriptions_response(self, result, iq): | |
345 reply = domish.Element((NS_PUBSUB, 'pubsub')) | |
346 subscriptions = reply.addElement('subscriptions') | |
347 for node, subscriber, state in result: | |
348 item = subscriptions.addElement('subscription') | |
349 item['node'] = node | |
350 item['jid'] = subscriber.full() | |
351 item['subscription'] = state | |
352 return [reply] | |
330 | 353 |
331 components.registerAdapter(ComponentServiceFromSubscriptionService, | 354 components.registerAdapter(ComponentServiceFromSubscriptionService, |
332 backend.ISubscriptionService, | 355 backend.ISubscriptionService, |
333 component.IService) | 356 component.IService) |
334 | 357 |
470 return d | 493 return d |
471 | 494 |
472 def _return_affiliations_response(self, result, iq): | 495 def _return_affiliations_response(self, result, iq): |
473 reply = domish.Element((NS_PUBSUB, 'pubsub')) | 496 reply = domish.Element((NS_PUBSUB, 'pubsub')) |
474 affiliations = reply.addElement('affiliations') | 497 affiliations = reply.addElement('affiliations') |
475 for r in result: | 498 for node, affiliation in result: |
476 entity = affiliations.addElement('entity') | 499 item = affiliations.addElement('affiliation') |
477 entity['node'] = r['node'] | 500 item['node'] = node |
478 entity['jid'] = r['jid'].full() | 501 item['affiliation'] = affiliation |
479 entity['affiliation'] = r['affiliation'] or 'none' | |
480 entity['subscription'] = r['subscription'] or 'none' | |
481 return [reply] | 502 return [reply] |
482 | 503 |
483 components.registerAdapter(ComponentServiceFromAffiliationsService, | 504 components.registerAdapter(ComponentServiceFromAffiliationsService, |
484 backend.IAffiliationsService, | 505 backend.IAffiliationsService, |
485 component.IService) | 506 component.IService) |