Make text client python2/3 compatible
Make str unicode string
Use BytesIO for python2 and StringIO for python3
# limitations under the License.
#
from __future__ import print_function
+from builtins import str
import sys
import io
@@ -29,8 +30,12 @@ def custom_except_hook(exctype, value, traceback): # noqa
sys.excepthook = custom_except_hook # noqa
# capture any output
+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
@@ -170,7 +175,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)))
##############################################################################
