8000 ndiff: Fix support for Python 3.12 · Ansuel/nmap@3475e35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3475e35

Browse files
committed
ndiff: Fix support for Python 3.12
Python 3.12 deprecated and removed the already deprecated and not documented imp library (the load_source function was never documented) Replace this with a modern alternative suggested by python/cpython#104212. Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
1 parent ddfa361 commit 3475e35

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

ndiff/ndifftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,23 @@
1212

1313
import xml.dom.minidom
1414

15-
import imp
15+
# import os
16+
import types
17+
import importlib.machinery
18+
19+
# Suggested conversion for imp.load_module from
20+
# https://github.com/python/cpython/issues/104212
21+
def load_module(module_name, filename):
22+
loader = importlib.machinery.SourceFileLoader(module_name, filename)
23+
module = types.ModuleType(loader.name)
24+
module.__file__ = filename
25+
sys.modules[module.__name__] = module
26+
loader.exec_module(module)
27+
return module
28+
1629
dont_write_bytecode = sys.dont_write_bytecode
1730
sys.dont_write_bytecode = True
18-
ndiff = imp.load_source("ndiff", "ndiff.py")
31+
ndiff = load_module("ndiff", "ndiff.py")
1932
for x in dir(ndiff):
2033
if not x.startswith("_"):
2134
globals()[x] = getattr(ndiff, x)

0 commit comments

Comments
 (0)
0