mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
bpo-14678: Update zipimport to support importlib.invalidate_caches() (GH-24159)
Added an invalidate_caches() method to the zipimport.zipimporter class based on the implementation of importlib.FileFinder.invalidate_caches(). This was done by adding a get_files() method and an _archive_mtime attribute to zipimport.zipimporter to check for updates or cache invalidation whenever the cache of files and toc entry information in the zipimporter is accessed.
This commit is contained in:
parent
bbba28212c
commit
3abf6f0102
5 changed files with 1020 additions and 939 deletions
|
@ -321,6 +321,16 @@ class zipimporter(_bootstrap_external._LoaderBasics):
|
|||
return ZipReader(self, fullname)
|
||||
|
||||
|
||||
def invalidate_caches(self):
|
||||
"""Reload the file data of the archive path."""
|
||||
try:
|
||||
self._files = _read_directory(self.archive)
|
||||
_zip_directory_cache[self.archive] = self._files
|
||||
except ZipImportError:
|
||||
_zip_directory_cache.pop(self.archive, None)
|
||||
self._files = None
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return f'<zipimporter object "{self.archive}{path_sep}{self.prefix}">'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue