From 88e60b4338e0e402507e5a58808d4240a1bf2bdb Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Mon, 17 Aug 2015 17:49:10 +0300 Subject: [PATCH] util: move to_ascii() from __main__ --- sshagent/__main__.py | 10 ++++------ sshagent/tests/test_utils.py | 4 ++++ sshagent/util.py | 4 ++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sshagent/__main__.py b/sshagent/__main__.py index 9e8fd49..62099e4 100644 --- a/sshagent/__main__.py +++ b/sshagent/__main__.py @@ -6,6 +6,7 @@ import subprocess from . import trezor from . import server +from . import util import logging log = logging.getLogger(__name__) @@ -84,14 +85,11 @@ def trezor_agent(): use_shell = False if args.connect: - def to_ascii(s): - return s.encode('ascii') - - command = ['ssh', to_ascii(identity.host)] + command = ['ssh', util.to_ascii(identity.host)] if identity.user: - command += ['-l', to_ascii(identity.user)] + command += ['-l', util.to_ascii(identity.user)] if identity.port: - command += ['-p', to_ascii(identity.port)] + command += ['-p', util.to_ascii(identity.port)] log.debug('SSH connect: %r', command) command = command + args.command diff --git a/sshagent/tests/test_utils.py b/sshagent/tests/test_utils.py index 9d88eec..928f656 100644 --- a/sshagent/tests/test_utils.py +++ b/sshagent/tests/test_utils.py @@ -45,3 +45,7 @@ def test_send_recv(): assert util.recv(s, 2) == b'3*' pytest.raises(EOFError, util.recv, s, 1) + + +def test_ascii(): + assert util.to_ascii(b'123abc') == '123abc' diff --git a/sshagent/util.py b/sshagent/util.py index eeac94f..d169a28 100644 --- a/sshagent/util.py +++ b/sshagent/util.py @@ -64,3 +64,7 @@ def frame(*msgs): res.write(msg) msg = res.getvalue() return pack('L', len(msg)) + msg + + +def to_ascii(s): + return s.decode('ascii')