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 ryles
Recipients ryles
Date 2009-08-22.06:22:00
SpamBayes Score 6.4582033e-09
Marked as misclassified No
Message-id <1250922122.86.0.650490470964.issue6759@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-08-22 06:22:02rylessetrecipients: + ryles
2009-08-22 06:22:02rylessetmessageid: <1250922122.86.0.650490470964.issue6759@psf.upfronthosting.co.za>
2009-08-22 06:22:01ryleslinkissue6759 messages
2009-08-22 06:22:00rylescreate