diff -r 5f3ac68f34f2 Lib/zipfile.py --- a/Lib/zipfile.py Mon Dec 26 18:52:46 2016 +0900 +++ b/Lib/zipfile.py Mon Dec 26 21:32:00 2016 +0900 @@ -1044,13 +1044,14 @@ class ZipFile: allowZip64: if True ZipFile will create files with ZIP64 extensions when needed, otherwise it will raise an exception when this would be necessary. - + legacy_encoding: encoding used when reading entry without EFS flag. """ fp = None # Set here since __del__ checks it _windows_illegal_name_trans_table = None - def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True): + def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True, + legacy_encoding='latin1'): """Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'.""" if mode not in ('r', 'w', 'x', 'a'): @@ -1067,6 +1068,7 @@ class ZipFile: self.mode = mode self.pwd = None self._comment = b'' + self.legacy_encoding = legacy_encoding # Check if we were passed a file-like object if isinstance(file, str): @@ -1201,8 +1203,7 @@ class ZipFile: # UTF-8 file names extension filename = filename.decode('utf-8') else: - # Historical ZIP filename encoding - filename = filename.decode('cp437') + filename = filename.decode(self.encoding) # Create ZipInfo instance to store file information x = ZipInfo(filename) x.extra = fp.read(centdir[_CD_EXTRA_FIELD_LENGTH]) @@ -1380,7 +1381,7 @@ class ZipFile: # UTF-8 filename fname_str = fname.decode("utf-8") else: - fname_str = fname.decode("cp437") + fname_str = fname.decode(self.encoding) if fname_str != zinfo.orig_filename: raise BadZipFile(