[Python-checkins] r87604 - in python/branches/py3k: Lib/test/test_zipfile.py Lib/test/zip_cp437_header.zip Lib/zipfile.py Misc/NEWS
georg.brandl
python-checkins at python.org
Sat Jan 1 11:09:32 CET 2011
Author: georg.brandl
Date: Sat Jan 1 11:09:32 2011
New Revision: 87604
Log:
#10801: In zipfile, support different encodings for the header and the filenames. Patch by MvL, test by Eli Bendersky.
Added:
python/branches/py3k/Lib/test/zip_cp437_header.zip (contents, props changed)
Modified:
python/branches/py3k/Lib/test/test_zipfile.py
python/branches/py3k/Lib/zipfile.py
python/branches/py3k/Misc/NEWS
Modified: python/branches/py3k/Lib/test/test_zipfile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_zipfile.py (original)
+++ python/branches/py3k/Lib/test/test_zipfile.py Sat Jan 1 11:09:32 2011
@@ -6,6 +6,7 @@
import io
import os
+import sys
import imp
import time
import shutil
@@ -23,6 +24,7 @@
TESTFN2 = TESTFN + "2"
TESTFNDIR = TESTFN + "d"
FIXEDTEST_SIZE = 1000
+DATAFILES_DIR = 'zipfile_datafiles'
SMALL_TEST_DATA = [('_ziptest1', '1q2w3e4r5t'),
('ziptest2dir/_ziptest2', 'qawsedrftg'),
@@ -487,6 +489,18 @@
except zipfile.BadZipFile:
self.assertTrue(zipfp2.fp is None, 'zipfp is not closed')
+ def test_unicode_filenames(self):
+ if __name__ == '__main__':
+ myfile = sys.argv[0]
+ else:
+ myfile = __file__
+
+ mydir = os.path.dirname(myfile) or os.curdir
+ fname = os.path.join(mydir, 'zip_cp437_header.zip')
+
+ with zipfile.ZipFile(fname) as zipfp:
+ zipfp.extractall()
+
def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)
Added: python/branches/py3k/Lib/test/zip_cp437_header.zip
==============================================================================
Binary file. No diff available.
Modified: python/branches/py3k/Lib/zipfile.py
==============================================================================
--- python/branches/py3k/Lib/zipfile.py (original)
+++ python/branches/py3k/Lib/zipfile.py Sat Jan 1 11:09:32 2011
@@ -930,7 +930,13 @@
if fheader[_FH_EXTRA_FIELD_LENGTH]:
zef_file.read(fheader[_FH_EXTRA_FIELD_LENGTH])
- if fname != zinfo.orig_filename.encode("utf-8"):
+ if zinfo.flag_bits & 0x800:
+ # UTF-8 filename
+ fname_str = fname.decode("utf-8")
+ else:
+ fname_str = fname.decode("cp437")
+
+ if fname_str != zinfo.orig_filename:
if not self._filePassed:
zef_file.close()
raise BadZipFile(
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sat Jan 1 11:09:32 2011
@@ -20,6 +20,9 @@
Library
-------
+- Issue #10801: In zipfile, support different encodings for the header and
+ the filenames.
+
- Issue #6285: IDLE no longer crashes on missing help file; patch by Scott
David Daniels.
More information about the Python-checkins
mailing list