]> granicus.if.org Git - python/commitdiff
Merged revisions 85970 via svnmerge from
authorGeorg Brandl <georg@python.org>
Sat, 20 Nov 2010 11:29:58 +0000 (11:29 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 20 Nov 2010 11:29:58 +0000 (11:29 +0000)
svn+ssh://svn.python.org/python/branches/py3k

........
  r85970 | georg.brandl | 2010-10-30 10:29:28 +0200 (Sa, 30 Okt 2010) | 1 line

  #10198: fix duplicate header when writeframes() is called with an empty string.
........

Lib/wave.py
Misc/NEWS

index 2fa9b6b11fb1ac116c34f12042572cecf3be3c76..24839ca4ce1c5cfbbdf34750ec9e75aa7541b210 100644 (file)
@@ -319,6 +319,7 @@ class Wave_write:
         self._nframeswritten = 0
         self._datawritten = 0
         self._datalength = 0
+        self._headerwritten = False
 
     def __del__(self):
         self.close()
@@ -449,7 +450,7 @@ class Wave_write:
     #
 
     def _ensure_header_written(self, datasize):
-        if not self._datawritten:
+        if not self._headerwritten:
             if not self._nchannels:
                 raise Error('# channels not specified')
             if not self._sampwidth:
@@ -459,6 +460,7 @@ class Wave_write:
             self._write_header(datasize)
 
     def _write_header(self, initlength):
+        assert not self._headerwritten
         self._file.write(b'RIFF')
         if not self._nframes:
             self._nframes = initlength // (self._nchannels * self._sampwidth)
@@ -472,8 +474,10 @@ class Wave_write:
             self._sampwidth * 8, 'data'))
         self._data_length_pos = self._file.tell()
         self._file.write(struct.pack('<l', self._datalength))
+        self._headerwritten = True
 
     def _patchheader(self):
+        assert self._headerwritten
         if self._datawritten == self._datalength:
             return
         curpos = self._file.tell()
index fc9f5a61cc75cb18f58434dc1d839a0ab7464d0a..b51e6e67b11215e6a6919f232bb4b0e912ae50fe 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #10198: fix duplicate header written to wave files when writeframes()
+  is called without data.
+
 Build
 -----