mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-23 13:28:39 +00:00
generic shell: extract UTF-8 encoding/decoding into methods
This commit is contained in:
parent
4f87141f0c
commit
385746850e
@ -65,9 +65,17 @@ class Generic(object):
|
|||||||
|
|
||||||
def split_command(self, command):
|
def split_command(self, command):
|
||||||
"""Split the command using shell-like syntax."""
|
"""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:
|
if six.PY2:
|
||||||
return [s.decode('utf8') for s in shlex.split(command.encode('utf8'))]
|
return command.encode('utf8')
|
||||||
return shlex.split(command)
|
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):
|
def quote(self, s):
|
||||||
"""Return a shell-escaped version of the string s."""
|
"""Return a shell-escaped version of the string s."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user