tests/util.py: fix compatibility with Python 2

Backporting the Python 3 implementation of setStream
to ClosingFileHandler as a fallback within Python 2.

Reported-by: Jay Satiro

Fixes #6259
Closes #6270
This commit is contained in:
Marc Hoersken 2020-11-30 22:16:21 +01:00
parent 41b3b830f1
commit 753a2c758a
No known key found for this signature in database
GPG Key ID: 61E03CBED7BC859E

View File

@ -46,6 +46,21 @@ class ClosingFileHandler(logging.StreamHandler):
super(ClosingFileHandler, self).emit(record)
self.setStream(None)
def setStream(self, stream):
setStream = getattr(super(ClosingFileHandler, self), 'setStream', None)
if callable(setStream):
return setStream(stream)
if stream is self.stream:
result = None
else:
result = self.stream
self.acquire()
try:
self.flush()
self.stream = stream
finally:
self.release()
return result
class TestData(object):
def __init__(self, data_folder):