comparison sat/plugins/plugin_xep_0277.py @ 3069:73db9db8b9e1

plugin XEP-0277: fixed comments URLs parsing
author Goffi <goffi@goffi.org>
date Fri, 08 Nov 2019 11:55:21 +0100
parents ab2696e34d29
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3068:e189ceca7e8b 3069:73db9db8b9e1
363 ): 363 ):
364 key = check_conflict("comments", True) 364 key = check_conflict("comments", True)
365 microblog_data[key] = link_elt["href"] 365 microblog_data[key] = link_elt["href"]
366 try: 366 try:
367 service, node = self.parseCommentUrl(microblog_data[key]) 367 service, node = self.parseCommentUrl(microblog_data[key])
368 except: 368 except Exception as e:
369 log.warning("Can't parse url {}".format(microblog_data[key])) 369 log.warning(f"Can't parse url {microblog_data[key]}: {e}")
370 del microblog_data[key] 370 del microblog_data[key]
371 else: 371 else:
372 microblog_data["{}_service".format(key)] = service.full() 372 microblog_data["{}_service".format(key)] = service.full()
373 microblog_data["{}_node".format(key)] = node 373 microblog_data["{}_node".format(key)] = node
374 else: 374 else:
851 will return(JID(u'sat-pubsub.example.net'), 'urn:xmpp:comments:_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:somebody@example.net') 851 will return(JID(u'sat-pubsub.example.net'), 'urn:xmpp:comments:_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:somebody@example.net')
852 @return (tuple[jid.JID, unicode]): service and node 852 @return (tuple[jid.JID, unicode]): service and node
853 """ 853 """
854 parsed_url = urllib.parse.urlparse(node_url, "xmpp") 854 parsed_url = urllib.parse.urlparse(node_url, "xmpp")
855 service = jid.JID(parsed_url.path) 855 service = jid.JID(parsed_url.path)
856 parsed_queries = urllib.parse.parse_qs(parsed_url.query.encode("utf-8")) 856 parsed_queries = urllib.parse.parse_qs(parsed_url.query)
857 node = parsed_queries.get("node", [""])[0] 857 node = parsed_queries.get("node", [""])[0]
858 858
859 if not node: 859 if not node:
860 raise failure.Failure(exceptions.DataError("Invalid comments link")) 860 raise failure.Failure(exceptions.DataError("Invalid comments link"))
861 861