summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-12-14 18:42:22 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-12-14 18:42:22 (GMT)
commit79f19f9e7c1849be68bba57ee78c116714e2c5ea (patch)
treeb94507a79a0fbd36d29ee7f28d0a3d63e2d56b7f /Lib
parent03241e801780edd967923d1cce00c2d07b208e58 (diff)
parent84d28b4ee5983bcb048323a0e56ea4c5498a0652 (diff)
downloadcpython-79f19f9e7c1849be68bba57ee78c116714e2c5ea.zip
cpython-79f19f9e7c1849be68bba57ee78c116714e2c5ea.tar.gz
cpython-79f19f9e7c1849be68bba57ee78c116714e2c5ea.tar.bz2
Issue #19623: Fixed writing to unseekable files in the aifc module.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/aifc.py11
-rw-r--r--Lib/test/test_aifc.py3
-rw-r--r--Lib/test/test_sunau.py28
-rw-r--r--Lib/test/test_wave.py23
4 files changed, 25 insertions, 40 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py
index c1c8ea7..9e64de9 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -790,7 +790,10 @@ class Aifc_write:
self._datalength = (self._datalength + 3) // 4
if self._datalength & 1:
self._datalength = self._datalength + 1
- self._form_length_pos = self._file.tell()
+ try:
+ self._form_length_pos = self._file.tell()
+ except (AttributeError, OSError):
+ self._form_length_pos = None
commlength = self._write_form_length(self._datalength)
if self._aifc:
self._file.write(b'AIFC')
@@ -802,7 +805,8 @@ class Aifc_write:
self._file.write(b'COMM')
_write_ulong(self._file, commlength)
_write_short(self._file, self._nchannels)
- self._nframes_pos = self._file.tell()
+ if self._form_length_pos is not None:
+ self._nframes_pos = self._file.tell()
_write_ulong(self._file, self._nframes)
if self._comptype in (b'ULAW', b'ulaw', b'ALAW', b'alaw', b'G722'):
_write_short(self._file, 8)
@@ -813,7 +817,8 @@ class Aifc_write:
self._file.write(self._comptype)
_write_string(self._file, self._compname)
self._file.write(b'SSND')
- self._ssnd_length_pos = self._file.tell()
+ if self._form_length_pos is not None:
+ self._ssnd_length_pos = self._file.tell()
_write_ulong(self._file, self._datalength + 8)
_write_ulong(self._file, 0)
_write_ulong(self._file, 0)
diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py
index 041b236..ab51437 100644
--- a/Lib/test/test_aifc.py
+++ b/Lib/test/test_aifc.py
@@ -14,9 +14,6 @@ class AifcTest(audiotests.AudioWriteTests,
module = aifc
close_fd = True
test_unseekable_read = None
- test_unseekable_write = None
- test_unseekable_incompleted_write = None
- test_unseekable_overflowed_write = None
class AifcPCM8Test(AifcTest, unittest.TestCase):
diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py
index af9ffec..0f4134e 100644
--- a/Lib/test/test_sunau.py
+++ b/Lib/test/test_sunau.py
@@ -6,10 +6,12 @@ import sys
import sunau
-class SunauPCM8Test(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
+class SunauTest(audiotests.AudioWriteTests,
+ audiotests.AudioTestsWithSourceFile):
module = sunau
+
+
+class SunauPCM8Test(SunauTest, unittest.TestCase):
sndfilename = 'pluck-pcm8.au'
sndfilenframes = 3307
nchannels = 2
@@ -26,10 +28,7 @@ class SunauPCM8Test(audiotests.AudioWriteTests,
""")
-class SunauPCM16Test(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
- module = sunau
+class SunauPCM16Test(SunauTest, unittest.TestCase):
sndfilename = 'pluck-pcm16.au'
sndfilenframes = 3307
nchannels = 2
@@ -48,10 +47,7 @@ class SunauPCM16Test(audiotests.AudioWriteTests,
""")
-class SunauPCM24Test(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
- module = sunau
+class SunauPCM24Test(SunauTest, unittest.TestCase):
sndfilename = 'pluck-pcm24.au'
sndfilenframes = 3307
nchannels = 2
@@ -76,10 +72,7 @@ class SunauPCM24Test(audiotests.AudioWriteTests,
""")
-class SunauPCM32Test(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
- module = sunau
+class SunauPCM32Test(SunauTest, unittest.TestCase):
sndfilename = 'pluck-pcm32.au'
sndfilenframes = 3307
nchannels = 2
@@ -104,10 +97,7 @@ class SunauPCM32Test(audiotests.AudioWriteTests,
""")
-class SunauULAWTest(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
- module = sunau
+class SunauULAWTest(SunauTest, unittest.TestCase):
sndfilename = 'pluck-ulaw.au'
sndfilenframes = 3307
nchannels = 2
diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py
index 549ca89..3eff773 100644
--- a/Lib/test/test_wave.py
+++ b/Lib/test/test_wave.py
@@ -6,10 +6,12 @@ import sys
import wave
-class WavePCM8Test(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
+class WaveTest(audiotests.AudioWriteTests,
+ audiotests.AudioTestsWithSourceFile):
module = wave
+
+
+class WavePCM8Test(WaveTest, unittest.TestCase):
sndfilename = 'pluck-pcm8.wav'
sndfilenframes = 3307
nchannels = 2
@@ -26,10 +28,7 @@ class WavePCM8Test(audiotests.AudioWriteTests,
""")
-class WavePCM16Test(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
- module = wave
+class WavePCM16Test(WaveTest, unittest.TestCase):
sndfilename = 'pluck-pcm16.wav'
sndfilenframes = 3307
nchannels = 2
@@ -50,10 +49,7 @@ class WavePCM16Test(audiotests.AudioWriteTests,
frames = byteswap(frames, 2)
-class WavePCM24Test(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
- module = wave
+class WavePCM24Test(WaveTest, unittest.TestCase):
sndfilename = 'pluck-pcm24.wav'
sndfilenframes = 3307
nchannels = 2
@@ -80,10 +76,7 @@ class WavePCM24Test(audiotests.AudioWriteTests,
frames = byteswap(frames, 3)
-class WavePCM32Test(audiotests.AudioWriteTests,
- audiotests.AudioTestsWithSourceFile,
- unittest.TestCase):
- module = wave
+class WavePCM32Test(WaveTest, unittest.TestCase):
sndfilename = 'pluck-pcm32.wav'
sndfilenframes = 3307
nchannels = 2