[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PROPOSAL] Using binary mode in Python open() calls

From: Michael Haggerty <mhagger_at_alum.mit.edu>
Date: 2006-04-17 22:27:58 CEST

Paul Burba wrote:
> So I'm taking a new look at this and applying lessons learned in the hope
> I can make some changes to the scripts that are relatively unobtrusive,
> won't affect other platforms, and will make our lives testing the OS400
> port easier.
>
> The first category of "fixes" I'd like to present for consideration are
> the truly "general" in nature, i.e. no OS400 dependent script code. And
> the first of these relates to the built-in Python function open(). For
> those of you who remember the CCSID mess with apr_file_open() the
> situation is not all that different: files on the OS400 are tagged with
> CCSIDs representing the file's encoding and reading/writing/creating test
> to these files presents a host of problems when the file is not opened in
> binary mode. All of these problems are easily avoided by using the 'b'
> mode with open().
>
> So my question is: If all open() calls in the test scripts were done in
> binary mode would this have any adverse effect on other platforms?
>
> I've already tried this on XP and the tests run normally. I've looked at
> the scripts and don't see any potential problems (yet). If any Python
> experts would like to weigh in on this I'd appreciate it.

I can think of lots of reasons to *expect* problems switching all file
access to binary mode. The fact that no problems turned up in your XP
test should be considered to be a lucky coincidence until proven otherwise.

Therefore, I think that this change has to be justified on a
case-by-case basis. In the cases that you have looked at, why does it work?

Perhaps it works because the only files that are read by Python using
the binary option were also written by Python in binary mode. This
would result in the errors canceling each other out and the tests passing.

However, this leaves other problems unaddressed:

- If a file is opened with the binary option, people reading the code
will be misled to think that the file contains non-text information.
Therefore, code clarity is reduced.

- It will not occur to authors of future tests to open text files in
non-text mode, so future tests will likely be broken on OS400.

- The contents of the file itself would not be in the correct text
format for the local platform. This would make it difficult to look at
or process a test's intermediate results using the platform's standard
tools.

> All of these problems are easily avoided by using the 'b' mode with
> open().

Just a very naive question then: why does the OS400 version of stdio (or
Python) do translation when opening a text-mode file? Why not treat
text files the same as binary in general on this platform?

Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Apr 17 22:50:54 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.