Use irc bot connection factory for SSL

The ib3 SSL object is not compatible with python3.12 and newer due to
ssl.wrap_socket being removed. This has been fixed upstream in this
pull request [0], but that code is not released to pypi.

To workaround this we simply create our own connection factory for the
irc bot using ssl's default ssl context's socket wrapper.

[0] https://github.com/bd808/python-ib3/issues/23

Change-Id: I4d670b7ebb5efcab1237f27fcb39f635db854cf5
This commit is contained in:
Clark Boylan
2026-01-30 14:47:40 -08:00
parent ba72122847
commit 2b4bfa0f76
+21 -2
View File
@@ -18,14 +18,15 @@
import argparse
import configparser
import daemon
import functools
from ib3.auth import SASL
from ib3.connection import SSL
import irc.bot
import irc.client
import json
import logging.config
import os
import re
import ssl
import threading
import time
import yaml
@@ -101,7 +102,25 @@ class Channel(object):
self.last_used = time.time()
class BaseGerritBot(SSL, irc.bot.SingleServerIRCBot):
class BaseGerritBot(irc.bot.SingleServerIRCBot):
def __init__(self, server_list, nickname, realname, *args, **kwargs):
server = server_list[0][0]
port = server_list[0][1]
if port == 6697:
# Taken from the example in the Factory class docstring at
# https://github.com/jaraco/irc/blob/main/irc/connection.py
context = ssl.create_default_context()
wrapper = functools.partial(
context.wrap_socket, server_hostname=server)
factory = irc.connection.Factory(wrapper=wrapper)
kwargs['connect_factory'] = factory
super(BaseGerritBot, self).__init__(
server_list=server_list,
nickname=nickname,
realname=realname,
*args,
**kwargs)
def send(self, channel_name, msg):
self.log.info('Sending "%s" to %s' % (msg, channel_name))
if channel_name not in self.joined_channels: