homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Sergey.Dorofeev
Recipients Sergey.Dorofeev, amaury.forgeotdarc, ethan.furman, loewis, ocean-city, serhiy.storchaka, umedoblock, vstinner
Date 2013年10月18日.07:30:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1382081431.46.0.87355876622.issue10614@psf.upfronthosting.co.za>
In-reply-to
Content
I'd like to submit patch to support zip archives created on systems that use non-US codepage (e.g. russian CP866).
Codepage would be specified in additional parameter of ZipFile constructor, named "codepage".
If it is not specified, old behavior is preserved (use CP437).
--- zipfile.py-orig 2013年09月18日 16:45:56.000000000 +0400
+++ zipfile.py 2013年10月15日 00:24:06.105157572 +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, codepage='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.codepage = codepage
 # Check if we were passed a file-like object
 if isinstance(file, str):
@@ -1002,7 +1003,7 @@
 filename = filename.decode('utf-8')
 else:
 # Historical ZIP filename encoding
- filename = filename.decode('cp437')
+ filename = filename.decode(self.codepage)
 # 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.codepage)
 if fname_str != zinfo.orig_filename:
 raise BadZipFile(
History
Date User Action Args
2013年10月18日 07:30:31Sergey.Dorofeevsetrecipients: + Sergey.Dorofeev, loewis, amaury.forgeotdarc, vstinner, ocean-city, ethan.furman, umedoblock, serhiy.storchaka
2013年10月18日 07:30:31Sergey.Dorofeevsetmessageid: <1382081431.46.0.87355876622.issue10614@psf.upfronthosting.co.za>
2013年10月18日 07:30:31Sergey.Dorofeevlinkissue10614 messages
2013年10月18日 07:30:30Sergey.Dorofeevcreate

AltStyle によって変換されたページ (->オリジナル) /