Mercurial > cpython-lru_cache-weakref
diff Lib/packaging/command/upload_docs.py @ 70202:8dc80509f181
packaging: use with open() instead of try/finally: close
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Thu, 19 May 2011 15:51:27 +0200 |
| parents | 1a31c3be88b1 |
| children | c2785ed52ed4 |
line wrap: on
line diff
--- a/Lib/packaging/command/upload_docs.py Thu May 19 15:51:54 2011 +0200 +++ b/Lib/packaging/command/upload_docs.py Thu May 19 15:51:27 2011 +0200 @@ -18,14 +18,13 @@ def zip_dir(directory): """Compresses recursively contents of directory into a BytesIO object""" destination = BytesIO() - zip_file = zipfile.ZipFile(destination, "w") - for root, dirs, files in os.walk(directory): - for name in files: - full = os.path.join(root, name) - relative = root[len(directory):].lstrip(os.path.sep) - dest = os.path.join(relative, name) - zip_file.write(full, dest) - zip_file.close() + with zipfile.ZipFile(destination, "w") as zip_file: + for root, dirs, files in os.walk(directory): + for name in files: + full = os.path.join(root, name) + relative = root[len(directory):].lstrip(os.path.sep) + dest = os.path.join(relative, name) + zip_file.write(full, dest) return destination
