From a8c056c27b97c3329cd04834be1e9d11e2417f45 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 20 Jan 2019 12:31:38 +0000 Subject: [PATCH] issue #436: decode debug log lines on Python 3. --- mitogen/ssh.py | 3 ++- tests/ssh_test.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mitogen/ssh.py b/mitogen/ssh.py index 106dfd56..2bee15c8 100644 --- a/mitogen/ssh.py +++ b/mitogen/ssh.py @@ -100,7 +100,8 @@ def filter_debug(stream, it): if b('\n') not in buf: break line, _, buf = buf.partition(b('\n')) - LOG.debug('%r: %s', stream, line.rstrip()) + LOG.debug('%r: %s', stream, + mitogen.core.to_text(line.rstrip())) state = 'start_of_line' elif state == 'in_plain': line, nl, buf = buf.partition(b('\n')) diff --git a/tests/ssh_test.py b/tests/ssh_test.py index 661ff5ed..abb25a58 100644 --- a/tests/ssh_test.py +++ b/tests/ssh_test.py @@ -44,6 +44,21 @@ class ConstructorTest(testlib.RouterMixin, testlib.TestCase): class SshTest(testlib.DockerMixin, testlib.TestCase): stream_class = mitogen.ssh.Stream + def test_debug_decoding(self): + # ensure filter_debug_logs() decodes the logged string. + capture = testlib.LogCapturer() + capture.start() + try: + context = self.docker_ssh( + username='mitogen__has_sudo', + password='has_sudo_password', + ssh_debug_level=3, + ) + finally: + s = capture.stop() + + self.assertTrue("'): debug1: Reading configuration data" in s) + def test_stream_name(self): context = self.docker_ssh( username='mitogen__has_sudo',