comparison src/plugins/plugin_xep_0277.py @ 858:660b3f5b6c78

plugins groupblog, XEP-0277: attempt to clarify the code for the comments handling: - add or update some methods docstrings - add GroupBlog.__fillCommentsElement to factorize the code responsible to build the comments link - do not mix up attributes names between the item own service/node and the comments service/node
author souliane <souliane@mailoo.org>
date Fri, 14 Feb 2014 21:24:31 +0100
parents 03addfe98b64
children 64ec04991d9d
comparison
equal deleted inserted replaced
857:3c270d691e56 858:660b3f5b6c78
69 method=self.setMicroblogAccess, 69 method=self.setMicroblogAccess,
70 async=True, 70 async=True,
71 doc={}) 71 doc={})
72 72
73 def parseCommentUrl(self, node_url): 73 def parseCommentUrl(self, node_url):
74 """Determine the fields comments_service and comments_node of a microblog data
75 from the href attribute of an entry's link element. For example this input:
76 xmpp:sat-pubsub.libervia.org?node=urn%3Axmpp%3Acomments%3A_c5c4a142-2279-4b2a-ba4c-1bc33aa87634__urn%3Axmpp%3Agroupblog%3Asouliane%libervia.org
77 will return (JID(u'sat-pubsub.libervia.org'), 'urn:xmpp:comments:_c5c4a142-2279-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:souliane%libervia.org')
78 @return: a tuple (JID, str)
79 """
74 parsed_url = urlparse.urlparse(node_url, 'xmpp') 80 parsed_url = urlparse.urlparse(node_url, 'xmpp')
75 service = jid.JID(parsed_url.path) 81 service = jid.JID(parsed_url.path)
76 queries = parsed_url.query.split(';') 82 queries = parsed_url.query.split(';')
77 parsed_queries = dict() 83 parsed_queries = dict()
78 for query in queries: 84 for query in queries:
152 service, node = self.parseCommentUrl(microblog_data["comments"]) 158 service, node = self.parseCommentUrl(microblog_data["comments"])
153 microblog_data['comments_service'] = service.full() 159 microblog_data['comments_service'] = service.full()
154 microblog_data['comments_node'] = node 160 microblog_data['comments_node'] = node
155 break 161 break
156 except (KeyError, exceptions.DataError, RuntimeError): 162 except (KeyError, exceptions.DataError, RuntimeError):
157 warning("Can't parse link") 163 warning(_("Can't parse the link element of pubsub entry %s") % item['id'])
158 continue 164 continue
159 except (AttributeError, KeyError): 165 except (AttributeError, KeyError):
160 error(_('Error while parsing atom entry for microblogging event')) 166 error(_('Error while parsing atom entry for microblogging event'))
161 raise exceptions.DataError 167 raise exceptions.DataError
162 168