Commit b84464da authored by Philip Thiem's avatar Philip Thiem

caching the zip manifests Fixes #154

--HG--
extra : rebase_source : 0f32792e01b6a1b746a1e07ffa4d7a85eeda1595
parent 5c08ba7d
......@@ -1530,7 +1530,21 @@ class EmptyProvider(NullProvider):
empty_provider = EmptyProvider()
def build_zipmanifest(path):
class ZipManifests(object):
def __init__(self):
self.known = dict()
def __call__(self, path):
path = os.path.normpath(path)
stat = os.stat(path)
if path not in self.known or self.known[path][0] != stat.st_mtime:
self.known[path] = (stat.st_mtime, self.build_manifest(path))
return self.known[path][1]
def build_manifest(self, path):
"""
This builds a similar dictionary to the zipimport directory
caches. However instead of tuples, ZipInfo objects are stored.
......@@ -1557,6 +1571,7 @@ def build_zipmanifest(path):
zipinfo[zpath] = zfile.getinfo(zitem)
assert zipinfo[zpath] is not None
return zipinfo
build_zipmanifest = ZipManifests()
class ContextualZipFile(zipfile.ZipFile):
......@@ -1586,7 +1601,6 @@ class ZipProvider(EggProvider):
def __init__(self, module):
EggProvider.__init__(self, module)
self.zipinfo = build_zipmanifest(self.loader.archive)
self.zip_pre = self.loader.archive+os.sep
def _zipinfo_name(self, fspath):
......@@ -1802,7 +1816,6 @@ class EggMetadata(ZipProvider):
def __init__(self, importer):
"""Create a metadata provider from a zipimporter"""
self.zipinfo = build_zipmanifest(importer.archive)
self.zip_pre = importer.archive+os.sep
self.loader = importer
if importer.prefix:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment