os.mkdir(os.path.join(TESTFN2, "a"))
self.test_extract_dir()
+ def test_extract_dir_backslash(self):
+ zfname = findfile("zipdir_backslash.zip")
+ with zipfile.ZipFile(zfname) as zipf:
+ zipf.extractall(TESTFN2)
+ if os.name == 'nt':
+ self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a")))
+ self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a", "b")))
+ self.assertTrue(os.path.isfile(os.path.join(TESTFN2, "a", "b", "c")))
+ self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "d")))
+ self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "d", "e")))
+ else:
+ self.assertTrue(os.path.isfile(os.path.join(TESTFN2, "a\\b\\c")))
+ self.assertTrue(os.path.isfile(os.path.join(TESTFN2, "d\\e\\")))
+ self.assertFalse(os.path.exists(os.path.join(TESTFN2, "a")))
+ self.assertFalse(os.path.exists(os.path.join(TESTFN2, "d")))
+
def test_write_dir(self):
dirpath = os.path.join(TESTFN2, "x")
os.mkdir(dirpath)
def is_dir(self):
"""Return True if this archive member is a directory."""
- return self.filename.endswith('/')
+ if self.filename.endswith('/'):
+ return True
+ # The ZIP format specification requires to use forward slashes
+ # as the directory separator, but in practice some ZIP files
+ # created on Windows can use backward slashes. For compatibility
+ # with the extraction code which already handles this:
+ if os.path.altsep:
+ return self.filename.endswith((os.path.sep, os.path.altsep))
+ return False
# ZIP encryption uses the CRC32 one-byte primitive for scrambling some