Skip to content

Commit

Permalink
Fix various problems highlighted by the test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Sep 7, 2011
1 parent f866f01 commit 6feb755
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,7 @@ def var_expand(self,cmd,depth=0):
# 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.
Expand Down
7 changes: 3 additions & 4 deletions IPython/testing/globalipapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
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

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -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...

Expand Down
3 changes: 2 additions & 1 deletion IPython/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ._process_posix import _find_cmd, system, getoutput

from ._process_common import getoutputerror
from IPython.utils import py3compat

#-----------------------------------------------------------------------------
# Code
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions IPython/utils/py3compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# coding: utf-8
"""Compatibility tricks for Python 3. Mainly to do with unicode."""
import sys
import types

orig_open = open

Expand Down Expand Up @@ -43,6 +44,8 @@ def isidentifier(s, dotted=False):
return s.isidentifier()

open = orig_open

MethodType = types.MethodType

else:
PY3 = False
Expand Down Expand Up @@ -83,6 +86,9 @@ def __enter__(self):

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
Expand Down

0 comments on commit 6feb755

Please sign in to comment.