From ae2949cfa205b5a08bcd8e039645010eda522526 Mon Sep 17 00:00:00 2001 From: lovedboy Date: Thu, 19 Nov 2015 00:15:07 +0800 Subject: [PATCH] python2.7 unicode error --- thefuck/shells.py | 11 +++++++++-- thefuck/types.py | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/thefuck/shells.py b/thefuck/shells.py index 66fa1d6..6a5d116 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -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.""" diff --git a/thefuck/types.py b/thefuck/types.py index a2cd962..3bc3903 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -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):