From 5efea0430caf2c6e066ae2f32e4c28f65d42d69a Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Wed, 13 Jan 2010 03:49:50 +0000 Subject: use floor division where needed #7681 --- Lib/test/test_wave.py | 11 +++++++++++ Lib/wave.py | 4 ++-- Misc/NEWS | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py index a7746fd..1bcaa242 100644 --- a/Lib/test/test_wave.py +++ b/Lib/test/test_wave.py @@ -1,6 +1,7 @@ from test.support import TESTFN, run_unittest import os import wave +import struct import unittest nchannels = 2 @@ -38,6 +39,16 @@ class TestWave(unittest.TestCase): self.assertEqual(nframes, self.f.getnframes()) self.assertEqual(self.f.readframes(nframes), output) + def test_issue7681(self): + self.f = wave.open(TESTFN, 'wb') + self.f.setnchannels(nchannels) + self.f.setsampwidth(sampwidth) + self.f.setframerate(framerate) + # Don't call setnframes, make _write_header divide to figure it out + output = b'\0' * nframes * nchannels * sampwidth + self.f.writeframes(output) + + def test_main(): run_unittest(TestWave) diff --git a/Lib/wave.py b/Lib/wave.py index 8455522..2fa9b6b 100644 --- a/Lib/wave.py +++ b/Lib/wave.py @@ -240,7 +240,7 @@ class Wave_read: data = array.array(_array_fmts[self._sampwidth]) nitems = nframes * self._nchannels if nitems * self._sampwidth > chunk.chunksize - chunk.size_read: - nitems = (chunk.chunksize - chunk.size_read) / self._sampwidth + nitems = (chunk.chunksize - chunk.size_read) // self._sampwidth data.fromfile(chunk.file.file, nitems) # "tell" data chunk how much was read chunk.size_read = chunk.size_read + nitems * self._sampwidth @@ -461,7 +461,7 @@ class Wave_write: def _write_header(self, initlength): self._file.write(b'RIFF') if not self._nframes: - self._nframes = initlength / (self._nchannels * self._sampwidth) + self._nframes = initlength // (self._nchannels * self._sampwidth) self._datalength = self._nframes * self._nchannels * self._sampwidth self._form_length_pos = self._file.tell() self._file.write(struct.pack('