diff options
author | R David Murray <rdmurray@bitdance.com> | 2013-08-01 00:48:26 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2013-08-01 00:48:26 (GMT) |
commit | 536ffe161c014f3646cbf52bc527f2ba9ebd6478 (patch) | |
tree | fc1491b81c3db517bad24d0ec425b666cf37a426 /Doc | |
parent | abe639f1150a770b2435417330c1c2a5a2e239ab (diff) | |
download | cpython-536ffe161c014f3646cbf52bc527f2ba9ebd6478.zip cpython-536ffe161c014f3646cbf52bc527f2ba9ebd6478.tar.gz cpython-536ffe161c014f3646cbf52bc527f2ba9ebd6478.tar.bz2 |
#17616: Improve context manager tests, fix bugs in close method and mode docs.
'mode' docs fix: the file must always be opened in binary in Python3.
Bug in Wave_write.close: when the close method calls the check that the header
exists and it raises an error, the _file attribute never gets set to None, so
the next close tries to close the file again and we get an ignored traceback
in the __del__ method. The fix is to set _file to None in a finally clause.
This represents a behavior change...in theory a program could be checking for
the error on close and then doing a recovery action on the still open file and
closing it again. But this change will only go into 3.4, so I think that
behavior change is acceptable given that it would be pretty weird and unlikely
logic to begin with.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/wave.rst | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Doc/library/wave.rst b/Doc/library/wave.rst index c52af89..9d12455 100644 --- a/Doc/library/wave.rst +++ b/Doc/library/wave.rst @@ -19,21 +19,20 @@ The :mod:`wave` module defines the following function and exception: .. function:: open(file, mode=None) If *file* is a string, open the file by that name, otherwise treat it as a - seekable file-like object. *mode* can be any of + seekable file-like object. *mode* can be: - ``'r'``, ``'rb'`` + ``'rb'`` Read only mode. - ``'w'``, ``'wb'`` + ``'wb'`` Write only mode. Note that it does not allow read/write WAV files. - A *mode* of ``'r'`` or ``'rb'`` returns a :class:`Wave_read` object, while a - *mode* of ``'w'`` or ``'wb'`` returns a :class:`Wave_write` object. If - *mode* is omitted and a file-like object is passed as *file*, ``file.mode`` - is used as the default value for *mode* (the ``'b'`` flag is still added if - necessary). + A *mode* of ``'rb'`` returns a :class:`Wave_read` object, while a *mode* of + ``'wb'`` returns a :class:`Wave_write` object. If *mode* is omitted and a + file-like object is passed as *file*, ``file.mode`` is used as the default + value for *mode*. If you pass in a file-like object, the wave object will not close it when its :meth:`close` method is called; it is the caller's responsibility to close |