File tree Expand file tree Collapse file tree 1 file changed +6
-7
lines changed
Expand file tree Collapse file tree 1 file changed +6
-7
lines changed Original file line number Diff line number Diff line change 1212See the License for the specific language governing permissions and
1313limitations under the License."""
1414
15- import imp
15+ import importlib
1616import io
1717import json as _json
1818import socket
@@ -145,12 +145,11 @@ def is_unsafe_str(s):
145145
146146def load_module (module_path , member = None ):
147147 module_name = splitext (basename (module_path ))[0 ]
148- try : # 'U' is default from Python 3.0 and deprecated since 3.9
149- module_file = open (module_path , 'U' )
150- except ValueError :
151- module_file = open (module_path , 'rt' )
152- description = ('.py' , 'U' , imp .PY_SOURCE )
153- module = imp .load_module (module_name , module_file , module_path , description )
148+ spec = importlib .util .spec_from_file_location (module_name , module_path )
149+ if spec is None :
150+ raise IOError (f'file { module_path } not found' )
151+ module = importlib .util .module_from_spec (spec )
152+ spec .loader .exec_module (module )
154153 if member :
155154 return getattr (module , member )
156155 else :
You can’t perform that action at this time.
0 commit comments