annotate libervia/backend/plugins/plugin_xep_0199.py @ 4340:ea72364131d5 default tip @

doc (components): Update Email Gateway documentation: A section has been added to explain how attachments are handled. fix 453
author Goffi <goffi@goffi.org>
date Tue, 03 Dec 2024 00:53:18 +0100
parents 0d7bb4df2343
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
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
3
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for Delayed Delivery (XEP-0199)
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
7
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # (at your option) any later version.
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
12
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
17
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.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 _, D_
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.core.log import getLogger
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
23
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
24 log = getLogger(__name__)
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
25 from libervia.backend.core.constants import Const as C
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from wokkel import disco, iwokkel
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber import xmlstream, jid
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
28 from zope.interface import implementer
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
29 import time
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
30
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
31
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
32 PLUGIN_INFO = {
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
33 C.PI_NAME: "XMPP PING",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
34 C.PI_IMPORT_NAME: "XEP-0199",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
35 C.PI_TYPE: "XEP",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
36 C.PI_PROTOCOLS: ["XEP-199"],
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_MAIN: "XEP_0199",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
38 C.PI_HANDLER: "yes",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
39 C.PI_DESCRIPTION: D_("""Implementation of XMPP Ping"""),
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
40 }
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
41
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
42 NS_PING = "urn:xmpp:ping"
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
43 PING_REQUEST = C.IQ_GET + '/ping[@xmlns="' + NS_PING + '"]'
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
44
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
45
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
46 class XEP_0199(object):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
47
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def __init__(self, host):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
49 log.info(_("XMPP Ping plugin initialization"))
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.host = host
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
51 host.bridge.add_method(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
52 "ping", ".plugin", in_sign="ss", out_sign="d", method=self._ping, async_=True
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
53 )
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
54 try:
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.text_cmds = self.host.plugins[C.TEXT_CMDS]
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
56 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
57 log.info(_("Text commands not available"))
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
58 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
59 self.text_cmds.register_text_commands(self)
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
60
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
61 def get_handler(self, client):
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
62 return XEP_0199_handler(self)
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
63
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
64 def _ping_raise_if_failure(self, pong):
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
65 """If ping didn't succeed, raise the failure, else return pong delay"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
66 if pong[0] != "PONG":
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
67 raise pong[0]
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
68 return pong[1]
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
69
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def _ping(self, jid_s, profile):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
71 client = self.host.get_client(profile)
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
72 entity_jid = jid.JID(jid_s)
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
73 d = self.ping(client, entity_jid)
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
74 d.addCallback(self._ping_raise_if_failure)
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
75 return d
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
76
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
77 def _ping_cb(self, iq_result, send_time):
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
78 receive_time = time.time()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
79 return ("PONG", receive_time - send_time)
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
80
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
81 def _ping_eb(self, failure_, send_time):
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
82 receive_time = time.time()
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
83 return (failure_.value, receive_time - send_time)
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
84
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
85 def ping(self, client, entity_jid):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
86 """Ping an XMPP entity
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
87
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
88 @param entity_jid(jid.JID): entity to ping
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
89 @return (tuple[(unicode,failure), float]): pong data:
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
90 - either u"PONG" if it was successful, or failure
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
91 - delay between sending time and reception time
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
92 """
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
93 iq_elt = client.IQ("get")
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
94 iq_elt["to"] = entity_jid.full()
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
95 iq_elt.addElement((NS_PING, "ping"))
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
96 d = iq_elt.send()
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
97 send_time = time.time()
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
98 d.addCallback(self._ping_cb, send_time)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99 d.addErrback(self._ping_eb, send_time)
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
100 return d
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
101
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
102 def _cmd_ping_fb(self, pong, client, mess_data):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
103 """Send feedback to client when pong data is received"""
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
104 txt_cmd = self.host.plugins[C.TEXT_CMDS]
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
105
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
106 if pong[0] == "PONG":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
107 txt_cmd.feed_back(client, "PONG ({time} s)".format(time=pong[1]), mess_data)
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
108 else:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
109 txt_cmd.feed_back(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
110 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
111 _("ping error ({err_msg}). Response time: {time} s").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
112 err_msg=pong[0], time=pong[1]
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
113 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
114 mess_data,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
115 )
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
116
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def cmd_ping(self, client, mess_data):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
118 """ping an entity
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
119
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
120 @command (all): [JID]
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
121 - JID: jid of the entity to ping
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
122 """
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
123 if mess_data["unparsed"].strip():
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
124 try:
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
125 entity_jid = jid.JID(mess_data["unparsed"].strip())
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
126 except RuntimeError:
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
127 txt_cmd = self.host.plugins[C.TEXT_CMDS]
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
128 txt_cmd.feed_back(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
129 client,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
130 _('Invalid jid: "{entity_jid}"').format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
131 entity_jid=mess_data["unparsed"].strip()
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
132 ),
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
133 mess_data,
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
134 )
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
135 return False
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
136 else:
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
137 entity_jid = mess_data["to"]
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
138 d = self.ping(client, entity_jid)
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
139 d.addCallback(self._cmd_ping_fb, client, mess_data)
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
140
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
141 return False
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
142
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
143 def on_ping_request(self, iq_elt, client):
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
144 log.info(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
145 _("XMPP PING received from {from_jid} [{profile}]").format(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
146 from_jid=iq_elt["from"], profile=client.profile
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
147 )
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
148 )
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
149 iq_elt.handled = True
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
150 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
151 client.send(iq_result_elt)
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
152
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
153
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
154 @implementer(iwokkel.IDisco)
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
155 class XEP_0199_handler(xmlstream.XMPPHandler):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
156
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
157 def __init__(self, plugin_parent):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self.plugin_parent = plugin_parent
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
159
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
160 def connectionInitialized(self):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self.xmlstream.addObserver(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
162 PING_REQUEST, self.plugin_parent.on_ping_request, client=self.parent
2689
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
163 )
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
164
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
165 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
166 return [disco.DiscoFeature(NS_PING)]
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
167
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
168 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
d715d912afac plugin XEP-0199: implementation of XMPP Ping
Goffi <goffi@goffi.org>
parents:
diff changeset
169 return []