[Python-checkins] cpython (merge 3.4 -> default): Issue #22201: Command-line interface of the zipfile module now correctly

serhiy.storchaka python-checkins at python.org
Sun Aug 17 14:20:28 CEST 2014


http://hg.python.org/cpython/rev/dc77ad3a17aa
changeset:   92132:dc77ad3a17aa
parent:      92128:7cdc941d5180
parent:      92131:7b933005c492
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Aug 17 15:17:56 2014 +0300
summary:
  Issue #22201: Command-line interface of the zipfile module now correctly
extracts ZIP files with directory entries.  Patch by Ryan Wilson.

files:
  Lib/zipfile.py |  13 +------------
  Misc/NEWS      |   3 +++
  2 files changed, 4 insertions(+), 12 deletions(-)


diff --git a/Lib/zipfile.py b/Lib/zipfile.py
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1764,18 +1764,7 @@
             sys.exit(1)
 
         with ZipFile(args[1], 'r') as zf:
-            out = args[2]
-            for path in zf.namelist():
-                if path.startswith('./'):
-                    tgt = os.path.join(out, path[2:])
-                else:
-                    tgt = os.path.join(out, path)
-
-                tgtdir = os.path.dirname(tgt)
-                if not os.path.exists(tgtdir):
-                    os.makedirs(tgtdir)
-                with open(tgt, 'wb') as fp:
-                    fp.write(zf.read(path))
+            zf.extractall(args[2])
 
     elif args[0] == '-c':
         if len(args) < 3:
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -935,6 +935,9 @@
 Tools/Demos
 -----------
 
+- Issue #22201: Command-line interface of the zipfile module now correctly
+  extracts ZIP files with directory entries.  Patch by Ryan Wilson.
+
 - Issue #22120: For functions using an unsigned integer return converter,
   Argument Clinic now generates a cast to that type for the comparison
   to -1 in the generated code.  (This supresses a compilation warning.)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list