mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Open wave files in binary mode.
Accept 'rb' and 'wb' as well as 'r' and 'w' as the mode parameter to open().
This commit is contained in:
parent
bf88c3830e
commit
ac36c6403f
1 changed files with 5 additions and 5 deletions
10
Lib/wave.py
10
Lib/wave.py
|
@ -230,7 +230,7 @@ class Wave_read:
|
||||||
|
|
||||||
def __init__(self, f):
|
def __init__(self, f):
|
||||||
if type(f) == type(''):
|
if type(f) == type(''):
|
||||||
f = __builtin__.open(f, 'r')
|
f = __builtin__.open(f, 'rb')
|
||||||
# else, assume it is an open file object already
|
# else, assume it is an open file object already
|
||||||
self.initfp(f)
|
self.initfp(f)
|
||||||
|
|
||||||
|
@ -368,7 +368,7 @@ class Wave_write:
|
||||||
|
|
||||||
def __init__(self, f):
|
def __init__(self, f):
|
||||||
if type(f) == type(''):
|
if type(f) == type(''):
|
||||||
f = __builtin__.open(f, 'w')
|
f = __builtin__.open(f, 'wb')
|
||||||
self.initfp(f)
|
self.initfp(f)
|
||||||
|
|
||||||
def initfp(self, file):
|
def initfp(self, file):
|
||||||
|
@ -549,11 +549,11 @@ class Wave_write:
|
||||||
self._datalength = self._datawritten
|
self._datalength = self._datawritten
|
||||||
|
|
||||||
def open(f, mode):
|
def open(f, mode):
|
||||||
if mode == 'r':
|
if mode in ('r', 'rb'):
|
||||||
return Wave_read(f)
|
return Wave_read(f)
|
||||||
elif mode == 'w':
|
elif mode in ('w', 'wb'):
|
||||||
return Wave_write(f)
|
return Wave_write(f)
|
||||||
else:
|
else:
|
||||||
raise Error, "mode must be 'r' or 'w'"
|
raise Error, "mode must be 'r', 'rb', 'w', or 'wb'"
|
||||||
|
|
||||||
openfp = open # B/W compatibility
|
openfp = open # B/W compatibility
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue