Message126791
| Author |
vstinner |
| Recipients |
amaury.forgeotdarc, loewis, ocean-city, vstinner |
| Date |
2011年01月21日.22:39:16 |
| SpamBayes Score |
1.6247002e-08 |
| Marked as misclassified |
No |
| Message-id |
<1295649558.2.0.915282022743.issue10614@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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.
Examples:
---
zipfile.ZipFile("non-ascii-cp932.zip", filename_encoding="cp932")
f = zipfile.ZipFile("test.zip", "w")
f.write(filename, filename_encoding="UTF-8")
info = ZipInfo(filename, filename_encoding="UTF-8")
f.writestr(info, b'data')
---
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. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2011年01月21日 22:39:18 | vstinner | set | recipients:
+ vstinner, loewis, amaury.forgeotdarc, ocean-city |
| 2011年01月21日 22:39:18 | vstinner | set | messageid: <1295649558.2.0.915282022743.issue10614@psf.upfronthosting.co.za> |
| 2011年01月21日 22:39:16 | vstinner | link | issue10614 messages |
| 2011年01月21日 22:39:16 | vstinner | create |
|