@@ -69,15 +69,15 @@ def _find_module(name, path=None):
69
69
# Some special cases:
70
70
71
71
if spec .loader is importlib .machinery .BuiltinImporter :
72
- return None , None , ("" , _C_BUILTIN )
72
+ return None , None , ("" , "" , _C_BUILTIN )
73
73
74
74
if spec .loader is importlib .machinery .FrozenImporter :
75
- return None , None , ("" , _PY_FROZEN )
75
+ return None , None , ("" , "" , _PY_FROZEN )
76
76
77
77
file_path = spec .origin
78
78
79
79
if spec .loader .is_package (name ):
80
- return None , os .path .dirname (file_path ), ("" , _PKG_DIRECTORY )
80
+ return None , os .path .dirname (file_path ), ("" , "" , _PKG_DIRECTORY )
81
81
82
82
if isinstance (spec .loader , importlib .machinery .SourceFileLoader ):
83
83
kind = _PY_SOURCE
@@ -89,12 +89,12 @@ def _find_module(name, path=None):
89
89
kind = _PY_COMPILED
90
90
91
91
else : # Should never happen.
92
- return None , None , ("" , _SEARCH_ERROR )
92
+ return None , None , ("" , "" , _SEARCH_ERROR )
93
93
94
94
file = io .open_code (file_path )
95
95
suffix = os .path .splitext (file_path )[- 1 ]
96
96
97
- return file , file_path , (suffix , kind )
97
+ return file , file_path , (suffix , "rb" , kind )
98
98
99
99
100
100
class Module :
@@ -159,14 +159,14 @@ def msgout(self, *args):
159
159
def run_script (self , pathname ):
160
160
self .msg (2 , "run_script" , pathname )
161
161
with io .open_code (pathname ) as fp :
162
- stuff = ("" , _PY_SOURCE )
162
+ stuff = ("" , "rb" , _PY_SOURCE )
163
163
self .load_module ('__main__' , fp , pathname , stuff )
164
164
165
165
def load_file (self , pathname ):
166
166
dir , name = os .path .split (pathname )
167
167
name , ext = os .path .splitext (name )
168
168
with io .open_code (pathname ) as fp :
169
- stuff = (ext , _PY_SOURCE )
169
+ stuff = (ext , "rb" , _PY_SOURCE )
170
170
self .load_module (name , fp , pathname , stuff )
171
171
172
172
def import_hook (self , name , caller = None , fromlist = None , level = - 1 ):
@@ -320,6 +320,7 @@ def import_module(self, partname, fqname, parent):
320
320
except ImportError :
321
321
self .msgout (3 , "import_module ->" , None )
322
322
return None
323
+
323
324
try :
324
325
m = self .load_module (fqname , fp , pathname , stuff )
325
326
finally :
@@ -331,7 +332,7 @@ def import_module(self, partname, fqname, parent):
331
332
return m
332
333
333
334
def load_module (self , fqname , fp , pathname , file_info ):
334
- suffix , type = file_info
335
+ suffix , mode , type = file_info
335
336
self .msgin (2 , "load_module" , fqname , fp and "fp" , pathname )
336
337
if type == _PKG_DIRECTORY :
337
338
m = self .load_package (fqname , pathname )
@@ -502,7 +503,7 @@ def find_module(self, name, path, parent=None):
502
503
503
504
if path is None :
504
505
if name in sys .builtin_module_names :
505
- return (None , None , ("" , _C_BUILTIN ))
506
+ return (None , None , ("" , "" , _C_BUILTIN ))
506
507
507
508
path = self .path
508
509
0 commit comments