cpython: a62f59667c9e (original) (raw)

Mercurial > cpython

changeset 85534:a62f59667c9e

Issue #18878: sunau.open now supports the context manager protocol. Based on patches by Claudiu Popa and R. David Murray. [#18878]

Serhiy Storchaka storchaka@gmail.com
date Thu, 05 Sep 2013 17:01:53 +0300
parents ac27d979078a
children cecec75c2250 86ab7b7c173e
files Doc/whatsnew/3.4.rst Lib/sunau.py Lib/test/test_sunau.py Misc/NEWS
diffstat 4 files changed, 72 insertions(+), 15 deletions(-)[+] [-] Doc/whatsnew/3.4.rst 2 Lib/sunau.py 31 Lib/test/test_sunau.py 51 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -374,6 +374,8 @@ sunau The :meth:~sunau.getparams method now returns a namedtuple rather than a plain tuple. (Contributed by Claudiu Popa in :issue:18901.) +:meth:sunau.open now supports the context manager protocol (:issue:18878). + urllib ------

--- a/Lib/sunau.py +++ b/Lib/sunau.py @@ -168,6 +168,12 @@ class Au_read: if self._file: self.close()

+

+ def initfp(self, file): self._file = file self._soundpos = 0 @@ -303,6 +309,12 @@ class Au_write: self.close() self._file = None

+

+ def initfp(self, file): self._file = file self._framerate = 0 @@ -410,14 +422,17 @@ class Au_write: self._patchheader() def close(self):

# # private methods

--- a/Lib/test/test_sunau.py +++ b/Lib/test/test_sunau.py @@ -1,4 +1,4 @@ -from test.support import run_unittest, TESTFN +from test.support import TESTFN, unlink import unittest import pickle import os @@ -18,10 +18,7 @@ class SunAUTest(unittest.TestCase): def tearDown(self): if self.f is not None: self.f.close()

def test_lin(self): self.f = sunau.open(TESTFN, 'w') @@ -84,9 +81,49 @@ class SunAUTest(unittest.TestCase): dump = pickle.dumps(params) self.assertEqual(pickle.loads(dump), params)

-def test_main():

+

+ if name == "main": unittest.main()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -54,6 +54,9 @@ Core and Builtins Library ------- +- Issue #18878: sunau.open now supports the context manager protocol. Based on