diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index be54783..58bca58 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2454,7 +2454,7 @@ class InteractiveShell(SingletonConfigurable, Magic): # Skip our own frame in searching for locals: sys._getframe(depth+1).f_locals # locals ) - return str(res).decode(res.codec) + return py3compat.str_to_unicode(str(res), res.codec) def mktempfile(self, data=None, prefix='ipython_edit_'): """Make a new tempfile and return its filename. diff --git a/IPython/testing/globalipapp.py b/IPython/testing/globalipapp.py index 7f57fc5..ceb6ad4 100644 --- a/IPython/testing/globalipapp.py +++ b/IPython/testing/globalipapp.py @@ -23,12 +23,12 @@ from __future__ import print_function import __builtin__ as builtin_mod import os import sys -from types import MethodType # our own from . import tools from IPython.utils import io +from IPython.utils import py3compat from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell #----------------------------------------------------------------------------- @@ -204,11 +204,10 @@ def start_ipython(): # Modify the IPython system call with one that uses getoutput, so that we # can capture subcommands and print them to Python's stdout, otherwise the # doctest machinery would miss them. - shell.system = MethodType(xsys, shell, TerminalInteractiveShell) + shell.system = py3compat.MethodType(xsys, shell) - shell._showtraceback = MethodType(_showtraceback, shell, - TerminalInteractiveShell) + shell._showtraceback = py3compat.MethodType(_showtraceback, shell) # IPython is ready, now clean up some global state... diff --git a/IPython/utils/process.py b/IPython/utils/process.py index 2ed580b..a26024f 100644 --- a/IPython/utils/process.py +++ b/IPython/utils/process.py @@ -27,6 +27,7 @@ else: from ._process_posix import _find_cmd, system, getoutput from ._process_common import getoutputerror +from IPython.utils import py3compat #----------------------------------------------------------------------------- # Code @@ -115,7 +116,7 @@ def arg_split(s, posix=False): # At least encoding the input when it's unicode seems to help, but there # may be more problems lurking. Apparently this is fixed in python3. is_unicode = False - if isinstance(s, unicode): + if (not py3compat.PY3) and isinstance(s, unicode): is_unicode = True s = s.encode('utf-8') lex = shlex.shlex(s, posix=posix) diff --git a/IPython/utils/py3compat.py b/IPython/utils/py3compat.py index b486a17..2e59ddc 100644 --- a/IPython/utils/py3compat.py +++ b/IPython/utils/py3compat.py @@ -1,6 +1,7 @@ # coding: utf-8 """Compatibility tricks for Python 3. Mainly to do with unicode.""" import sys +import types orig_open = open @@ -43,6 +44,8 @@ if sys.version_info[0] >= 3: return s.isidentifier() open = orig_open + + MethodType = types.MethodType else: PY3 = False @@ -83,6 +86,9 @@ else: def __exit__(self, etype, value, traceback): self.f.close() + + def MethodType(func, instance): + return types.MethodType(func, instance, type(instance)) def execfile(fname, glob, loc=None): loc = loc if (loc is not None) else glob