changeset: 92786:981d18930d6d branch: 3.4 parent: 92782:a486b673b57f user: Serhiy Storchaka date: Sat Oct 04 13:39:34 2014 +0300 files: Lib/zipfile.py Misc/NEWS description: Issue #22219: The zipfile module CLI now adds entries for directories (including empty directories) in ZIP file. diff -r a486b673b57f -r 981d18930d6d Lib/zipfile.py --- a/Lib/zipfile.py Fri Oct 03 20:18:48 2014 -0400 +++ b/Lib/zipfile.py Sat Oct 04 13:39:34 2014 +0300 @@ -1790,14 +1790,21 @@ if os.path.isfile(path): zf.write(path, zippath, ZIP_DEFLATED) elif os.path.isdir(path): + if zippath: + zf.write(path, zippath) for nm in os.listdir(path): addToZip(zf, os.path.join(path, nm), os.path.join(zippath, nm)) # else: ignore with ZipFile(args[1], 'w') as zf: - for src in args[2:]: - addToZip(zf, src, os.path.basename(src)) + for path in args[2:]: + zippath = os.path.basename(path) + if not zippath: + zippath = os.path.basename(os.path.dirname(path)) + if zippath in ('', os.curdir, os.pardir): + zippath = '' + addToZip(zf, path, zippath) if __name__ == "__main__": main() diff -r a486b673b57f -r 981d18930d6d Misc/NEWS --- a/Misc/NEWS Fri Oct 03 20:18:48 2014 -0400 +++ b/Misc/NEWS Sat Oct 04 13:39:34 2014 +0300 @@ -19,6 +19,9 @@ Library ------- +- Issue #22219: The zipfile module CLI now adds entries for directories + (including empty directories) in ZIP file. + - Issue #22449: In the ssl.SSLContext.load_default_certs, consult the enviromental variables SSL_CERT_DIR and SSL_CERT_FILE on Windows.