1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-22 12:58:33 +00:00

generic shell: extract UTF-8 encoding/decoding into methods

This commit is contained in:
Joseph Frazier 2016-11-23 07:53:22 -05:00
parent 4f87141f0c
commit 385746850e

View File

@ -65,9 +65,17 @@ class Generic(object):
def split_command(self, command):
"""Split the command using shell-like syntax."""
return self.decode_utf8(shlex.split(self.encode_utf8(command)))
def encode_utf8(self, command):
if six.PY2:
return [s.decode('utf8') for s in shlex.split(command.encode('utf8'))]
return shlex.split(command)
return command.encode('utf8')
return command
def decode_utf8(self, command_parts):
if six.PY2:
return [s.decode('utf8') for s in command_parts]
return command_parts
def quote(self, s):
"""Return a shell-escaped version of the string s."""