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
4412e769
Commit
4412e769
authored
Sep 03, 2013
by
Meador Inge
Browse files
Options
Browse Files
Download
Plain Diff
Merge heads.
parents
5886e061
01d909ab
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
66 additions
and
12 deletions
+66
-12
Doc/library/sunau.rst
Doc/library/sunau.rst
+3
-2
Doc/whatsnew/3.4.rst
Doc/whatsnew/3.4.rst
+7
-0
Lib/sunau.py
Lib/sunau.py
+12
-7
Lib/test/test_sunau.py
Lib/test/test_sunau.py
+22
-0
Lib/test/test_wave.py
Lib/test/test_wave.py
+13
-0
Lib/wave.py
Lib/wave.py
+3
-3
Misc/NEWS
Misc/NEWS
+6
-0
No files found.
Doc/library/sunau.rst
View file @
4412e769
...
...
@@ -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)
...
...
Doc/whatsnew/3.4.rst
View file @
4412e769
...
...
@@ -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
------
...
...
Lib/sunau.py
View file @
4412e769
...
...
@@ -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
named
tuple 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
...
...
Lib/test/test_sunau.py
View file @
4412e769
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
)
...
...
Lib/test/test_wave.py
View file @
4412e769
from
test.support
import
TESTFN
,
unlink
import
wave
import
pickle
import
unittest
nchannels
=
2
...
...
@@ -69,6 +70,18 @@ class TestWave(unittest.TestCase):
self
.
assertEqual
(
params
.
comptype
,
self
.
f
.
getcomptype
())
self
.
assertEqual
(
params
.
compname
,
self
.
f
.
getcompname
())
def
test_getparams_picklable
(
self
):
self
.
f
=
wave
.
open
(
TESTFN
,
'wb'
)
self
.
f
.
setnchannels
(
nchannels
)
self
.
f
.
setsampwidth
(
sampwidth
)
self
.
f
.
setframerate
(
framerate
)
self
.
f
.
close
()
self
.
f
=
wave
.
open
(
TESTFN
,
'rb'
)
params
=
self
.
f
.
getparams
()
dump
=
pickle
.
dumps
(
params
)
self
.
assertEqual
(
pickle
.
loads
(
dump
),
params
)
def
test_wave_write_context_manager_calls_close
(
self
):
# Close checks for a minimum header and will raise an error
# if it is not set, so this proves that close is called.
...
...
Lib/wave.py
View file @
4412e769
...
...
@@ -87,7 +87,7 @@ import sys
from
chunk
import
Chunk
from
collections
import
namedtuple
_
result
=
namedtuple
(
'
params'
,
_
wave_params
=
namedtuple
(
'_wave_
params'
,
'nchannels sampwidth framerate nframes comptype compname'
)
class
Wave_read
:
...
...
@@ -212,7 +212,7 @@ class Wave_read:
return
self
.
_compname
def
getparams
(
self
):
return
_
result
(
self
.
getnchannels
(),
self
.
getsampwidth
(),
return
_
wave_params
(
self
.
getnchannels
(),
self
.
getsampwidth
(),
self
.
getframerate
(),
self
.
getnframes
(),
self
.
getcomptype
(),
self
.
getcompname
())
...
...
@@ -410,7 +410,7 @@ class Wave_write:
def
getparams
(
self
):
if
not
self
.
_nchannels
or
not
self
.
_sampwidth
or
not
self
.
_framerate
:
raise
Error
(
'not all parameters set'
)
return
_
result
(
self
.
_nchannels
,
self
.
_sampwidth
,
self
.
_framerate
,
return
_
wave_params
(
self
.
_nchannels
,
self
.
_sampwidth
,
self
.
_framerate
,
self
.
_nframes
,
self
.
_comptype
,
self
.
_compname
)
def
setmark
(
self
,
id
,
pos
,
name
):
...
...
Misc/NEWS
View file @
4412e769
...
...
@@ -56,6 +56,12 @@ Library
- Issue #16826: Don'
t
check
for
PYTHONCASEOK
if
interpreter
started
with
-
E
.
-
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
.
-
Issue
#
18756
:
os
.
urandom
()
now
uses
a
lazily
-
opened
persistent
file
descriptor
,
so
as
to
avoid
using
many
file
descriptors
when
run
in
parallel
from
multiple
threads
.
...
...
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