From bc85d93cf49ba6145613360002e6587a7271aaba Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 9 Oct 2019 11:20:03 -0400 Subject: [PATCH] More Py3 fixes --- confluent_server/confluent/consoleserver.py | 6 ++++- confluent_server/confluent/httpapi.py | 2 +- .../confluent/plugins/shell/ssh.py | 22 +++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/confluent_server/confluent/consoleserver.py b/confluent_server/confluent/consoleserver.py index bb5ba89d..4eb177b9 100644 --- a/confluent_server/confluent/consoleserver.py +++ b/confluent_server/confluent/consoleserver.py @@ -531,9 +531,11 @@ class ConsoleHandler(object): if data == conapi.ConsoleEvent.Disconnect: self._got_disconnected() return - elif data == '': + elif data in (b'', u''): # ignore empty strings from a cconsole provider return + if not isinstance(data, bytes): + data = data.encode('utf-8') if b'\x1b[?1l' in data: # request for ansi mode cursor keys self.appmodedetected = False if b'\x1b[?1h' in data: # remember the session wants the client to use @@ -616,6 +618,8 @@ class ConsoleHandler(object): def write(self, data): if self.connectstate == 'connected': try: + if isinstance(data, str) and not isinstance(data, bytes): + data = data.encode('utf-8') self._console.write(data) except Exception: _tracelog.log(traceback.format_exc(), ltype=log.DataTypes.event, diff --git a/confluent_server/confluent/httpapi.py b/confluent_server/confluent/httpapi.py index a4f1cd69..ce36b67a 100644 --- a/confluent_server/confluent/httpapi.py +++ b/confluent_server/confluent/httpapi.py @@ -499,7 +499,7 @@ def resourcehandler_backend(env, start_response): auditmsg = { 'operation': 'start', 'target': env['PATH_INFO'], - 'user': authorized['username'], + 'user': util.stringify(authorized['username']), } if 'tenant' in authorized: auditmsg['tenant'] = authorized['tenant'] diff --git a/confluent_server/confluent/plugins/shell/ssh.py b/confluent_server/confluent/plugins/shell/ssh.py index efd0c71a..16d22bc4 100644 --- a/confluent_server/confluent/plugins/shell/ssh.py +++ b/confluent_server/confluent/plugins/shell/ssh.py @@ -77,7 +77,7 @@ class HostKeyHandler(paramiko.client.MissingHostKeyPolicy): class SshShell(conapi.Console): - def __init__(self, node, config, username='', password=''): + def __init__(self, node, config, username=b'', password=b''): self.node = node self.ssh = None self.datacallback = None @@ -127,15 +127,15 @@ class SshShell(conapi.Console): look_for_keys=False) except paramiko.AuthenticationException: self.inputmode = 0 - self.username = '' - self.password = '' + self.username = b'' + self.password = b'' self.datacallback('\r\nlogin as: ') return except paramiko.ssh_exception.NoValidConnectionsError as e: self.datacallback(str(e)) self.inputmode = 0 - self.username = '' - self.password = '' + self.username = b'' + self.password = b'' self.datacallback('\r\nlogin as: ') return except cexc.PubkeyInvalid as pi: @@ -205,9 +205,9 @@ class SshShell(conapi.Console): delidx = data.index(b'\x7f') data = data[:delidx - 1] + data[delidx + 1:] self.username += data - if '\r' in self.username: - self.username, self.password = self.username.split('\r')[:2] - lastdata = data.split('\r')[0] + if b'\r' in self.username: + self.username, self.password = self.username.split(b'\r')[:2] + lastdata = data.split(b'\r')[0] if lastdata != '': self.datacallback(lastdata) self.datacallback('\r\nEnter password: ') @@ -223,9 +223,9 @@ class SshShell(conapi.Console): delidx = data.index(b'\x7f') data = data[:delidx - 1] + data[delidx + 1:] self.password += data - if '\r' in self.password: - self.password = self.password.split('\r')[0] - self.datacallback('\r\n') + if b'\r' in self.password: + self.password = self.password.split(b'\r')[0] + self.datacallback(b'\r\n') self.logon() else: self.shell.sendall(data)