diff -r d232cff25bbd Doc/library/aifc.rst --- a/Doc/library/aifc.rst Sat Apr 27 00:20:04 2013 +0200 +++ b/Doc/library/aifc.rst Sat Apr 27 07:36:43 2013 +0300 @@ -96,7 +96,7 @@ .. method:: aifc.getparams() - Return a tuple consisting of all of the above values in the above order. + Return a :func:`~collections.namedtuple` consisting of all of the above values in the above order. .. method:: aifc.getmarkers() diff -r d232cff25bbd Doc/whatsnew/3.4.rst --- a/Doc/whatsnew/3.4.rst Sat Apr 27 00:20:04 2013 +0200 +++ b/Doc/whatsnew/3.4.rst Sat Apr 27 07:36:43 2013 +0300 @@ -174,6 +174,12 @@ The :meth:`~wave.getparams` method now returns a namedtuple rather than a plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.) +aifc +---- + +The :meth:`~aifc.getparams` method now returns a namedtuple rather than a +plain tuple. (Contributed by Claudiu Popa in :issue:`17818`.) + Optimizations ============= diff -r d232cff25bbd Lib/aifc.py --- a/Lib/aifc.py Sat Apr 27 00:20:04 2013 +0200 +++ b/Lib/aifc.py Sat Apr 27 07:36:43 2013 +0300 @@ -69,7 +69,7 @@ getcomptype() -- returns compression type ('NONE' for AIFF files) getcompname() -- returns human-readable version of compression type ('not compressed' for AIFF files) - getparams() -- returns a tuple consisting of all of the + getparams() -- returns a namedtuple consisting of all of the above in the above order getmarkers() -- get the list of marks in the audio file or None if there are no marks @@ -252,6 +252,11 @@ _write_ulong(f, lomant) from chunk import Chunk +from collections import namedtuple + +_result = namedtuple('params', + 'nchannels sampwidth framerate nframes comptype compname') + class Aifc_read: # Variables used in this class: @@ -378,9 +383,9 @@ ## return self._version def getparams(self): - return self.getnchannels(), self.getsampwidth(), \ - self.getframerate(), self.getnframes(), \ - self.getcomptype(), self.getcompname() + return _result(self.getnchannels(), self.getsampwidth(), + self.getframerate(), self.getnframes(), + self.getcomptype(), self.getcompname()) def getmarkers(self): if len(self._markers) == 0: @@ -658,8 +663,8 @@ def getparams(self): if not self._nchannels or not self._sampwidth or not self._framerate: raise Error('not all parameters set') - return self._nchannels, self._sampwidth, self._framerate, \ - self._nframes, self._comptype, self._compname + return _result(self._nchannels, self._sampwidth, self._framerate, + self._nframes, self._comptype, self._compname) def setmark(self, id, pos, name): if id <= 0: diff -r d232cff25bbd Lib/test/test_aifc.py --- a/Lib/test/test_aifc.py Sat Apr 27 00:20:04 2013 +0200 +++ b/Lib/test/test_aifc.py Sat Apr 27 07:36:43 2013 +0300 @@ -31,18 +31,32 @@ def test_params(self): f = self.f = aifc.open(self.sndfilepath) + params = f.getparams() self.assertEqual(f.getfp().name, self.sndfilepath) - self.assertEqual(f.getnchannels(), 2) - self.assertEqual(f.getsampwidth(), 2) - self.assertEqual(f.getframerate(), 48000) - self.assertEqual(f.getnframes(), 14400) - self.assertEqual(f.getcomptype(), b'NONE') - self.assertEqual(f.getcompname(), b'not compressed') + self.assertEqual(f.getnchannels(), params.nchannels) + self.assertEqual(f.getsampwidth(), params.sampwidth) + self.assertEqual(f.getframerate(), params.framerate) + self.assertEqual(f.getnframes(), params.nframes) + self.assertEqual(f.getcomptype(), params.comptype) + self.assertEqual(f.getcompname(), params.compname) self.assertEqual( f.getparams(), (2, 2, 48000, 14400, b'NONE', b'not compressed'), ) + def test_params_added(self): + f = self.f = aifc.open(TESTFN, 'wb') + f.aiff() + f.setparams((1, 1, 1, 1, b'NONE', b'')) + params = f.getparams() + self.assertEqual(params.nchannels, 1) + self.assertEqual(params.sampwidth, 1) + self.assertEqual(params.framerate, 1) + self.assertEqual(params.nframes, 1) + self.assertEqual(params.comptype, b'NONE') + self.assertEqual(params.compname, b'') + + def test_context_manager(self): with open(self.sndfilepath, 'rb') as testfile: with aifc.open(testfile) as f: