From 5ccf163594fa11239b5cb83c73aa9c63879a17f2 Mon Sep 17 00:00:00 2001 From: nvbn Date: Tue, 21 Apr 2015 06:24:40 +0200 Subject: [PATCH] `command.script` now unicode --- tests/test_main.py | 4 ++-- thefuck/main.py | 2 +- thefuck/rules/has_exists_script.py | 2 +- thefuck/rules/no_command.py | 2 +- thefuck/rules/python_command.py | 13 +++++++------ thefuck/rules/sudo.py | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index f2c2843..696b390 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -53,8 +53,8 @@ def test_get_command(): return_value=True): Popen.return_value.stdout.read.return_value = b'stdout' Popen.return_value.stderr.read.return_value = b'stderr' - assert main.get_command(Mock(), ['thefuck', 'apt-get', - 'search', 'vim']) \ + assert main.get_command(Mock(), [b'thefuck', b'apt-get', + b'search', b'vim']) \ == main.Command('apt-get search vim', 'stdout', 'stderr') Popen.assert_called_once_with('apt-get search vim', shell=True, diff --git a/thefuck/main.py b/thefuck/main.py index e5ca16c..bc24453 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -76,7 +76,7 @@ def wait_output(settings, popen): def get_command(settings, args): """Creates command from `args` and executes it.""" - script = ' '.join(args[1:]) + script = ' '.join(arg.decode('utf-8') for arg in args[1:]) result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE, env=dict(os.environ, LANG='C')) if wait_output(settings, result): diff --git a/thefuck/rules/has_exists_script.py b/thefuck/rules/has_exists_script.py index 522dd8e..4ceac48 100644 --- a/thefuck/rules/has_exists_script.py +++ b/thefuck/rules/has_exists_script.py @@ -7,5 +7,5 @@ def match(command, settings): def get_new_command(command, settings): - return './{}'.format(command.script) + return u'./{}'.format(command.script) diff --git a/thefuck/rules/no_command.py b/thefuck/rules/no_command.py index 0c9b9f4..37b3647 100644 --- a/thefuck/rules/no_command.py +++ b/thefuck/rules/no_command.py @@ -8,7 +8,7 @@ local_settings = {'command_not_found': '/usr/lib/command-not-found'} def _get_output(command, settings): name = command.script.split(' ')[command.script.startswith('sudo')] - check_script = '{} {}'.format(settings.command_not_found, name) + check_script = u'{} {}'.format(settings.command_not_found, name) result = Popen(check_script, shell=True, stderr=PIPE) return result.stderr.read().decode('utf-8') diff --git a/thefuck/rules/python_command.py b/thefuck/rules/python_command.py index 3fc4782..507a934 100644 --- a/thefuck/rules/python_command.py +++ b/thefuck/rules/python_command.py @@ -3,11 +3,12 @@ # 2) is interpreted as shell script def match(command, settings): - toks = command.script.split() - return (len(toks) > 0 - and toks[0].endswith('.py') - and ('Permission denied' in command.stderr or - 'command not found' in command.stderr)) + toks = command.script.split() + return (len(toks) > 0 + and toks[0].endswith('.py') + and ('Permission denied' in command.stderr or + 'command not found' in command.stderr)) + def get_new_command(command, settings): - return 'python ' + command.script + return 'python ' + command.script diff --git a/thefuck/rules/sudo.py b/thefuck/rules/sudo.py index 17ad142..e1a1835 100644 --- a/thefuck/rules/sudo.py +++ b/thefuck/rules/sudo.py @@ -14,4 +14,4 @@ def match(command, settings): def get_new_command(command, settings): - return 'sudo {}'.format(command.script) + return u'sudo {}'.format(command.script)