Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c91d5eea
Commit
c91d5eea
authored
Jul 31, 2013
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#17616: wave.open now supports the 'with' statement.
Feature and tests by ClClaudiu.Popa, I added the doc changes.
parent
0ce642eb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
12 deletions
+45
-12
Doc/library/aifc.rst
Doc/library/aifc.rst
+2
-1
Doc/library/wave.rst
Doc/library/wave.rst
+5
-0
Doc/whatsnew/3.4.rst
Doc/whatsnew/3.4.rst
+4
-1
Lib/test/test_wave.py
Lib/test/test_wave.py
+19
-10
Lib/wave.py
Lib/wave.py
+13
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/aifc.rst
View file @
c91d5eea
...
@@ -51,7 +51,8 @@ Module :mod:`aifc` defines the following function:
...
@@ -51,7 +51,8 @@ Module :mod:`aifc` defines the following function:
used for writing, the file object should be seekable, unless you know ahead of
used for writing, the file object should be seekable, unless you know ahead of
time how many samples you are going to write in total and use
time how many samples you are going to write in total and use
:meth:`writeframesraw` and :meth:`setnframes`.
:meth:`writeframesraw` and :meth:`setnframes`.
Objects returned by :func:`.open` also supports the :keyword:`with` statement.
The :func:`.open` function may be used in a :keyword:`with` statement. When
the :keyword:`with` block completes, the :meth:`~aifc.close` method is called.
.. versionchanged:: 3.4
.. versionchanged:: 3.4
Support for the :keyword:`with` statement was added.
Support for the :keyword:`with` statement was added.
...
...
Doc/library/wave.rst
View file @
c91d5eea
...
@@ -39,6 +39,11 @@ The :mod:`wave` module defines the following function and exception:
...
@@ -39,6 +39,11 @@ The :mod:`wave` module defines the following function and exception:
:meth:`close` method is called; it is the caller's responsibility to close
:meth:`close` method is called; it is the caller's responsibility to close
the file object.
the file object.
The :func:`.open` function may be used in a :keyword:`with` statement. When
the :keyword:`with` block completes, the :meth:`Wave_read.close()
<wave.Wave_read.close>` or :meth:`Wave_write.close()
<wave.Wave_write.close()>` method is called.
.. function:: openfp(file, mode)
.. function:: openfp(file, mode)
...
...
Doc/whatsnew/3.4.rst
View file @
c91d5eea
...
@@ -239,8 +239,11 @@ wave
...
@@ -239,8 +239,11 @@ wave
The :meth:`~wave.getparams` method now returns a namedtuple rather than a
The :meth:`~wave.getparams` method now returns a namedtuple rather than a
plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.)
plain tuple. (Contributed by Claudiu Popa in :issue:`17487`.)
:meth:`wave.open` now supports the context manager protocol. (Contributed
by Claudiu Popa in :issue:`17616`.)
stat
stat
---
---
-
The stat module is now backed by a C implementation in :mod:`_stat`. A C
The stat module is now backed by a C implementation in :mod:`_stat`. A C
implementation is required as most of the values aren't standardized and
implementation is required as most of the values aren't standardized and
...
...
Lib/test/test_wave.py
View file @
c91d5eea
from
test.support
import
TESTFN
,
run_unittest
from
test.support
import
TESTFN
,
unlink
import
os
import
wave
import
wave
import
struct
import
unittest
import
unittest
nchannels
=
2
nchannels
=
2
...
@@ -17,10 +15,7 @@ class TestWave(unittest.TestCase):
...
@@ -17,10 +15,7 @@ class TestWave(unittest.TestCase):
def
tearDown
(
self
):
def
tearDown
(
self
):
if
self
.
f
is
not
None
:
if
self
.
f
is
not
None
:
self
.
f
.
close
()
self
.
f
.
close
()
try
:
unlink
(
TESTFN
)
os
.
remove
(
TESTFN
)
except
OSError
:
pass
def
test_it
(
self
,
test_rounding
=
False
):
def
test_it
(
self
,
test_rounding
=
False
):
self
.
f
=
wave
.
open
(
TESTFN
,
'wb'
)
self
.
f
=
wave
.
open
(
TESTFN
,
'wb'
)
...
@@ -74,9 +69,23 @@ class TestWave(unittest.TestCase):
...
@@ -74,9 +69,23 @@ class TestWave(unittest.TestCase):
self
.
assertEqual
(
params
.
comptype
,
self
.
f
.
getcomptype
())
self
.
assertEqual
(
params
.
comptype
,
self
.
f
.
getcomptype
())
self
.
assertEqual
(
params
.
compname
,
self
.
f
.
getcompname
())
self
.
assertEqual
(
params
.
compname
,
self
.
f
.
getcompname
())
def
test_context_manager
(
self
):
self
.
f
=
wave
.
open
(
TESTFN
,
'wb'
)
self
.
f
.
setnchannels
(
nchannels
)
self
.
f
.
setsampwidth
(
sampwidth
)
self
.
f
.
setframerate
(
framerate
)
self
.
f
.
close
()
with
wave
.
open
(
TESTFN
)
as
f
:
self
.
assertFalse
(
f
.
getfp
().
closed
)
self
.
assertIs
(
f
.
getfp
(),
None
)
with
open
(
TESTFN
,
'wb'
)
as
testfile
:
with
self
.
assertRaises
(
wave
.
Error
):
with
wave
.
open
(
testfile
,
'wb'
):
pass
self
.
assertEqual
(
testfile
.
closed
,
False
)
def
test_main
():
run_unittest
(
TestWave
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
main
()
Lib/wave.py
View file @
c91d5eea
...
@@ -167,6 +167,13 @@ class Wave_read:
...
@@ -167,6 +167,13 @@ class Wave_read:
def
__del__
(
self
):
def
__del__
(
self
):
self
.
close
()
self
.
close
()
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
close
()
#
#
# User visible methods.
# User visible methods.
#
#
...
@@ -323,6 +330,12 @@ class Wave_write:
...
@@ -323,6 +330,12 @@ class Wave_write:
def
__del__
(
self
):
def
__del__
(
self
):
self
.
close
()
self
.
close
()
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
*
args
):
self
.
close
()
#
#
# User visible methods.
# User visible methods.
#
#
...
...
Misc/NEWS
View file @
c91d5eea
...
@@ -173,6 +173,8 @@ Core and Builtins
...
@@ -173,6 +173,8 @@ Core and Builtins
Library
Library
-------
-------
-
Issue
#
17616
:
wave
.
open
now
supports
the
context
manager
protocol
.
-
Issue
#
18599
:
Fix
name
attribute
of
_sha1
.
sha1
()
object
.
It
now
returns
-
Issue
#
18599
:
Fix
name
attribute
of
_sha1
.
sha1
()
object
.
It
now
returns
'SHA1'
instead
of
'SHA'
.
'SHA1'
instead
of
'SHA'
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment