From f5390b8e639a8b4ded16302477fc27a32f59939e Mon Sep 17 00:00:00 2001 From: Steven Xu Date: Mon, 6 Jan 2020 22:53:12 +1100 Subject: [PATCH] We have to wrap gzip filse in `io.TextIOWrapper` if using text mode --- lib/cfv/fileutil.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/cfv/fileutil.py b/lib/cfv/fileutil.py index ecbd7eb..1d2ebd0 100644 --- a/lib/cfv/fileutil.py +++ b/lib/cfv/fileutil.py @@ -169,9 +169,14 @@ def open_write(filename, config): if config.gzip >= 2 or (config.gzip >= 0 and filename[-3:].lower() == '.gz'): import gzip + import io if filename == '-': - return gzip.GzipFile(filename=filename, mode=mode, fileobj=sys.stdout) - return gzip.open(filename, mode) + res = gzip.GzipFile(filename=filename, mode=mode, fileobj=sys.stdout) + else: + res = gzip.open(filename, mode) + if mode == 'w': + res = io.TextIOWrapper(res, encoding=encoding) + return res else: if filename == '-': return NoCloseFile(sys.stdout)