Skip to content

Commit 7f99b6a

Browse files
Try to replace imp with importlib for Python 3.12 compatibility
Largely based on https://discuss.python.org/t/how-do-i-migrate-from-imp/27885 and other discussions linked from python/cpython#104212.
1 parent 1b411a0 commit 7f99b6a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎xsd-fu/python/generateDS/generateDS.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
import time
9595
import getopt
9696
import urllib.request, urllib.error, urllib.parse
97-
import imp
97+
import importlib
9898
from xml.sax import handler, make_parser
9999
import xml.sax.xmlreader
100100
import logging
@@ -4221,8 +4221,9 @@ def parseAndGenerate(outfileName, subclassFilename, prefix,
42214221
path_list = UserMethodsPath.split('.')
42224222
mod_name = path_list[-1]
42234223
mod_path = os.sep.join(path_list[:-1])
4224-
module_spec = imp.find_module(mod_name, [mod_path, ])
4225-
UserMethodsModule = imp.load_module(mod_name, *module_spec)
4224+
module_spec = importlib.util.find_spec(mod_name, [mod_path, ])
4225+
UserMethodsModule = importlib.util.module_from_spec(module_spec)
4226+
module_spec.loader.exec_module(UserMethodsMdule)
42264227
## parser = saxexts.make_parser("xml.sax.drivers2.drv_pyexpat")
42274228
parser = make_parser()
42284229
dh = XschemaHandler()

0 commit comments

Comments
 (0)