annotate libervia/backend/plugins/plugin_xep_0203.py @ 4332:71c939e34ca6

XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author Syndace <me@syndace.dev>
date Sat, 13 Jul 2024 18:28:28 +0200
parents 4b842c1fb686
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
3
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT plugin for Delayed Delivery (XEP-0203)
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1743
diff changeset
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
7
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
12
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
17
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
20
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 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
23 from libervia.backend.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
24
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
25 log = getLogger(__name__)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
26
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from wokkel import disco, iwokkel, delay
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
28
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
29 try:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from twisted.words.protocols.xmlstream import XMPPHandler
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
31 except ImportError:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
32 from wokkel.subprotocols import XMPPHandler
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
33 from zope.interface import implementer
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
34
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
35
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 NS_DD = "urn:xmpp:delay"
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
37
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
38 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
39 C.PI_NAME: "Delayed Delivery",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
40 C.PI_IMPORT_NAME: "XEP-0203",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
41 C.PI_TYPE: "XEP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
42 C.PI_PROTOCOLS: ["XEP-0203"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
43 C.PI_MAIN: "XEP_0203",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
44 C.PI_HANDLER: "yes",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 C.PI_DESCRIPTION: _("""Implementation of Delayed Delivery"""),
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
46 }
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
47
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
48
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
49 class XEP_0203(object):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
50 def __init__(self, host):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
51 log.info(_("Delayed Delivery plugin initialization"))
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
52 self.host = host
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
53
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
54 def get_handler(self, client):
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1955
diff changeset
55 return XEP_0203_handler(self, client.profile)
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
56
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 def delay(self, stamp, sender=None, desc="", parent=None):
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
58 """Build a delay element, eventually append it to the given parent element.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
59
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
60 @param stamp (datetime): offset-aware timestamp of the original sending.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
61 @param sender (JID): entity that originally sent or delayed the message.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
62 @param desc (unicode): optional natural language description.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
63 @param parent (domish.Element): add the delay element to this element.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
64 @return: the delay element (domish.Element)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
65 """
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
66 elt = delay.Delay(stamp, sender).toElement()
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
67 if desc:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
68 elt.addContent(desc)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
69 if parent:
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
70 parent.addChild(elt)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
71 return elt
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
72
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
73
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
74 @implementer(iwokkel.IDisco)
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
75 class XEP_0203_handler(XMPPHandler):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
76
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
77 def __init__(self, plugin_parent, profile):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
78 self.plugin_parent = plugin_parent
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
79 self.host = plugin_parent.host
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
80 self.profile = profile
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
81
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
83 return [disco.DiscoFeature(NS_DD)]
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
84
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
86 return []