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 | 3c9a67799586e23b201faf4258d9917d97cca380 (patch) | |
tree | 8f73ab4384027ef8dc000c13e1b0d7f009cde4e2 /ez_setup.py | |
parent | 0657e25b0c5a5a0e0017ba0b8b1f1cabcf95f2d3 (diff) | |
download | python-setuptools-bitbucket-3c9a67799586e23b201faf4258d9917d97cca380.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 |