comparison sat/plugins/plugin_xep_0277.py @ 3643:30196b9a2b4c

plugin XEP-0277: use `common.uri` to parse comment URIs
author Goffi <goffi@goffi.org>
date Wed, 08 Sep 2021 11:14:53 +0200
parents 7df12ffa6620
children cbb988a6f507
comparison
equal deleted inserted replaced
3642:cc3b453670a2 3643:30196b9a2b4c
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 import time 19 import time
20 import dateutil 20 import dateutil
21 import calendar 21 import calendar
22 import urllib.parse
23 from secrets import token_urlsafe 22 from secrets import token_urlsafe
24 from typing import Optional 23 from typing import Optional
25 from functools import partial 24 from functools import partial
26 25
27 import shortuuid 26 import shortuuid
1004 from the href attribute of an entry's link element. For example this input: 1003 from the href attribute of an entry's link element. For example this input:
1005 xmpp:sat-pubsub.example.net?;node=urn%3Axmpp%3Acomments%3A_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn%3Axmpp%3Agroupblog%3Asomebody%40example.net 1004 xmpp:sat-pubsub.example.net?;node=urn%3Axmpp%3Acomments%3A_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn%3Axmpp%3Agroupblog%3Asomebody%40example.net
1006 will return(JID(u'sat-pubsub.example.net'), 'urn:xmpp:comments:_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:somebody@example.net') 1005 will return(JID(u'sat-pubsub.example.net'), 'urn:xmpp:comments:_af43b363-3259-4b2a-ba4c-1bc33aa87634__urn:xmpp:groupblog:somebody@example.net')
1007 @return (tuple[jid.JID, unicode]): service and node 1006 @return (tuple[jid.JID, unicode]): service and node
1008 """ 1007 """
1009 parsed_url = urllib.parse.urlparse(node_url, "xmpp") 1008 try:
1010 service = jid.JID(parsed_url.path) 1009 parsed_url = xmpp_uri.parseXMPPUri(node_url)
1011 parsed_queries = urllib.parse.parse_qs(parsed_url.query) 1010 service = jid.JID(parsed_url["path"])
1012 node = parsed_queries.get("node", [""])[0] 1011 node = parsed_url["node"]
1013 1012 except Exception as e:
1014 if not node: 1013 raise exceptions.DataError(f"Invalid comments link: {e}")
1015 raise exceptions.DataError("Invalid comments link")
1016 1014
1017 return (service, node) 1015 return (service, node)
1018 1016
1019 ## configure ## 1017 ## configure ##
1020 1018