[issue11160] ZipFile.comment expects bytes
New submission from Xuanji Li <xuanji@gmail.com>: The documentation for zipfile describes ZipFile.comment as "The comment text associated with the ZIP file." From reading this I expect that setting it to a string is ok; however ZipFile.comment must actually be set to bytes (or a bytes-like object, I am not very sure). This may also unexpectedly affect old code because I saw one patch on the bug tracker that was written just last year that set ZipFile.comment to a string. IMO there are 2 ways to fix: 1) Change docs to mention that ZipFile.comment only accepts bytes 2) Patch zipfile.py to accept string and try to convert, throwing an error if the conversion fails ---------- assignee: docs@python components: Documentation, Library (Lib) messages: 128217 nosy: docs@python, haypo, xuanji priority: normal severity: normal status: open title: ZipFile.comment expects bytes versions: Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11160> _______________________________________
yeswanth <swamiyeswanth@yahoo.com> added the comment: IMO the Zipfile.comment should accept strings too instead of just accepting bytes , so patching should help i guess ---------- nosy: +swamiyeswanth _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11160> _______________________________________
yeswanth <swamiyeswanth@yahoo.com> added the comment: can we use str.encode() function to convert string into bytes ? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11160> _______________________________________
STINNER Victor <victor.stinner@haypocalc.com> added the comment:
can we use str.encode() function to convert string into bytes ?
Can you try different ZIP archivers to check which encoding is expected? WinZip, WinRAR, 7-zip, "zip" command line program on Linux, etc. And do you have any reference into a ZIP documentation? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11160> _______________________________________
Serhiy Storchaka added the comment: The ZIP specification says: """ If general purpose bit 11 is unset, the file name and comment should conform to the original ZIP character encoding. If general purpose bit 11 is set, the filename and comment must support The Unicode Standard, Version 4.1.0 or greater using the character encoding form defined by the UTF-8 storage specification. The Unicode Standard is published by the The Unicode Consortium (www.unicode.org). UTF-8 encoded data stored within ZIP files is expected to not include a byte order mark (BOM). """ Also there is extension for UTF-8 encoded file comment. All this means the file comment should be interpreted as an unicode string. However the specification says nothing about .ZIP file comment (except that encryption or data authentication is applied to it). Since changeset 4186f20d9fa4 ZipFile.comment raises TypeError on try to assign non-bytes. I think the documentation should be clarified. ---------- components: -Library (Lib) nosy: +serhiy.storchaka stage: -> needs patch type: -> enhancement versions: +Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue11160> _______________________________________
participants (4)
-
Serhiy Storchaka
-
STINNER Victor
-
Xuanji Li
-
yeswanth