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 terry.reedy
Recipients jtidman, terry.reedy
Date 2011-02-11.19:49:18
SpamBayes Score 8.8535415e-07
Marked as misclassified No
Message-id <1297453761.98.0.929809281413.issue11126@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-02-11 19:49:22terry.reedysetrecipients: + terry.reedy, jtidman
2011-02-11 19:49:21terry.reedysetmessageid: <1297453761.98.0.929809281413.issue11126@psf.upfronthosting.co.za>
2011-02-11 19:49:19terry.reedylinkissue11126 messages
2011-02-11 19:49:18terry.reedycreate