LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 0003-Make-text-client-python2-3-compatible.patch of Package mycroft-core (Project home:alarrosa:packages)

From 608669c39ec7cac810d93b8f22eecd4cf9b3729b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=85ke=20Forslund?= <ake.forslund@gmail.com>
Date: Wed, 7 Feb 2018 22:32:43 +0100
Subject: [PATCH 03/13] Make text client python2/3 compatible

- Make str unicode string
- Use BytesIO for python2 and StringIO for python3
---
 mycroft/client/text/main.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/mycroft/client/text/main.py b/mycroft/client/text/main.py
index cd6782e..877a1cd 100644
--- a/mycroft/client/text/main.py
+++ b/mycroft/client/text/main.py
@@ -13,6 +13,7 @@
 # limitations under the License.
 #
 from __future__ import print_function
+from builtins import str
 import sys
 import io
 
@@ -27,8 +28,12 @@ def custom_except_hook(exctype, value, traceback):           # noqa
 sys.excepthook = custom_except_hook  # noqa
 
 # capture any output
-sys.stdout = io.BytesIO()  # noqa
-sys.stderr = io.BytesIO()  # noqa
+if sys.version_info[0] < 3:  # noqa
+    sys.stdout = io.BytesIO()  # noqa
+    sys.stderr = io.BytesIO()  # noqa
+else:  # noqa
+    sys.stdout = io.StringIO()  # noqa
+    sys.stderr = io.StringIO()  # noqa
 
 import os
 import os.path
@@ -157,7 +162,7 @@ def save_settings():
     config["max_log_lines"] = max_log_lines
     config["show_meter"] = show_meter
     with io.open(config_file, 'w') as f:
-        f.write(unicode(json.dumps(config, ensure_ascii=False)))
+        f.write(str(json.dumps(config, ensure_ascii=False)))
 
 
 ##############################################################################
-- 
2.16.2