diff options
Diffstat (limited to 'Obok_plugin/obok/obok.py')
-rw-r--r-- | Obok_plugin/obok/obok.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/Obok_plugin/obok/obok.py b/Obok_plugin/obok/obok.py index a986965..4de7644 100644 --- a/Obok_plugin/obok/obok.py +++ b/Obok_plugin/obok/obok.py @@ -224,10 +224,17 @@ class SafeUnbuffered: if self.encoding == None: self.encoding = "utf-8" def write(self, data): - if isinstance(data,str): + if isinstance(data,str) or isinstance(data,unicode): + # str for Python3, unicode for Python2 data = data.encode(self.encoding,"replace") - self.stream.buffer.write(data) - self.stream.buffer.flush() + try: + buffer = getattr(self.stream, 'buffer', self.stream) + # self.stream.buffer for Python3, self.stream for Python2 + buffer.write(data) + buffer.flush() + except: + # We can do nothing if a write fails + raise def __getattr__(self, attr): return getattr(self.stream, attr) |