Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d35e75

Browse files
committed
#17818: aifc.getparams now returns a namedtuple.
Patch by Claudiu Popa.
1 parent 840c310 commit 4d35e75

6 files changed

Lines changed: 55 additions & 8 deletions

File tree

Doc/library/aifc.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ following methods:
9696

9797
.. method:: aifc.getparams()
9898

99-
Return a tuple consisting of all of the above values in the above order.
99+
Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth,
100+
framerate, nframes, comptype, compname)``, equivalent to output of the
101+
:meth:`get\*` methods.
100102

101103

102104
.. method:: aifc.getmarkers()

Doc/whatsnew/3.4.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ be specified on the command line, and ``-f`` is a shorthand for ``-o
173173
FAIL_FAST`` (to parallel the similar option supported by the :mod:`unittest`
174174
CLI). (Contributed by R. David Murray in :issue:`11390`.)
175175

176+
aifc
177+
----
178+
179+
The :meth:`~aifc.getparams` method now returns a namedtuple rather than a
180+
plain tuple. (Contributed by Claudiu Popa in :issue:`17818`.)
181+
176182

177183
functools
178184
---------

Lib/aifc.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
getcomptype() -- returns compression type ('NONE' for AIFF files)
7070
getcompname() -- returns human-readable version of
7171
compression type ('not compressed' for AIFF files)
72-
getparams() -- returns a tuple consisting of all of the
72+
getparams() -- returns a namedtuple consisting of all of the
7373
above in the above order
7474
getmarkers() -- get the list of marks in the audio file or None
7575
if there are no marks
@@ -252,6 +252,11 @@ def _write_float(f, x):
252252
_write_ulong(f, lomant)
253253

254254
from chunk import Chunk
255+
from collections import namedtuple
256+
257+
_aifc_params = namedtuple('_aifc_params',
258+
'nchannels sampwidth framerate nframes comptype compname')
259+
255260

256261
class Aifc_read:
257262
# Variables used in this class:
@@ -378,9 +383,9 @@ def getcompname(self):
378383
## return self._version
379384

380385
def getparams(self):
381-
return self.getnchannels(), self.getsampwidth(), \
382-
self.getframerate(), self.getnframes(), \
383-
self.getcomptype(), self.getcompname()
386+
return _aifc_params(self.getnchannels(), self.getsampwidth(),
387+
self.getframerate(), self.getnframes(),
388+
self.getcomptype(), self.getcompname())
384389

385390
def getmarkers(self):
386391
if len(self._markers) == 0:
@@ -658,8 +663,8 @@ def setparams(self, params):
658663
def getparams(self):
659664
if not self._nchannels or not self._sampwidth or not self._framerate:
660665
raise Error('not all parameters set')
661-
return self._nchannels, self._sampwidth, self._framerate, \
662-
self._nframes, self._comptype, self._compname
666+
return _aifc_params(self._nchannels, self._sampwidth, self._framerate,
667+
self._nframes, self._comptype, self._compname)
663668

664669
def setmark(self, id, pos, name):
665670
if id <= 0:

Lib/test/test_aifc.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import io
55
import struct
6+
import pickle
67

78
import aifc
89

@@ -31,6 +32,7 @@ def test_skipunknown(self):
3132

3233
def test_params(self):
3334
f = self.f = aifc.open(self.sndfilepath)
35+
params = f.getparams()
3436
self.assertEqual(f.getfp().name, self.sndfilepath)
3537
self.assertEqual(f.getnchannels(), 2)
3638
self.assertEqual(f.getsampwidth(), 2)
@@ -43,6 +45,36 @@ def test_params(self):
4345
(2, 2, 48000, 14400, b'NONE', b'not compressed'),
4446
)
4547

48+
params = f.getparams()
49+
self.assertEqual(params.nchannels, 2)
50+
self.assertEqual(params.sampwidth, 2)
51+
self.assertEqual(params.framerate, 48000)
52+
self.assertEqual(params.nframes, 14400)
53+
self.assertEqual(params.comptype, b'NONE')
54+
self.assertEqual(params.compname, b'not compressed')
55+
56+
def test_params_added(self):
57+
f = self.f = aifc.open(TESTFN, 'wb')
58+
f.aiff()
59+
f.setparams((1, 1, 1, 1, b'NONE', b''))
60+
f.close()
61+
62+
f = self.f = aifc.open(TESTFN, 'rb')
63+
params = f.getparams()
64+
self.assertEqual(params.nchannels, f.getnchannels())
65+
self.assertEqual(params.sampwidth, f.getsampwidth())
66+
self.assertEqual(params.framerate, f.getframerate())
67+
self.assertEqual(params.nframes, f.getnframes())
68+
self.assertEqual(params.comptype, f.getcomptype())
69+
self.assertEqual(params.compname, f.getcompname())
70+
71+
def test_getparams_picklable(self):
72+
self.f = aifc.open(self.sndfilepath)
73+
params = self.f.getparams()
74+
dump = pickle.dumps(params)
75+
self.assertEqual(pickle.loads(dump), params)
76+
self.f.close()
77+
4678
def test_context_manager(self):
4779
with open(self.sndfilepath, 'rb') as testfile:
4880
with aifc.open(testfile) as f:

Lib/test/test_pyclbr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_others(self):
158158
cm('random', ignore=('Random',)) # from _random import Random as CoreGenerator
159159
cm('cgi', ignore=('log',)) # set with = in module
160160
cm('pickle')
161-
cm('aifc', ignore=('openfp',)) # set with = in module
161+
cm('aifc', ignore=('openfp', '_aifc_params')) # set with = in module
162162
cm('sre_parse', ignore=('dump',)) # from sre_constants import *
163163
cm('pdb')
164164
cm('pydoc')

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ Core and Builtins
166166
Library
167167
-------
168168

169+
- Issue #17818: aifc.getparams now returns a namedtuple.
170+
169171
- Issue #18549: Eliminate dead code in socket_ntohl()
170172

171173
- Issue #18530: Remove additional stat call from posixpath.ismount.

0 commit comments

Comments
 (0)