[issue10614] ZipFile: add a filename_encoding argument

2013-10-18 Thread Sergey Dorofeev

Sergey Dorofeev added the comment:

OK, here you are:

--- zipfile.py-orig 2013-09-18 16:45:56.0 +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 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 
> <http://bugs.python.org/issue10614>
> ___
>

--

___
Python tracker 
<http://bugs.python.org/issue10614>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10614] ZipFile: add a filename_encoding argument

2013-10-18 Thread Sergey Dorofeev

Sergey Dorofeev added the comment:

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.0 +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(

--
nosy: +Sergey.Dorofeev

___
Python tracker 
<http://bugs.python.org/issue10614>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14313] zipfile does not unpack files from archive (files extracted have zero length)

2012-03-14 Thread Sergey Dorofeev

New submission from Sergey Dorofeev :

unzip does extract files but zipfile no
works fine with python2.7 but fails with python 3.2.2
tested on solaris 11 express and windows xp

>>> import zipfile
>>> zipfile.ZipFile("test.zip")

>>> z=_
>>> z.namelist
>
>>> z.namelist()
['19A7B5A4.PKT']
>>> z.read('19A7B5A4.PKT')
b''

--
components: Library (Lib)
files: test.zip
messages: 155854
nosy: fidoman
priority: normal
severity: normal
status: open
title: zipfile does not unpack files from archive (files extracted have zero 
length)
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file24857/test.zip

___
Python tracker 
<http://bugs.python.org/issue14313>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13688] ast.literal_eval fails on octal numbers

2011-12-31 Thread Sergey Dorofeev

Sergey Dorofeev  added the comment:

python 3 feature - should use 0o10
need to rebuild data file :(

--
resolution:  -> rejected
status: open -> closed

___
Python tracker 
<http://bugs.python.org/issue13688>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue13688] ast.literal_eval fails on octal numbers

2011-12-31 Thread Sergey Dorofeev

New submission from Sergey Dorofeev :

Python 3.2.2 (default, Nov 16 2011, 10:58:44) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.literal_eval('10')
10
>>> ast.literal_eval('0x10')
16
>>> ast.literal_eval('010')
Traceback (most recent call last):
  File "", line 1, in 
  File "/opt/python322/lib/python3.2/ast.py", line 48, in literal_eval
node_or_string = parse(node_or_string, mode='eval')
  File "/opt/python322/lib/python3.2/ast.py", line 36, in parse
return compile(source, filename, mode, PyCF_ONLY_AST)
  File "", line 1
010
  ^
SyntaxError: invalid token

--
components: Library (Lib)
messages: 150414
nosy: fidoman
priority: normal
severity: normal
status: open
title: ast.literal_eval fails on octal numbers
versions: Python 3.2

___
Python tracker 
<http://bugs.python.org/issue13688>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com