diff options
author | Marc Hoersken <info@marc-hoersken.de> | 2020-11-30 22:16:21 +0100 |
---|---|---|
committer | Marc Hoersken <info@marc-hoersken.de> | 2020-12-03 20:57:39 +0100 |
commit | 753a2c758aafcf3220367436e0244bd090806d2d (patch) | |
tree | 2c452c11c63633d55244c2125acfbe885d6bdb6d /tests | |
parent | 41b3b830f118197a4b4988f425902493f4f85de8 (diff) | |
download | curl-753a2c758aafcf3220367436e0244bd090806d2d.tar.gz |
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
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/util.py | 15 |
1 files changed, 15 insertions, 0 deletions
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): |