[Python-checkins] cpython: Issue #18901: The sunau getparams method now returns a namedtuple rather than

serhiy.storchaka python-checkins at python.org
Tue Sep 3 23:43:40 CEST 2013


http://hg.python.org/cpython/rev/99d26f32aed3
changeset: 85514:99d26f32aed3
user: Serhiy Storchaka <storchaka at gmail.com>
date: Wed Sep 04 00:43:03 2013 +0300
summary:
 Issue #18901: The sunau getparams method now returns a namedtuple rather than
a plain tuple. Patch by Claudiu Popa.
files:
 Doc/library/sunau.rst | 5 +++--
 Doc/whatsnew/3.4.rst | 7 +++++++
 Lib/sunau.py | 19 ++++++++++++-------
 Lib/test/test_sunau.py | 22 ++++++++++++++++++++++
 Misc/NEWS | 3 +++
 5 files changed, 47 insertions(+), 9 deletions(-)
diff --git a/Doc/library/sunau.rst b/Doc/library/sunau.rst
--- a/Doc/library/sunau.rst
+++ b/Doc/library/sunau.rst
@@ -150,8 +150,9 @@
 
 .. method:: AU_read.getparams()
 
- Returns a tuple ``(nchannels, sampwidth, framerate, nframes, comptype,
- compname)``, equivalent to output of the :meth:`get\*` methods.
+ Returns a :func:`~collections.namedtuple` ``(nchannels, sampwidth,
+ framerate, nframes, comptype, compname)``, equivalent to output of the
+ :meth:`get\*` methods.
 
 
 .. method:: AU_read.readframes(n)
diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst
--- a/Doc/whatsnew/3.4.rst
+++ b/Doc/whatsnew/3.4.rst
@@ -365,6 +365,13 @@
 (Contributed by Antoine Pitrou in :issue:`17804`.)
 
 
+sunau
+-----
+
+The :meth:`~sunau.getparams` method now returns a namedtuple rather than a
+plain tuple. (Contributed by Claudiu Popa in :issue:`18901`.)
+
+
 urllib
 ------
 
diff --git a/Lib/sunau.py b/Lib/sunau.py
--- a/Lib/sunau.py
+++ b/Lib/sunau.py
@@ -51,7 +51,7 @@
 getcomptype() -- returns compression type ('NONE' or 'ULAW')
 getcompname() -- returns human-readable version of
 compression type ('not compressed' matches 'NONE')
- getparams() -- returns a tuple consisting of all of the
+ getparams() -- returns a namedtuple consisting of all of the
 above in the above order
 getmarkers() -- returns None (for compatibility with the
 aifc module)
@@ -103,6 +103,11 @@
 is destroyed.
 """
 
+from collections import namedtuple
+
+_sunau_params = namedtuple('_sunau_params',
+ 'nchannels sampwidth framerate nframes comptype compname')
+
 # from <multimedia/audio_filehdr.h>
 AUDIO_FILE_MAGIC = 0x2e736e64
 AUDIO_FILE_ENCODING_MULAW_8 = 1
@@ -242,9 +247,9 @@
 return 'not compressed'
 
 def getparams(self):
- return self.getnchannels(), self.getsampwidth(), \
- self.getframerate(), self.getnframes(), \
- self.getcomptype(), self.getcompname()
+ return _sunau_params(self.getnchannels(), self.getsampwidth(),
+ self.getframerate(), self.getnframes(),
+ self.getcomptype(), self.getcompname())
 
 def getmarkers(self):
 return None
@@ -381,9 +386,9 @@
 self.setcomptype(comptype, compname)
 
 def getparams(self):
- return self.getnchannels(), self.getsampwidth(), \
- self.getframerate(), self.getnframes(), \
- self.getcomptype(), self.getcompname()
+ return _sunau_getparams(self.getnchannels(), self.getsampwidth(),
+ self.getframerate(), self.getnframes(),
+ self.getcomptype(), self.getcompname())
 
 def tell(self):
 return self._nframeswritten
diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py
--- a/Lib/test/test_sunau.py
+++ b/Lib/test/test_sunau.py
@@ -1,5 +1,6 @@
 from test.support import run_unittest, TESTFN
 import unittest
+import pickle
 import os
 
 import sunau
@@ -62,6 +63,27 @@
 self.assertEqual(self.f.readframes(nframes), output)
 self.f.close()
 
+ def test_getparams(self):
+ self.f = sunau.open(TESTFN, 'w')
+ self.f.setnchannels(nchannels)
+ self.f.setsampwidth(sampwidth)
+ self.f.setframerate(framerate)
+ self.f.setcomptype('ULAW', '')
+ output = b'0円' * nframes * nchannels * sampwidth
+ self.f.writeframes(output)
+ self.f.close()
+
+ self.f = sunau.open(TESTFN, 'rb')
+ params = self.f.getparams()
+ self.assertEqual(params.nchannels, nchannels)
+ self.assertEqual(params.sampwidth, sampwidth)
+ self.assertEqual(params.framerate, framerate)
+ self.assertEqual(params.nframes, nframes)
+ self.assertEqual(params.comptype, 'ULAW')
+
+ dump = pickle.dumps(params)
+ self.assertEqual(pickle.loads(dump), params)
+
 
 def test_main():
 run_unittest(SunAUTest)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -54,6 +54,9 @@
 Library
 -------
 
+- Issue #18901: The sunau getparams method now returns a namedtuple rather than
+ a plain tuple. Patch by Claudiu Popa.
+
 - Issue #17487: The result of the wave getparams method now is pickleable again.
 Patch by Claudiu Popa.
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /