Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5efea04

Browse files
committed
use floor division where needed #7681
1 parent ee5383d commit 5efea04

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

Lib/test/test_wave.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from test.support import TESTFN, run_unittest
22
import os
33
import wave
4+
import struct
45
import unittest
56

67
nchannels = 2
@@ -38,6 +39,16 @@ def test_it(self):
3839
self.assertEqual(nframes, self.f.getnframes())
3940
self.assertEqual(self.f.readframes(nframes), output)
4041

42+
def test_issue7681(self):
43+
self.f = wave.open(TESTFN, 'wb')
44+
self.f.setnchannels(nchannels)
45+
self.f.setsampwidth(sampwidth)
46+
self.f.setframerate(framerate)
47+
# Don't call setnframes, make _write_header divide to figure it out
48+
output = b'\0' * nframes * nchannels * sampwidth
49+
self.f.writeframes(output)
50+
51+
4152
def test_main():
4253
run_unittest(TestWave)
4354

Lib/wave.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def readframes(self, nframes):
240240
data = array.array(_array_fmts[self._sampwidth])
241241
nitems = nframes * self._nchannels
242242
if nitems * self._sampwidth > chunk.chunksize - chunk.size_read:
243-
nitems = (chunk.chunksize - chunk.size_read) / self._sampwidth
243+
nitems = (chunk.chunksize - chunk.size_read) // self._sampwidth
244244
data.fromfile(chunk.file.file, nitems)
245245
# "tell" data chunk how much was read
246246
chunk.size_read = chunk.size_read + nitems * self._sampwidth
@@ -461,7 +461,7 @@ def _ensure_header_written(self, datasize):
461461
def _write_header(self, initlength):
462462
self._file.write(b'RIFF')
463463
if not self._nframes:
464-
self._nframes = initlength / (self._nchannels * self._sampwidth)
464+
self._nframes = initlength // (self._nchannels * self._sampwidth)
465465
self._datalength = self._nframes * self._nchannels * self._sampwidth
466466
self._form_length_pos = self._file.tell()
467467
self._file.write(struct.pack('<l4s4slhhllhh4s',

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ C-API
209209
Library
210210
-------
211211

212+
- Issue #7681: Use floor division in appropiate places in the wave module.
213+
212214
- Issue #5372: Drop the reuse of .o files in Distutils' ccompiler (since
213215
Extension extra options may change the output without changing the .c
214216
file). Initial patch by Collin Winter.

0 commit comments

Comments
 (0)