diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2014-03-06 06:24:27 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-03-06 06:24:27 -0500 |
| commit | 468929dc9320a78926dd1cacd8353bdfe8fdedd1 (patch) | |
| tree | c4691e27f86ca53b69fee9e43a357a27e55d96f1 /ez_setup.py | |
| parent | 2610eb2913cccd2e7264f47a79bdbf772611764a (diff) | |
| download | python-setuptools-git-468929dc9320a78926dd1cacd8353bdfe8fdedd1.tar.gz | |
Restore support for Python 2.6 in bootstrap script. Fixes #157.
Diffstat (limited to 'ez_setup.py')
| -rw-r--r-- | ez_setup.py | 15 |
1 files changed, 14 insertions, 1 deletions
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 |
