[X2Go-Commits] [python-x2go] 08/11: x2go/backends/control/plain.py: Resolve Python 2 vs. 3 type issue on returned data from SSHClient.exec_command().
git-admin at x2go.org
git-admin at x2go.org
Mon Sep 25 12:44:54 CEST 2017
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository python-x2go.
commit 1623d96f60d3754da009e745650e96b4f5cae4a0
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date: Sun Sep 24 21:05:33 2017 +0200
x2go/backends/control/plain.py: Resolve Python 2 vs. 3 type issue on returned data from SSHClient.exec_command().
---
x2go/backends/control/plain.py | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/x2go/backends/control/plain.py b/x2go/backends/control/plain.py
index 6d525c4..3091af9 100644
--- a/x2go/backends/control/plain.py
+++ b/x2go/backends/control/plain.py
@@ -32,6 +32,7 @@ __name__ = 'x2go.backends.control.plain'
# modules
import os
+import sys
import types
import paramiko
import gevent
@@ -535,17 +536,17 @@ class X2GoControlSession(paramiko.SSHClient):
(_stdin, _stdout, _stderr) = _retval
raw_stdout = _stdout.read()
- sanitized_stdout = ''
+ sanitized_stdout = u''
is_x2go_data = False
- # Python 3 needs a decoding from bytestring to (unicode) string
- try:
+ # Python 3 needs a decoding from bytestring to string
+ if sys.version_info[0] >= 3:
raw_stdout = raw_stdout.decode()
- except:
- pass
+ else:
+ if type(raw_stdout) is not types.UnicodeType:
+ raw_stdout = raw_stdout.decode('utf-8')
for line in raw_stdout.split('\n'):
-
if line.startswith('X2GODATABEGIN:'+cmd_uuid):
is_x2go_data = True
continue
@@ -553,12 +554,7 @@ class X2GoControlSession(paramiko.SSHClient):
if line.startswith('X2GODATAEND:'+cmd_uuid): break
sanitized_stdout += line + "\n"
- try:
- # Python 3:
- _stdout_new = io.StringIO(sanitized_stdout)
- except TypeError:
- # Python 2:
- _stdout_new = io.StringIO(sanitized_stdout.decode())
+ _stdout_new = io.StringIO(sanitized_stdout)
_retval = (_stdin, _stdout_new, _stderr)
return _retval
--
Alioth's /srv/git/code.x2go.org/python-x2go.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/python-x2go.git
More information about the x2go-commits
mailing list