comparison libervia/backend/core/xmpp.py @ 4333:e94799a0908f

core (main): Let plugins have several handlers + various improvements: `get_handler` can now return several handlers, which is notably useful for component with several included services. Various improvements such move to `async` method, docstring/type hints update, and slight improvment of SatXMPPComponent. rel 453
author Goffi <goffi@goffi.org>
date Tue, 03 Dec 2024 00:11:00 +0100
parents 94e0968987cd
children 17fa953c8cd7
comparison
equal deleted inserted replaced
4332:71c939e34ca6 4333:e94799a0908f
16 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
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 asyncio 19 import asyncio
20 import calendar 20 import calendar
21 from collections.abc import Iterable
21 import copy 22 import copy
22 from functools import partial 23 from functools import partial
23 import mimetypes 24 import mimetypes
24 from pathlib import Path 25 from pathlib import Path
25 import sys 26 import sys
144 """ 145 """
145 plugin_conn_cb = [] 146 plugin_conn_cb = []
146 self.plugins = plugins = self._get_plugins_list() 147 self.plugins = plugins = self._get_plugins_list()
147 for plugin in plugins: 148 for plugin in plugins:
148 # we check if plugin handle client mode 149 # we check if plugin handle client mode
149 if plugin.is_handler: 150 if plugin.has_handlers:
150 plugin.get_handler(self).setHandlerParent(self) 151 handlers = plugin.get_handler(self)
152 if not isinstance(handlers, Iterable):
153 handlers = [handlers]
154 for handler in handlers:
155 handler.setHandlerParent(self)
151 156
152 # profile_connecting/profile_connected methods handling 157 # profile_connecting/profile_connected methods handling
153 158
154 timer = connection_timer[plugin] = {"total": 0} 159 timer = connection_timer[plugin] = {"total": 0}
155 # profile connecting is called right now (before actually starting client) 160 # profile connecting is called right now (before actually starting client)
1083 d = self.roster.request_roster() 1088 d = self.roster.request_roster()
1084 d.addCallback(lambda __: super(SatXMPPClient, self)._finish_connection(__)) 1089 d.addCallback(lambda __: super(SatXMPPClient, self)._finish_connection(__))
1085 1090
1086 1091
1087 @implementer(iwokkel.IDisco) 1092 @implementer(iwokkel.IDisco)
1088 class SatXMPPComponent(SatXMPPEntity, component.Component): 1093 class SatXMPPComponent(SatXMPPEntity, core_types.SatXMPPComponent, component.Component):
1089 """XMPP component 1094 """XMPP component
1090 1095
1091 This component are similar but not identical to clients. 1096 This component are similar but not identical to clients.
1092 An entry point plugin is launched after component is connected. 1097 An entry point plugin is launched after component is connected.
1093 Component need to instantiate MessageProtocol itself 1098 Component need to instantiate MessageProtocol itself