Commit c3148641 by rfkelly0

cleanup FileWrapper.__del__ a little

parent 7d801b21
...@@ -618,11 +618,11 @@ class FileWrapper(FileLikeBase): ...@@ -618,11 +618,11 @@ class FileWrapper(FileLikeBase):
# Close the wrapper and the underlying file independently, so the # Close the wrapper and the underlying file independently, so the
# latter is still closed on cleanup even if the former errors out. # latter is still closed on cleanup even if the former errors out.
try: try:
super(FileWrapper,self).close() if FileWrapper is not None:
except Exception: super(FileWrapper,self).close()
finally:
if hasattr(getattr(self,"wrapped_file",None),"close"): if hasattr(getattr(self,"wrapped_file",None),"close"):
self.wrapped_file.close() self.wrapped_file.close()
raise
def close(self): def close(self):
"""Close the object for reading/writing.""" """Close the object for reading/writing."""
...@@ -631,10 +631,11 @@ class FileWrapper(FileLikeBase): ...@@ -631,10 +631,11 @@ class FileWrapper(FileLikeBase):
# close() on it, which will call its flush() again! To avoid # close() on it, which will call its flush() again! To avoid
# this inefficiency, our flush() will not flush the wrapped # this inefficiency, our flush() will not flush the wrapped
# file when we're closing. # file when we're closing.
self.__closing = True if not self.closed:
super(FileWrapper,self).close() self.__closing = True
if hasattr(self.wrapped_file,"close"): super(FileWrapper,self).close()
self.wrapped_file.close() if hasattr(self.wrapped_file,"close"):
self.wrapped_file.close()
def flush(self): def flush(self):
"""Flush the write buffers of the file.""" """Flush the write buffers of the file."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment