diff options
author | NoDRM <[email protected]> | 2022-08-06 19:57:20 +0200 |
---|---|---|
committer | NoDRM <[email protected]> | 2022-08-06 19:57:20 +0200 |
commit | b404605878391f56fc485bd0824c8c168a9c1a1a (patch) | |
tree | c8ed3f096cb4049629912fbb226d6dbfa81fce5a /Obok_plugin | |
parent | 1cc5d383ccd60269cc2296b7ecd94e5fbf85e3f3 (diff) |
Another Python2 Bugfix for Obok
Diffstat (limited to 'Obok_plugin')
-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) |