File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from test .support import TESTFN , run_unittest
22import os
33import wave
4+ import struct
45import unittest
56
67nchannels = 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+
4152def test_main ():
4253 run_unittest (TestWave )
4354
Original file line number Diff line number Diff 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' ,
Original file line number Diff line number Diff line change @@ -209,6 +209,8 @@ C-API
209209Library
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.
You can’t perform that action at this time.
0 commit comments