Message200311
| Author |
Sergey.Dorofeev |
| Recipients |
Sergey.Dorofeev, amaury.forgeotdarc, ethan.furman, loewis, ocean-city, serhiy.storchaka, umedoblock, vstinner |
| Date |
2013年10月18日.22:08:51 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<CANYos10Fo6vOE+4hBc-os1794JTN6FCP5Yo=VhdtsQu0UiCBtA@mail.gmail.com> |
| In-reply-to |
<CAMpsgwamFRy58Cjc1+tDODkZyX9=JnCdxCcJj1PJ+wVswvhDyw@mail.gmail.com> |
| Content |
OK, here you are:
--- zipfile.py-orig 2013年09月18日 16:45:56.000000000 +0400
+++ zipfile.py 2013年10月19日 01:59:07.444346674 +0400
@@ -885,7 +885,7 @@
fp = None # Set here since __del__ checks it
_windows_illegal_name_trans_table = None
- def __init__(self, file, mode="r", compression=ZIP_STORED,
allowZip64=False):
+ def __init__(self, file, mode="r", compression=ZIP_STORED,
allowZip64=False, encoding='cp437'):
"""Open the ZIP file with mode read "r", write "w" or append
"a"."""
if mode not in ("r", "w", "a"):
raise RuntimeError('ZipFile() requires mode "r", "w", or "a"')
@@ -901,6 +901,7 @@
self.mode = key = mode.replace('b', '')[0]
self.pwd = None
self._comment = b''
+ self.encoding = encoding
# Check if we were passed a file-like object
if isinstance(file, str):
@@ -1001,8 +1002,8 @@
# UTF-8 file names extension
filename = filename.decode('utf-8')
else:
- # Historical ZIP filename encoding
- filename = filename.decode('cp437')
+ # Historical ZIP filename encoding, default is 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])
@@ -1157,7 +1158,7 @@
# 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(
On Fri, Oct 18, 2013 at 11:47 AM, STINNER Victor <report@bugs.python.org>wrote:
>
> STINNER Victor added the comment:
>
> Please rename codepage to encoding. By the way, 437 is a codepage, cp437 is
> a (python) encoding.
>
> I don't think that ZIP is limited to windows. I uncompressed zip files many
> times on various OSes, github also produces zip (and github is probably not
> using windows). And codepage term is only used on windows. Mac OS 9 users
> might produce mac roman filenames.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue10614>
> _______________________________________
> |
|