summaryrefslogtreecommitdiff
path: root/Lib/aifc.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-12-31 21:40:42 -0600
committerBenjamin Peterson <benjamin@python.org>2012-12-31 21:40:42 -0600
commit1f7df8f2070391f28391e3594580c07e11b6b32b (patch)
treeec03dfe4f71df3840232731145b8f6736fc6a314 /Lib/aifc.py
parentb25d611f8d9140e83acbfffb6b0579939c88c033 (diff)
parent10e93a6d40502e100c68090730e0b3190df97854 (diff)
downloadcpython-git-1f7df8f2070391f28391e3594580c07e11b6b32b.tar.gz
merge heads
Diffstat (limited to 'Lib/aifc.py')
-rw-r--r--Lib/aifc.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/Lib/aifc.py b/Lib/aifc.py
index b8adc852ed..a0cfe5fc57 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -732,22 +732,28 @@ class Aifc_write:
self._patchheader()
def close(self):
- self._ensure_header_written(0)
- if self._datawritten & 1:
- # quick pad to even size
- self._file.write(chr(0))
- self._datawritten = self._datawritten + 1
- self._writemarkers()
- if self._nframeswritten != self._nframes or \
- self._datalength != self._datawritten or \
- self._marklength:
- self._patchheader()
- if self._comp:
- self._comp.CloseCompressor()
- self._comp = None
- # Prevent ref cycles
- self._convert = None
- self._file.close()
+ if self._file is None:
+ return
+ try:
+ self._ensure_header_written(0)
+ if self._datawritten & 1:
+ # quick pad to even size
+ self._file.write(chr(0))
+ self._datawritten = self._datawritten + 1
+ self._writemarkers()
+ if self._nframeswritten != self._nframes or \
+ self._datalength != self._datawritten or \
+ self._marklength:
+ self._patchheader()
+ if self._comp:
+ self._comp.CloseCompressor()
+ self._comp = None
+ finally:
+ # Prevent ref cycles
+ self._convert = None
+ f = self._file
+ self._file = None
+ f.close()
#
# Internal methods.