comparison src/plugins/plugin_misc_groupblog.py @ 1423:882e5fabf68c

plugin groupblog, tmp (mam, rsm): some style improvments/fixes: - renamed variables nammed after reserved word/module - removed class variables which are not needed - removed external parenthesis from asserts - in mam.MAMPrefs, removed default value for default argument, as None can't be used - (groupblog) extended docstring for DeferredItems and DeferredItemsFromMany
author Goffi <goffi@goffi.org>
date Thu, 23 Apr 2015 13:35:21 +0200
parents 7c0acb966fd6
children 7f8af1e69812
comparison
equal deleted inserted replaced
1422:be1fccf4854d 1423:882e5fabf68c
492 492
493 return self._initialise(profile_key).addCallback(initialised) 493 return self._initialise(profile_key).addCallback(initialised)
494 494
495 ## get ## 495 ## get ##
496 496
497 def _getOrCountComments(self, items, max=0, profile_key=C.PROF_KEY_NONE): 497 def _getOrCountComments(self, items, max_=0, profile_key=C.PROF_KEY_NONE):
498 """Get and/or count the comments of the given items. 498 """Get and/or count the comments of the given items.
499 499
500 @param items (list): items to consider. 500 @param items (list): items to consider.
501 @param max (int): maximum number of comments to get, if 0 only count 501 @param max_ (int): maximum number of comments to get, if 0 only count
502 them. The count is set to the item data of key "comments_count". 502 them. The count is set to the item data of key "comments_count".
503 @param profile_key (str): %(doc_profile_key)s 503 @param profile_key (str): %(doc_profile_key)s
504 @return: a deferred list of: 504 @return: a deferred list of:
505 - if max == 0: microblog data 505 - if max_ == 0: microblog data
506 - else: couple (dict, (list[dict], dict)) containing: 506 - else: couple (dict, (list[dict], dict)) containing:
507 - microblog data (main item) 507 - microblog data (main item)
508 - couple (comments data, RSM response data for the comments) 508 - couple (comments data, RSM response data for the comments)
509 """ 509 """
510 def comments_cb(comments_data, entry): 510 def comments_cb(comments_data, entry):
511 entry['comments_count'] = comments_data[1]['count'] 511 entry['comments_count'] = comments_data[1]['count']
512 return (entry, comments_data) if max > 0 else entry 512 return (entry, comments_data) if max_ > 0 else entry
513 513
514 assert(max >= 0) 514 assert max_ >= 0
515 d_list = [] 515 d_list = []
516 for entry in items: 516 for entry in items:
517 if entry.get('comments', False): 517 if entry.get('comments', False):
518 comments_rsm = {'max': max} 518 comments_rsm = {'max': max_}
519 d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], rsm=comments_rsm, profile_key=profile_key) 519 d = self.getGroupBlogComments(entry['comments_service'], entry['comments_node'], rsm=comments_rsm, profile_key=profile_key)
520 d.addCallback(comments_cb, entry) 520 d.addCallback(comments_cb, entry)
521 d_list.append(d) 521 d_list.append(d)
522 else: 522 else:
523 if max > 0: 523 if max_ > 0:
524 d_list.append(defer.succeed((entry, ([], {})))) 524 d_list.append(defer.succeed((entry, ([], {}))))
525 else: 525 else:
526 d_list.append(defer.succeed(entry)) 526 d_list.append(defer.succeed(entry))
527 deferred_list = defer.DeferredList(d_list) 527 deferred_list = defer.DeferredList(d_list)
528 deferred_list.addCallback(lambda result: [value for (success, value) in result if success]) 528 deferred_list.addCallback(lambda result: [value for (success, value) in result if success])
586 - couple (comments data, RSM response data for the comments) 586 - couple (comments data, RSM response data for the comments)
587 - RSM response data 587 - RSM response data
588 """ 588 """
589 if max_comments is None: 589 if max_comments is None:
590 max_comments = MAX_COMMENTS 590 max_comments = MAX_COMMENTS
591 assert(max_comments > 0) # otherwise the return signature is not the same 591 assert max_comments > 0 # otherwise the return signature is not the same
592 return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm=rsm, max_comments=max_comments, profile_key=profile_key) 592 return self._getGroupBlogs(pub_jid_s, item_ids=item_ids, rsm=rsm, max_comments=max_comments, profile_key=profile_key)
593 593
594 def getGroupBlogsAtom(self, pub_jid_s, rsm=None, profile_key=C.PROF_KEY_NONE): 594 def getGroupBlogsAtom(self, pub_jid_s, rsm=None, profile_key=C.PROF_KEY_NONE):
595 """Get the atom feed of the last published microblogs 595 """Get the atom feed of the last published microblogs
596 @param pub_jid: jid of the publisher 596 @param pub_jid: jid of the publisher
898 self.cb = cb 898 self.cb = cb
899 self.eb = (lambda dummy: ([], {})) if eb is None else eb 899 self.eb = (lambda dummy: ([], {})) if eb is None else eb
900 self.profile_key = profile_key 900 self.profile_key = profile_key
901 901
902 def get(self, node, item_ids=None, sub_id=None, rsm=None): 902 def get(self, node, item_ids=None, sub_id=None, rsm=None):
903 """ 903 """Retrieve and process a page of pubsub items
904 904
905 @param node (str): node identifier. 905 @param node (str): node identifier.
906 @param item_ids (list[str]): list of items identifiers. 906 @param item_ids (list[str]): list of items identifiers.
907 @param sub_id (str): optional subscription identifier. 907 @param sub_id (str): optional subscription identifier.
908 @param rsm (dict): RSM request data 908 @param rsm (dict): RSM request data
915 915
916 def initialised(result): 916 def initialised(result):
917 profile, client = result 917 profile, client = result
918 rsm_ = wokkel_rsm.RSMRequest(**rsm) 918 rsm_ = wokkel_rsm.RSMRequest(**rsm)
919 d = self.parent.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, 919 d = self.parent.host.plugins["XEP-0060"].getItems(client.item_access_pubsub,
920 node, rsm_.max_, 920 node, rsm_.max,
921 item_ids, sub_id, rsm_, 921 item_ids, sub_id, rsm_,
922 profile_key=profile) 922 profile_key=profile)
923 923
924 def cb(result): 924 def cb(result):
925 d = defer.maybeDeferred(self.cb, result[0], client) 925 d = defer.maybeDeferred(self.cb, result[0], client)
946 def _buildData(self, publishers_type, publishers, client): 946 def _buildData(self, publishers_type, publishers, client):
947 jids = self.parent._getPublishersJIDs(publishers_type, publishers, client) 947 jids = self.parent._getPublishersJIDs(publishers_type, publishers, client)
948 return {publisher: self.parent.getNodeName(publisher) for publisher in jids} 948 return {publisher: self.parent.getNodeName(publisher) for publisher in jids}
949 949
950 def get(self, publishers_type, publishers, sub_id=None, rsm=None): 950 def get(self, publishers_type, publishers, sub_id=None, rsm=None):
951 """ 951 """Retrieve and process a page of pubsub items
952
952 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL") 953 @param publishers_type (str): type of the list of publishers (one of "GROUP" or "JID" or "ALL")
953 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids) 954 @param publishers (list): list of publishers, according to publishers_type (list of groups or list of jids)
954 @param sub_id (str): optional subscription identifier. 955 @param sub_id (str): optional subscription identifier.
955 @param rsm (dict): RSM request data 956 @param rsm (dict): RSM request data
956 @return: a deferred dict with: 957 @return: a deferred dict with: