Message91854
The zipfile.ZipFile.open() behavior with mode 'U' or 'rU' is not quite
as advertised in
http://docs.python.org/library/zipfile.html#zipfile.ZipFile.open
Here is an example:
$ echo -ne "This is an example\r\nWhich demonstrates a problem\r\nwith
ZipFile.open(..., 'U')\r\n" > foo.txt
$ cat -v foo.txt
This is an example^M
Which demonstrates a problem^M
with ZipFile.open(..., 'U')^M
$ zip foo.zip foo.txt
adding: foo.txt (deflated 1%)
$ python
Python 2.6.2 (r262:71600, Aug 21 2009, 17:52:12)
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> open("foo.txt", 'U').read()
"This is an example\nWhich demonstrates a problem\nwith
ZipFile.open(..., 'U')\n"
>>> from zipfile import ZipFile
>>> ZipFile("foo.zip").open("foo.txt", 'U').read()
"This is an example\r\nWhich demonstrates a problem\r\nwith
ZipFile.open(..., 'U')\r\n"
>>>
The open() method was added here:
http://bugs.python.org/issue1121142
The cause is that the universal newline implementation is specific to
readline(), which also implements readlines() and next() as well.
Support was never added for read(), which is independent.
Note that test_zipfile.UniversalNewlineTests.readTest() passes. This is
suspect because it's explicitly coded to *not* expect translation of new
line sequences. |
|
Date |
User |
Action |
Args |
2009-08-22 06:22:02 | ryles | set | recipients:
+ ryles |
2009-08-22 06:22:02 | ryles | set | messageid: <1250922122.86.0.650490470964.issue6759@psf.upfronthosting.co.za> |
2009-08-22 06:22:01 | ryles | link | issue6759 messages |
2009-08-22 06:22:00 | ryles | create | |
|