Bug #3126: StreamHandler and FileHandler check before calling "flush" and "close" that the stream object has these, using hasattr (thanks to bobf for the patch).

This commit is contained in:
Vinay Sajip 2008-06-17 11:02:14 +00:00
parent 5c15aba870
commit 8f96b8ec43
1 changed files with 3 additions and 2 deletions

View File

@ -735,7 +735,7 @@ class StreamHandler(Handler):
"""
Flushes the stream.
"""
if self.stream:
if self.stream and hasattr(self.stream, "flush"):
self.stream.flush()
def emit(self, record):
@ -791,7 +791,8 @@ class FileHandler(StreamHandler):
"""
if self.stream:
self.flush()
self.stream.close()
if hasattr(self.stream, "close"):
self.stream.close()
StreamHandler.close(self)
self.stream = None