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 12
12
See the License for the specific language governing permissions and
13
13
limitations under the License."""
14
14
15
- import imp
15
+ import importlib
16
16
import io
17
17
import json as _json
18
18
import socket
@@ -145,12 +145,11 @@ def is_unsafe_str(s):
145
145
146
146
def load_module (module_path , member = None ):
147
147
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 )
154
153
if member :
155
154
return getattr (module , member )
156
155
else :
You can’t perform that action at this time.
0 commit comments