1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-06 10:51:11 +01:00

python2.7 unicode error

This commit is contained in:
lovedboy 2015-11-19 00:15:07 +08:00
parent 1bb04b41eb
commit ae2949cfa2
2 changed files with 11 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import io
import os
import shlex
import six
import sys
from .utils import DEVNULL, memoize, cache
@ -50,7 +51,10 @@ class Generic(object):
history_file_name = self._get_history_file_name()
if os.path.isfile(history_file_name):
with open(history_file_name, 'a') as history:
history.write(self._get_history_line(command_script))
if sys.version_info >= (3, 0):
history.write(self._get_history_line(command_script))
else:
history.write(self._get_history_line(command_script).encode("utf-8"))
def _script_from_history(self, line):
"""Returns prepared history line.
@ -80,7 +84,10 @@ class Generic(object):
def split_command(self, command):
"""Split the command using shell-like syntax."""
return shlex.split(command)
if sys.version_info >= (3, 0):
return shlex.split(command)
else:
return shlex.split(command.encode("utf-8"))
def quote(self, s):
"""Return a shell-escaped version of the string s."""

View File

@ -31,7 +31,7 @@ class Command(object):
try:
self._script_parts = shells.split_command(self.script)
except Exception:
logs.debug("Can't split command script {} because:\n {}".format(
logs.debug(u"Can't split command script {} because:\n {}".format(
self, sys.exc_info()))
self._script_parts = None
return self._script_parts
@ -44,7 +44,7 @@ class Command(object):
return False
def __repr__(self):
return 'Command(script={}, stdout={}, stderr={})'.format(
return u'Command(script={}, stdout={}, stderr={})'.format(
self.script, self.stdout, self.stderr)
def update(self, **kwargs):