Message128424
I agree that the _sampwidth multiplier is needed regardless of endianness.
The simplest option would be to pull the _datawritten statement out of the alternation, making the code read
if self._sampwidth > 1 and big_endian:
import array
data = array.array(_array_fmts[self._sampwidth], data)
data.byteswap()
data.tofile(self._file)
else:
self._file.write(data)
self._datawritten = self._datawritten + len(data) * self._sampwidth
Note: while _sampwidth is initialized to 0, _ensure_header_written() checks that it is not 0, and it is used elsewhere as a divisor.
The above adds a usually unneeded multiply by 1, but the alternative requires duplication of _file.write and two _datawritten statements
if self._sampwidth > 1:
if big_endian:
import array
data = array.array(_array_fmts[self._sampwidth], data)
data.byteswap()
data.tofile(self._file)
else: # little_endian
self._file.write(data)
self._datawritten = self._datawritten + len(data) * self._sampwidth
else: # _sampwidth == 1
self._file.write(data)
self._datawritten = self._datawritten + len(data)
This module is new to me. Can you think of any way to test this issue, perhaps by writing to StringIO file? This is not a heavily tested module ;-)
In 3.3, the openfp synonym for open could perhaps be deprecated. |
|
Date |
User |
Action |
Args |
2011-02-11 19:49:22 | terry.reedy | set | recipients:
+ terry.reedy, jtidman |
2011-02-11 19:49:21 | terry.reedy | set | messageid: <1297453761.98.0.929809281413.issue11126@psf.upfronthosting.co.za> |
2011-02-11 19:49:19 | terry.reedy | link | issue11126 messages |
2011-02-11 19:49:18 | terry.reedy | create | |
|