Commits

Yuya Nishihara committed ea0fbc4

introduce decorator to access library.zip

Comments (0)

Files changed (1)

hgext/fixfrozenexts.py

 def _libpath():
     return os.path.join(os.path.dirname(sys.executable), 'library.zip')
 
+def _withlibzip(func):
+    def wrap(*args, **kwargs):
+        zf = zipfile.ZipFile(_libpath())
+        try:
+            return func(zf, *args, **kwargs)
+        finally:
+            zf.close()
+    wrap.func_name = func.func_name
+    return wrap
+
+@_cached
+@_withlibzip
 def _listzippedexts(zf):
     """list up extensions in library.zip"""
     exts = {}
 
     return exts
 
-@_cached
-def _disabledzippedpaths():
-    zf = zipfile.ZipFile(_libpath())
-    try:
-        return _listzippedexts(zf)
-    finally:
-        zf.close()
-
 def _disabledpaths(orig, strip_init=False):
-    allexts = _disabledzippedpaths()
+    allexts = _listzippedexts()
     exts = dict((name, path) for name, path in allexts.iteritems()
                 if name not in extensions._order)
     if not strip_init:
             exts[name] = os.path.dirname(path)
     return exts
 
+@_cached
+@_withlibzip
 def _extractzippeddoc(zf, path):
     """extract docstring from zipped *.pyo"""
     try:
     finally:
         file.close()
 
-@_cached
-def _disabledzippedhelp(path):
-    zf = zipfile.ZipFile(_libpath())
-    try:
-        return _extractzippeddoc(zf, path)
-    finally:
-        zf.close()
-
 def _disabledhelp(orig, path):
-    doc = _disabledzippedhelp(path)
+    doc = _extractzippeddoc(path)
     if doc: # extracting localized synopsis
         return gettext(doc).splitlines()[0]
     else: