annotate libervia/backend/plugins/plugin_xep_0465.py @ 4214:07439bc0ed3c

doc (contributing/testing): typo
author Goffi <goffi@goffi.org>
date Fri, 23 Feb 2024 15:47:53 +0100
parents 4b842c1fb686
children 0d7bb4df2343
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia plugin for XEP-0465
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from typing import Optional, List, Dict, Union
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from twisted.words.protocols.jabber import jid
4008
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
23 from twisted.words.protocols.jabber import error
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.words.xish import domish
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from zope.interface import implementer
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from wokkel import disco, iwokkel
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
28 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
29 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
30 from libervia.backend.core.log import getLogger
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
31 from libervia.backend.core import exceptions
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
32 from libervia.backend.core.core_types import SatXMPPEntity
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
33 from libervia.backend.tools import utils
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
34 from libervia.backend.tools.common import data_format
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 log = getLogger(__name__)
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 PLUGIN_INFO = {
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_NAME: "Pubsub Public Subscriptions",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_IMPORT_NAME: "XEP-0465",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_TYPE: C.PLUG_TYPE_XEP,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_MODES: C.PLUG_MODE_BOTH,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_PROTOCOLS: ["XEP-0465"],
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 C.PI_DEPENDENCIES: ["XEP-0060", "XEP-0376"],
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 C.PI_MAIN: "XEP_0465",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 C.PI_HANDLER: "yes",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 C.PI_DESCRIPTION: _("""Pubsub Public Subscriptions implementation"""),
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 }
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 NS_PPS = "urn:xmpp:pps:0"
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 NS_PPS_SUBSCRIPTIONS = "urn:xmpp:pps:subscriptions:0"
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 NS_PPS_SUBSCRIBERS = "urn:xmpp:pps:subscribers:0"
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 SUBSCRIBERS_NODE_PREFIX = f"{NS_PPS_SUBSCRIBERS}/"
4008
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
54 NOT_IMPLEMENTED_MSG = (
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
55 "The service at {service!s} doesn't seem to support Pubsub Public Subscriptions "
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
56 "(XEP-0465), please request support from your service administrator."
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
57 )
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 class XEP_0465:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def __init__(self, host):
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 log.info(_("Pubsub Public Subscriptions initialization"))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
64 host.register_namespace("pps", NS_PPS)
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.host = host
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
66 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
67 "ps_public_subscriptions_get",
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 ".plugin",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 in_sign="sss",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 out_sign="s",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 method=self._subscriptions,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 async_=True,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
74 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
75 "ps_public_subscriptions_get",
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 ".plugin",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 in_sign="sss",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 out_sign="s",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 method=self._subscriptions,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 async_=True,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
82 host.bridge.add_method(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
83 "ps_public_node_subscriptions_get",
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 ".plugin",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 in_sign="sss",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 out_sign="a{ss}",
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
87 method=self._get_public_node_subscriptions,
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 async_=True,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 )
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
90
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
91 def get_handler(self, client):
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 return XEP_0465_Handler()
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
93
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 @property
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def subscriptions_node(self) -> str:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 return NS_PPS_SUBSCRIPTIONS
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 @property
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 def subscribers_node_prefix(self) -> str:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 return SUBSCRIBERS_NODE_PREFIX
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
101
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
102 def build_subscription_elt(self, node: str, service: jid.JID) -> domish.Element:
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 """Generate a <subscriptions> element
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
104
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 This is the element that a service returns on public subscriptions request
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 """
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 subscription_elt = domish.Element((NS_PPS, "subscription"))
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 subscription_elt["node"] = node
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 subscription_elt["service"] = service.full()
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 return subscription_elt
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
111
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
112 def build_subscriber_elt(self, subscriber: jid.JID) -> domish.Element:
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 """Generate a <subscriber> element
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
114
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 This is the element that a service returns on node public subscriptions request
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 """
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 subscriber_elt = domish.Element((NS_PPS, "subscriber"))
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 subscriber_elt["jid"] = subscriber.full()
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 return subscriber_elt
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 @utils.ensure_deferred
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 async def _subscriptions(
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 self,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 service="",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 nodeIdentifier="",
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 profile_key=C.PROF_KEY_NONE
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 ) -> str:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
128 client = self.host.get_client(profile_key)
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 service = None if not service else jid.JID(service)
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 subs = await self.subscriptions(client, service, nodeIdentifier or None)
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 return data_format.serialise(subs)
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
132
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 async def subscriptions(
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 client: SatXMPPEntity,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 service: Optional[jid.JID] = None,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 node: Optional[str] = None
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 ) -> List[Dict[str, Union[str, bool]]]:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 """Retrieve public subscriptions from a service
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
140
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 @param service(jid.JID): PubSub service
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 @param nodeIdentifier(unicode, None): node to filter
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 None to get all subscriptions
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 """
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 if service is None:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 service = client.jid.userhostJID()
4008
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
147 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
148 items, __ = await self.host.plugins["XEP-0060"].get_items(
4008
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
149 client, service, NS_PPS_SUBSCRIPTIONS
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
150 )
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
151 except error.StanzaError as e:
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
152 if e.condition == "forbidden":
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
153 log.warning(NOT_IMPLEMENTED_MSG.format(service=service))
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
154 return []
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
155 else:
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
156 raise e
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 ret = []
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 for item in items:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 try:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 subscription_elt = next(item.elements(NS_PPS, "subscription"))
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 except StopIteration:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 log.warning(f"no <subscription> element found: {item.toXml()}")
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 continue
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
164
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 try:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 sub_dict = {
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 "service": subscription_elt["service"],
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 "node": subscription_elt["node"],
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 "subscriber": service.full(),
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 "state": subscription_elt.getAttribute("subscription", "subscribed"),
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 }
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 except KeyError:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 log.warning(
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 f"invalid <subscription> element: {subscription_elt.toXml()}"
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 )
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 continue
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 if node is not None and sub_dict["node"] != node:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 # if not is specified, we filter out any other node
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 # FIXME: should node filtering be done by server?
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 continue
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 ret.append(sub_dict)
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 return ret
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
183
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 @utils.ensure_deferred
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
185 async def _get_public_node_subscriptions(
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 self,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 service: str,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 node: str,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 profile_key: str
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 ) -> Dict[str, str]:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
191 client = self.host.get_client(profile_key)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
192 subs = await self.get_public_node_subscriptions(
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 client, jid.JID(service) if service else None, node
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 )
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 return {j.full(): a for j, a in subs.items()}
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
196
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
197 def get_public_subscribers_node(self, node: str) -> str:
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 """Return prefixed node to retrieve public subscribers"""
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 return f"{NS_PPS_SUBSCRIBERS}/{node}"
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
200
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
201 async def get_public_node_subscriptions(
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 self,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 client: SatXMPPEntity,
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 service: Optional[jid.JID],
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 nodeIdentifier: str
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 ) -> Dict[jid.JID, str]:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 """Retrieve public subscriptions to a node
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
208
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 @param nodeIdentifier(unicode): node to get subscriptions from
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 """
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 if not nodeIdentifier:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 raise exceptions.DataError("node identifier can't be empty")
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
213
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 if service is None:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 service = client.jid.userhostJID()
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
216
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
217 subscribers_node = self.get_public_subscribers_node(nodeIdentifier)
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
218
4008
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
219 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
220 items, __ = await self.host.plugins["XEP-0060"].get_items(
4008
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
221 client, service, subscribers_node
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
222 )
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
223 except error.StanzaError as e:
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
224 if e.condition == "forbidden":
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
225 log.warning(NOT_IMPLEMENTED_MSG.format(service=service))
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
226 return {}
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
227 else:
56e5b18f4d06 plugin XEP-0465: log a warning and return empty list/dict when `forbidden` error is received:
Goffi <goffi@goffi.org>
parents: 3758
diff changeset
228 raise e
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 ret = {}
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 for item in items:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 try:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 subscriber_elt = next(item.elements(NS_PPS, "subscriber"))
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 except StopIteration:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 log.warning(f"no <subscriber> element found: {item.toXml()}")
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 continue
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
236
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 try:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 ret[jid.JID(subscriber_elt["jid"])] = "subscribed"
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 except (KeyError, RuntimeError):
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 log.warning(
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 f"invalid <subscriber> element: {subscriber_elt.toXml()}"
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 )
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 continue
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 return ret
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
245
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 4008
diff changeset
246 def set_public_opt(self, options: Optional[dict] = None) -> dict:
3758
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 """Set option to make a subscription public
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
248
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 @param options: dict where the option must be set
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 if None, a new dict will be created
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
251
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 @return: the options dict
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 """
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 if options is None:
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 options = {}
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 options[f'{{{NS_PPS}}}public'] = True
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 return options
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
258
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
259
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 @implementer(iwokkel.IDisco)
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 class XEP_0465_Handler(XMPPHandler):
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
262
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 def getDiscoInfo(self, requestor, service, nodeIdentifier=""):
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 return [disco.DiscoFeature(NS_PPS)]
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
265
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 def getDiscoItems(self, requestor, service, nodeIdentifier=""):
b7cef1b24f83 plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 return []