From 753a2c758aafcf3220367436e0244bd090806d2d Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Mon, 30 Nov 2020 22:16:21 +0100 Subject: 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 --- tests/util.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/util.py b/tests/util.py index 2ac6ff132..70f6b4351 100755 --- a/tests/util.py +++ b/tests/util.py @@ -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): -- cgit v1.2.1