Skip to content

Commit 948e923

Browse files
committed
Merge fix for fail2ban#4126 (branch 'fail2bangh-4126--py-3.15')
refactor module loading to use exec_module: deprecated load_module is removed in py-3.15; closes fail2bangh-4126
2 parents 74981e4 + 247667c commit 948e923

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
python-version: [3.8, 3.9, '3.10', '3.11', '3.12', '3.13', '3.14.0-rc.2', pypy3.11]
25+
python-version: [3.8, 3.9, '3.10', '3.11', '3.12', '3.13', '3.14', '3.15.0-alpha.3', pypy3.11]
2626
fail-fast: false
2727
# Steps represent a sequence of tasks that will be executed as part of the job
2828
steps:

fail2ban/server/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import sys
3030
from threading import Lock
3131
import time
32+
import types
3233
from ..helpers import getLogger, _merge_dicts, uni_decode
3334
from collections import OrderedDict
3435

@@ -352,6 +353,7 @@ def pid_exists(pid):
352353
def load_python_module(pythonModule):
353354
pythonModuleName = os.path.splitext(
354355
os.path.basename(pythonModule))[0]
355-
mod = importlib.machinery.SourceFileLoader(
356-
pythonModuleName, pythonModule).load_module()
356+
ldr = importlib.machinery.SourceFileLoader(pythonModuleName, pythonModule)
357+
mod = types.ModuleType(ldr.name)
358+
ldr.exec_module(mod)
357359
return mod

fail2ban/tests/action_d/test_smtp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import unittest
2323
import re
2424
import sys
25+
import types
2526
import importlib
2627

2728
from ..dummyjail import DummyJail
@@ -296,10 +297,11 @@ def setUp(self):
296297
self.jail = DummyJail()
297298
pythonModule = os.path.join(CONFIG_DIR, "action.d", "smtp.py")
298299
pythonModuleName = os.path.basename(pythonModule.rstrip(".py"))
299-
customActionModule = importlib.machinery.SourceFileLoader(
300-
pythonModuleName, pythonModule).load_module()
300+
ldr = importlib.machinery.SourceFileLoader(pythonModuleName, pythonModule)
301+
mod = types.ModuleType(ldr.name)
302+
ldr.exec_module(mod)
301303

302-
self.action = customActionModule.Action(
304+
self.action = mod.Action(
303305
self.jail, "test", host="localhost:%i" % self.port)
304306

305307
self.action.ssl = True

0 commit comments

Comments
 (0)