Make the mode parameter to open() default in the same way as for wave.open().

This commit is contained in:
Fred Drake 1999-06-22 21:23:23 +00:00
parent 707f8e67b9
commit 4316135a44
2 changed files with 18 additions and 8 deletions

View File

@ -920,13 +920,18 @@ class Aifc_write:
_write_long(self._file, pos)
_write_string(self._file, name)
def open(f, mode):
if mode == 'r':
def open(f, mode=None):
if mode is None:
if hasattr(f, 'mode'):
mode = f.mode
else:
mode = 'rb'
if mode in ('r', 'rb'):
return Aifc_read(f)
elif mode == 'w':
elif mode in ('w', 'wb'):
return Aifc_write(f)
else:
raise Error, "mode must be 'r' or 'w'"
raise Error, "mode must be 'r', 'rb', 'w', or 'wb'"
openfp = open # B/W compatibility

View File

@ -456,12 +456,17 @@ class Au_write:
self._datalength = self._datawritten
self._file.seek(0, 2)
def open(f, mode):
if mode == 'r':
def open(f, mode=None):
if mode is None:
if hasattr(f, 'mode'):
mode = f.mode
else:
mode = 'rb'
if mode in ('r', 'rb'):
return Au_read(f)
elif mode == 'w':
elif mode in ('w', 'wb'):
return Au_write(f)
else:
raise Error, "mode must be 'r' or 'w'"
raise Error, "mode must be 'r', 'rb', 'w', or 'wb'"
openfp = open