blob: 70690cb1feba7f2702c900020d3f58b4d22e39f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
From: Carl Suster <carl@contraflo.ws>
Date: Tue, 12 Nov 2019 14:08:30 +1100
Subject: Avoid writing bytes to stdout
In Python 3, bytes should be written to the underlying buffer object
rather than directly to stdout. This was causing legitimate test
failures.
Forwarded: https://github.com/Robpol86/terminaltables/pull/71
---
terminaltables/terminal_io.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/terminaltables/terminal_io.py b/terminaltables/terminal_io.py
index 8b8c10d..005da1b 100644
--- a/terminaltables/terminal_io.py
+++ b/terminaltables/terminal_io.py
@@ -94,5 +94,10 @@ def set_terminal_title(title, kernel32=None):
return kernel32.SetConsoleTitleW(title) != 0
# Linux/OSX.
- sys.stdout.write(b'\033]0;' + title_bytes + b'\007')
+ set_title = b'\033]0;' + title_bytes + b'\007'
+ if hasattr(sys.stdout, 'buffer'):
+ sys.stdout.buffer.write(set_title)
+ else:
+ text = set_title.decode(sys.stdout.encoding, 'strict')
+ sys.stdout.write(text)
return True
|