aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-05-17 22:50:41 -0400
committerJason R. Coombs <jaraco@jaraco.com>2014-05-17 22:50:41 -0400
commitf49559970b7e551f045b59c9530733b1bd1ed0e6 (patch)
treea32b1b2f602411b63c0ad013e8e404b8fd262d2a
parent24d18354d9a2646d5192f959434c1044f7e7fbd4 (diff)
downloadexternal_python_setuptools-f49559970b7e551f045b59c9530733b1bd1ed0e6.tar.gz
external_python_setuptools-f49559970b7e551f045b59c9530733b1bd1ed0e6.tar.bz2
external_python_setuptools-f49559970b7e551f045b59c9530733b1bd1ed0e6.zip
Update ContextualZipFile to use a single constructor
-rw-r--r--ez_setup.py11
-rw-r--r--pkg_resources.py11
2 files changed, 10 insertions, 12 deletions
diff --git a/ez_setup.py b/ez_setup.py
index 53350e45..df3848a3 100644
--- a/ez_setup.py
+++ b/ez_setup.py
@@ -80,14 +80,13 @@ class ContextualZipFile(zipfile.ZipFile):
def __exit__(self, type, value, traceback):
self.close()
- @classmethod
- def compat(cls, *args, **kwargs):
+ def __new__(cls, *args, **kwargs):
"""
Construct a ZipFile or ContextualZipFile as appropriate
"""
- zf_has_exit = hasattr(zipfile.ZipFile, '__exit__')
- class_ = zipfile.ZipFile if zf_has_exit else cls
- return class_(*args, **kwargs)
+ if hasattr(zipfile.ZipFile, '__exit__'):
+ return zipfile.ZipFile(*args, **kwargs)
+ return super(ContextualZipFile, cls).__new__(cls, *args, **kwargs)
@contextlib.contextmanager
@@ -98,7 +97,7 @@ def archive_context(filename):
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
- with ContextualZipFile.compat(filename) as archive:
+ with ContextualZipFile(filename) as archive:
archive.extractall()
# going in the directory
diff --git a/pkg_resources.py b/pkg_resources.py
index 4c28d72c..1f8c3183 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -1551,7 +1551,7 @@ def build_zipmanifest(path):
* [7] - zipinfo.CRC
"""
zipinfo = dict()
- with ContextualZipFile.compat(path) as zfile:
+ with ContextualZipFile(path) as zfile:
for zitem in zfile.namelist():
zpath = zitem.replace('/', os.sep)
zipinfo[zpath] = zfile.getinfo(zitem)
@@ -1570,14 +1570,13 @@ class ContextualZipFile(zipfile.ZipFile):
def __exit__(self, type, value, traceback):
self.close()
- @classmethod
- def compat(cls, *args, **kwargs):
+ def __new__(cls, *args, **kwargs):
"""
Construct a ZipFile or ContextualZipFile as appropriate
"""
- zf_has_exit = hasattr(zipfile.ZipFile, '__exit__')
- class_ = zipfile.ZipFile if zf_has_exit else cls
- return class_(*args, **kwargs)
+ if hasattr(zipfile.ZipFile, '__exit__'):
+ return zipfile.ZipFile(*args, **kwargs)
+ return super(ContextualZipFile, cls).__new__(cls, *args, **kwargs)
class ZipProvider(EggProvider):