comparison src/plugins/plugin_xep_0060.py @ 2360:72cbb6478f97

plugin XEP-0060: use client instead of profile_key in getItems
author Goffi <goffi@goffi.org>
date Sun, 24 Sep 2017 16:32:22 +0200
parents 6c26f435a02d
children 5675af905725
comparison
equal deleted inserted replaced
2359:47516e90d26a 2360:72cbb6478f97
315 def _getItems(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, profile_key=C.PROF_KEY_NONE): 315 def _getItems(self, service='', node='', max_items=10, item_ids=None, sub_id=None, extra_dict=None, profile_key=C.PROF_KEY_NONE):
316 """Get items from pubsub node 316 """Get items from pubsub node
317 317
318 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit 318 @param max_items(int): maximum number of item to get, C.NO_LIMIT for no limit
319 """ 319 """
320 client = self.host.getClient(profile_key)
320 service = jid.JID(service) if service else None 321 service = jid.JID(service) if service else None
321 max_items = None if max_items == C.NO_LIMIT else max_items 322 max_items = None if max_items == C.NO_LIMIT else max_items
322 extra = self.parseExtra(extra_dict) 323 extra = self.parseExtra(extra_dict)
323 d = self.getItems(service, node or None, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra, profile_key) 324 d = self.getItems(client, service, node or None, max_items or None, item_ids, sub_id or None, extra.rsm_request, extra.extra)
324 d.addCallback(self.serItemsData) 325 d.addCallback(self.serItemsData)
325 return d 326 return d
326 327
327 def getItems(self, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None, profile_key=C.PROF_KEY_NONE): 328 def getItems(self, client, service, node, max_items=None, item_ids=None, sub_id=None, rsm_request=None, extra=None):
328 """Retrieve pubsub items from a node. 329 """Retrieve pubsub items from a node.
329 330
330 @param service (JID, None): pubsub service. 331 @param service (JID, None): pubsub service.
331 @param node (str): node id. 332 @param node (str): node id.
332 @param max_items (int): optional limit on the number of retrieved items. 333 @param max_items (int): optional limit on the number of retrieved items.
333 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be used with rsm_request). 334 @param item_ids (list[str]): identifiers of the items to be retrieved (can't be used with rsm_request).
334 @param sub_id (str): optional subscription identifier. 335 @param sub_id (str): optional subscription identifier.
335 @param rsm_request (rsm.RSMRequest): RSM request data 336 @param rsm_request (rsm.RSMRequest): RSM request data
336 @param profile_key (unicode): %(doc_profile_key)s
337 @return: a deferred couple (list[dict], dict) containing: 337 @return: a deferred couple (list[dict], dict) containing:
338 - list of items 338 - list of items
339 - metadata with the following keys: 339 - metadata with the following keys:
340 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index value of RSMResponse 340 - rsm_first, rsm_last, rsm_count, rsm_index: first, last, count and index value of RSMResponse
341 - service, node: service and node used 341 - service, node: service and node used
344 max_items = None 344 max_items = None
345 if rsm_request and item_ids: 345 if rsm_request and item_ids:
346 raise ValueError(u"items_id can't be used with rsm") 346 raise ValueError(u"items_id can't be used with rsm")
347 if extra is None: 347 if extra is None:
348 extra = {} 348 extra = {}
349 client = self.host.getClient(profile_key)
350 try: 349 try:
351 mam_query = extra['mam'] 350 mam_query = extra['mam']
352 except KeyError: 351 except KeyError:
353 d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, None, rsm_request) 352 d = client.pubsub_client.items(service, node, max_items, item_ids, sub_id, None, rsm_request)
354 else: 353 else:
378 def subscribeEb(failure, service, node): 377 def subscribeEb(failure, service, node):
379 failure.trap(error.StanzaError) 378 failure.trap(error.StanzaError)
380 log.warning(u"Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value))) 379 log.warning(u"Could not subscribe to node {} on service {}: {}".format(node, unicode(service), unicode(failure.value)))
381 380
382 def doSubscribe(items): 381 def doSubscribe(items):
383 self.subscribe(service, node, profile_key=profile_key).addErrback(subscribeEb, service, node) 382 self.subscribe(service, node, profile_key=client.profile_key).addErrback(subscribeEb, service, node)
384 return items 383 return items
385 384
386 if subscribe: 385 if subscribe:
387 d.addCallback(doSubscribe) 386 d.addCallback(doSubscribe)
388 387
401 return d 400 return d
402 401
403 # @defer.inlineCallbacks 402 # @defer.inlineCallbacks
404 # def getItemsFromMany(self, service, data, max_items=None, sub_id=None, rsm=None, profile_key=C.PROF_KEY_NONE): 403 # def getItemsFromMany(self, service, data, max_items=None, sub_id=None, rsm=None, profile_key=C.PROF_KEY_NONE):
405 # """Massively retrieve pubsub items from many nodes. 404 # """Massively retrieve pubsub items from many nodes.
406
407 # @param service (JID): target service. 405 # @param service (JID): target service.
408 # @param data (dict): dictionnary binding some arbitrary keys to the node identifiers. 406 # @param data (dict): dictionnary binding some arbitrary keys to the node identifiers.
409 # @param max_items (int): optional limit on the number of retrieved items *per node*. 407 # @param max_items (int): optional limit on the number of retrieved items *per node*.
410 # @param sub_id (str): optional subscription identifier. 408 # @param sub_id (str): optional subscription identifier.
411 # @param rsm (dict): RSM request data 409 # @param rsm (dict): RSM request data
852 @return (str): RT Deferred session id 850 @return (str): RT Deferred session id
853 """ 851 """
854 client = self.host.getClient(profile_key) 852 client = self.host.getClient(profile_key)
855 deferreds = {} 853 deferreds = {}
856 for service, node in node_data: 854 for service, node in node_data:
857 deferreds[(service, node)] = self.getItems(service, node, max_item, rsm_request=rsm_request, extra=extra, profile_key=profile_key) 855 deferreds[(service, node)] = self.getItems(client, service, node, max_item, rsm_request=rsm_request, extra=extra)
858 return self.rt_sessions.newSession(deferreds, client.profile) 856 return self.rt_sessions.newSession(deferreds, client.profile)
859 857
860 858
861 class SatPubSubClient(rsm.PubSubClient): 859 class SatPubSubClient(rsm.PubSubClient):
862 implements(disco.IDisco) 860 implements(disco.IDisco)