@@ -166,46 +166,32 @@ def find_spec(self, fullname, path,>
166166
167167if sys .graal_python_jython_emulation_enabled :
168168 class JarImportLoader :
169- def __init__ (self , jarpath , zippath ):
170- self .jarpath = jarpath
171- self .zippath = zippath
169+ def __init__ (self , code ):
170+ self .code = code
172171
173172 def create_module (self , spec ):
174173 newmod = _frozen_importlib ._new_module (spec .name )
175- newmod .__path__ = "%s!%s" % ( self .jarpath , self . zippath )
174+ newmod .__path__ = self .code . co_filename
176175 return newmod
177176
178177 def exec_module (self , module ):
179- import zipfile
180- with zipfile .ZipFile (self .jarpath ) as z :
181- code = z .read (self .zippath )
182- exec (code , module .__dict__ )
178+ exec (self .code , module .__dict__ )
183179
184180
185181 class JarImportFinder :
186182 def __init__ (self ):
187- self .namelist_cache = {}
183+ self .zipimport = __import__ ( "zipimport" )
188184
189185 def find_spec (self , fullname , path , target = None ):
190186 for path in sys .path :
191187 if ".jar!" in path :
192- jarfile , _ , zippath = path .partition ("!" )
193- file_to_find = "%s/%s.py" % (zippath , fullname .replace ("." , "/" ))
194- init_to_find = "%s/%s/__init__.py" % (zippath , fullname .replace ("." , "/" ))
195- old_mtime , namelist = self .namelist_cache .get (jarfile , (None , None ))
196- try :
197- mtime = posix .stat (jarfile ).st_mtime
198- except OSError :
199- mtime = - 1
200- if namelist is None or mtime > old_mtime :
201- import zipfile
202- with zipfile .ZipFile (jarfile ) as z :
203- namelist = z .namelist ()
204- self .namelist_cache [jarfile ] = (mtime , namelist )
205- if file_to_find in namelist :
206- return _frozen_importlib .ModuleSpec (fullname , JarImportLoader (jarfile , file_to_find ), is_package = False )
207- elif init_to_find in namelist :
208- return _frozen_importlib .ModuleSpec (fullname , JarImportLoader (jarfile , init_to_find ), is_package = True )
188+ zipimport_path = path .replace (".jar!/" , ".jar/" ).replace (".jar!" , ".jar/" )
189+ zipimporter = self .zipimport .zipimporter (zipimport_path )
190+ if zipimporter .find_module (fullname ):
191+ if zipimporter .is_package (fullname ):
192+ return _frozen_importlib .ModuleSpec (fullname , JarImportLoader (zipimporter .get_code (fullname )), is_package = True )
193+ else :
194+ return _frozen_importlib .ModuleSpec (fullname , JarImportLoader (zipimporter .get_code (fullname )), is_package = False )
209195
210196
211197 sys .meta_path .append (JarImportFinder ())
0 commit comments