summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-09-03 21:28:43 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-09-03 21:28:43 (GMT)
commit4c6a020a2d1a6d2bee1bbe4e426cbc8f7ca2cf9a (patch)
treef4367eaa39d6987ba720e25143b057649e5953c0 /Lib
parentc6171e49ab2aee5807bcb6c0f77d0de13a164a99 (diff)
downloadcpython-4c6a020a2d1a6d2bee1bbe4e426cbc8f7ca2cf9a.zip
cpython-4c6a020a2d1a6d2bee1bbe4e426cbc8f7ca2cf9a.tar.gz
cpython-4c6a020a2d1a6d2bee1bbe4e426cbc8f7ca2cf9a.tar.bz2
Issue #17487: The result of the wave getparams method now is pickleable again.
Patch by Claudiu Popa.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_wave.py13
-rw-r--r--Lib/wave.py6
2 files changed, 16 insertions, 3 deletions
diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py
index b70f917..30dca90b 100644
--- a/Lib/test/test_wave.py
+++ b/Lib/test/test_wave.py
@@ -1,5 +1,6 @@
from test.support import TESTFN, unlink
import wave
+import pickle
import unittest
nchannels = 2
@@ -69,6 +70,18 @@ class TestWave(unittest.TestCase):
self.assertEqual(params.comptype, self.f.getcomptype())
self.assertEqual(params.compname, self.f.getcompname())
+ def test_getparams_picklable(self):
+ self.f = wave.open(TESTFN, 'wb')
+ self.f.setnchannels(nchannels)
+ self.f.setsampwidth(sampwidth)
+ self.f.setframerate(framerate)
+ self.f.close()
+
+ self.f = wave.open(TESTFN, 'rb')
+ params = self.f.getparams()
+ dump = pickle.dumps(params)
+ self.assertEqual(pickle.loads(dump), params)
+
def test_wave_write_context_manager_calls_close(self):
# Close checks for a minimum header and will raise an error
# if it is not set, so this proves that close is called.
diff --git a/Lib/wave.py b/Lib/wave.py
index f43569e..1c6380e 100644
--- a/Lib/wave.py
+++ b/Lib/wave.py
@@ -87,7 +87,7 @@ import sys
from chunk import Chunk
from collections import namedtuple
-_result = namedtuple('params',
+_wave_params = namedtuple('_wave_params',
'nchannels sampwidth framerate nframes comptype compname')
class Wave_read:
@@ -212,7 +212,7 @@ class Wave_read:
return self._compname
def getparams(self):
- return _result(self.getnchannels(), self.getsampwidth(),
+ return _wave_params(self.getnchannels(), self.getsampwidth(),
self.getframerate(), self.getnframes(),
self.getcomptype(), self.getcompname())
@@ -410,7 +410,7 @@ class Wave_write:
def getparams(self):
if not self._nchannels or not self._sampwidth or not self._framerate:
raise Error('not all parameters set')
- return _result(self._nchannels, self._sampwidth, self._framerate,
+ return _wave_params(self._nchannels, self._sampwidth, self._framerate,
self._nframes, self._comptype, self._compname)
def setmark(self, id, pos, name):