aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-03-06 06:24:27 -0500
committerJason R. Coombs <jaraco@jaraco.com>2014-03-06 06:24:27 -0500
commit468929dc9320a78926dd1cacd8353bdfe8fdedd1 (patch)
treec4691e27f86ca53b69fee9e43a357a27e55d96f1
parent2610eb2913cccd2e7264f47a79bdbf772611764a (diff)
downloadexternal_python_setuptools-468929dc9320a78926dd1cacd8353bdfe8fdedd1.tar.gz
external_python_setuptools-468929dc9320a78926dd1cacd8353bdfe8fdedd1.tar.bz2
external_python_setuptools-468929dc9320a78926dd1cacd8353bdfe8fdedd1.zip
Restore support for Python 2.6 in bootstrap script. Fixes #157.
-rw-r--r--CHANGES.txt7
-rw-r--r--ez_setup.py15
2 files changed, 21 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 572280b7..2974a3b0 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,13 @@
CHANGES
=======
+-----
+3.0.1
+-----
+
+* Issue #157: Restore support for Python 2.6 in bootstrap script where
+ ``zipfile.ZipFile`` does not yet have support for context managers.
+
---
3.0
---
diff --git a/ez_setup.py b/ez_setup.py
index 324c0774..dbe2a2e3 100644
--- a/ez_setup.py
+++ b/ez_setup.py
@@ -64,6 +64,19 @@ def _build_egg(egg, archive_filename, to_dir):
raise IOError('Could not build the egg.')
+def get_zip_class():
+ """
+ Supplement ZipFile class to support context manager for Python 2.6
+ """
+ class ContextualZipFile(zipfile.ZipFile):
+ def __enter__(self):
+ return self
+ def __exit__(self, type, value, traceback):
+ self.close
+ return zipfile.Zipfile if hasattr(zipfile.ZipFile, '__exit__') else \
+ ContextualZipFile
+
+
@contextlib.contextmanager
def archive_context(filename):
# extracting the archive
@@ -72,7 +85,7 @@ def archive_context(filename):
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
- with zipfile.ZipFile(filename) as archive:
+ with get_zip_class()(filename) as archive:
archive.extractall()
# going in the directory