mirror of https://github.com/python/cpython
Patch #1681153: the wave module now closes a file object it opened if
initialization failed.
This commit is contained in:
parent
8784bae65d
commit
ab1f4674ad
14
Lib/wave.py
14
Lib/wave.py
|
@ -159,7 +159,12 @@ class Wave_read:
|
||||||
f = __builtin__.open(f, 'rb')
|
f = __builtin__.open(f, 'rb')
|
||||||
self._i_opened_the_file = f
|
self._i_opened_the_file = f
|
||||||
# else, assume it is an open file object already
|
# else, assume it is an open file object already
|
||||||
self.initfp(f)
|
try:
|
||||||
|
self.initfp(f)
|
||||||
|
except:
|
||||||
|
if self._i_opened_the_file:
|
||||||
|
f.close()
|
||||||
|
raise
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
@ -297,7 +302,12 @@ class Wave_write:
|
||||||
if isinstance(f, basestring):
|
if isinstance(f, basestring):
|
||||||
f = __builtin__.open(f, 'wb')
|
f = __builtin__.open(f, 'wb')
|
||||||
self._i_opened_the_file = f
|
self._i_opened_the_file = f
|
||||||
self.initfp(f)
|
try:
|
||||||
|
self.initfp(f)
|
||||||
|
except:
|
||||||
|
if self._i_opened_the_file:
|
||||||
|
f.close()
|
||||||
|
raise
|
||||||
|
|
||||||
def initfp(self, file):
|
def initfp(self, file):
|
||||||
self._file = file
|
self._file = file
|
||||||
|
|
|
@ -173,6 +173,9 @@ Core and builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Patch #1681153: the wave module now closes a file object it opened if
|
||||||
|
initialization failed.
|
||||||
|
|
||||||
- Bug #767111: fix long-standing bug in urllib which caused an
|
- Bug #767111: fix long-standing bug in urllib which caused an
|
||||||
AttributeError instead of an IOError when the server's response didn't
|
AttributeError instead of an IOError when the server's response didn't
|
||||||
contain a valid HTTP status line.
|
contain a valid HTTP status line.
|
||||||
|
|
Loading…
Reference in New Issue