[issue10614] ZipFile and CP932 encoding
report at bugs.python.org
Fri Jan 21 23:39:18 CET 2011
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
In #10972, I propose to add an option for the filename encoding to UTF-8. But I would like to force UTF-8 to create a ZIP file, it doesn't concern the decompression of a ZIP file.
Proposal of a specification to fix both issues at the same time.
"default_encoding" name is confusing because it doesn't specify if it is the encoding of (text?) file content or the encoding the filename. Why not simply "filename_encoding"?
The option can be added in multiple places:
- argument to ZipFile constructor: this is needed to decompress
- argument to ZipFile.write() and ZipInfo, because they are 3 different manners to add files
ZipFile.filename_encoding (and ZipInfo.filename_encoding) will be None by default: in this case, use the current algorithm (try cp437 or use UTF-8). Otherwise, use the encoding. If the encoding is UTF-8: set unicode flag.
f = zipfile.ZipFile("test.zip", "w")
info = ZipInfo(filename, filename_encoding="UTF-8")
Don't add filename_encoding argument to ZipFile.writestr(), because it may conflict if a ZipInfo is passed and ZipInfo.filename_encoding and filename_encoding are different.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list