From e13371e2f53e75904fe152813b793f765291b0d6 Mon Sep 17 00:00:00 2001 From: Martin Carlsen Date: Tue, 28 Mar 2017 13:18:11 +0200 Subject: [PATCH] fixes #175. utf-8 errors in Python 3. Caused by block reads chopping multibyte utf-8 sequences in half --- qds_sdk/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qds_sdk/commands.py b/qds_sdk/commands.py index a9cde5f3..097ab7b1 100644 --- a/qds_sdk/commands.py +++ b/qds_sdk/commands.py @@ -1237,9 +1237,9 @@ def _read_iteratively(key_instance, fp, delim): else: import io if isinstance(fp, io.TextIOBase): - fp.buffer.write(data.decode('utf-8').replace(chr(1), delim).encode('utf8')) + fp.buffer.write(data.replace(bytes([1]), delim.encode('utf8'))) elif isinstance(fp, io.BufferedIOBase) or isinstance(fp, io.RawIOBase): - fp.write(data.decode('utf8').replace(chr(1), delim).encode('utf8')) + fp.write(data.replace(bytes([1]), delim.encode('utf8'))) else: # Can this happen? Don't know what's the right thing to do in this case. pass