]> granicus.if.org Git - python/commitdiff
Issue #18901: The sunau getparams method now returns a namedtuple rather than
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 3 Sep 2013 21:43:03 +0000 (00:43 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 3 Sep 2013 21:43:03 +0000 (00:43 +0300)
a plain tuple.  Patch by Claudiu Popa.

Doc/library/sunau.rst
Doc/whatsnew/3.4.rst
Lib/sunau.py
Lib/test/test_sunau.py
Misc/NEWS

index 4bdb99bea6161a033e53c1760bd6f05e1eba6778..eae710d03bf49ad5e1492b5933393ec681eaea25 100644 (file)
@@ -150,8 +150,9 @@ AU_read objects, as returned by :func:`.open` above, have the following methods:
 
 .. 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)
index 218b8229776dc1db659179374bc9586d5d423fc3..427083af43f703db699abf98f426a6243f8ae88b 100644 (file)
@@ -365,6 +365,13 @@ Streaming struct unpacking using :func:`struct.iter_unpack`.
 (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
 ------
 
index 6775a53cf73e0e29ae5bc6ac7398e9e51823e65c..7d7cd6c6886f603c39869c17534f8a0adb67d168 100644 (file)
@@ -51,7 +51,7 @@ This returns an instance of a class with the following public methods:
         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 @@ The close() method is called automatically when the class instance
 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 @@ class Au_read:
             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 @@ class Au_write:
         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
index 339ab576d5cb8c62c1177de763855e2367bd71a1..c381d07a31beb0be6814a4ffa0bd2a3f15c6dc09 100644 (file)
@@ -1,5 +1,6 @@
 from test.support import run_unittest, TESTFN
 import unittest
+import pickle
 import os
 
 import sunau
@@ -62,6 +63,27 @@ class SunAUTest(unittest.TestCase):
         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)
index 328f3fe0cef68f6df2724bafd98c537689e4bc50..9539d62e13fdff48e55084885eea5c60b06f6732 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -54,6 +54,9 @@ Core and Builtins
 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.