From 61b2afce91b3b376b8aa028360c87aeef54e2be3 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 19 Nov 2024 23:46:32 +0100 Subject: [PATCH] [irc] Fixed Python 3.12 compatibility. `ssl.wrap_socket()` has been removed in Python 3.12 - see https://docs.python.org/3.12/whatsnew/3.12.html#ssl. Instead, the integration should create its own `SSLContext` and use the `wrap_socket()` from that object. --- platypush/plugins/irc/_bot.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/platypush/plugins/irc/_bot.py b/platypush/plugins/irc/_bot.py index 946081a62a..c710c2dac5 100644 --- a/platypush/plugins/irc/_bot.py +++ b/platypush/plugins/irc/_bot.py @@ -70,8 +70,11 @@ class IRCBot(irc.bot.SingleServerIRCBot): dcc_max_connections: Optional[int] = None, ): connection_factory = ConnectionFactory() + self._ssl_ctx = None + if ssl: - connection_factory.wrapper = _ssl.wrap_socket + self._ssl_ctx = _ssl.create_default_context() + connection_factory.wrapper = self._ssl_ctx.wrap_socket if ipv6: connection_factory.family = socket.AF_INET6 @@ -86,7 +89,7 @@ class IRCBot(irc.bot.SingleServerIRCBot): self.port = port self.alias = alias self._password = password - self.channels.update({channel: None for channel in channels}) + self.channels.update(dict.fromkeys(channels)) self._stop_message = stop_message self.dcc_ip_whitelist = set(dcc_ip_whitelist or []) self.dcc_ip_blacklist = set(dcc_ip_blacklist or []) @@ -455,7 +458,7 @@ class IRCBot(irc.bot.SingleServerIRCBot): def on_disconnect(self, connection: Connection, event: _IRCEvent): self._post_event(connection, IRCDisconnectEvent) # Cache channels for reconnect logic - channels = {ch: None for ch in self.channels.keys()} + channels = dict.fromkeys(self.channels) super()._on_disconnect(connection, event) self.channels.update(channels)