diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 2ae044a..12a54b2 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -1677,7 +1677,9 @@ class InteractiveShell(SingletonConfigurable, Magic): # Remove some chars from the delimiters list. If we encounter # unicode chars, discard them. - delims = readline.get_completer_delims().encode("ascii", "ignore") + delims = readline.get_completer_delims() + if not py3compat.PY3: + delims = delims.encode("ascii", "ignore") for d in self.readline_remove_delims: delims = delims.replace(d, "") delims = delims.replace(ESC_MAGIC, '') diff --git a/IPython/core/macro.py b/IPython/core/macro.py index e87ea78..86031eb 100644 --- a/IPython/core/macro.py +++ b/IPython/core/macro.py @@ -10,6 +10,8 @@ import re import sys +from IPython.utils import py3compat + coding_declaration = re.compile(r"#\s*coding[:=]\s*([-\w.]+)") class Macro(object): @@ -37,8 +39,7 @@ class Macro(object): self.value = code + '\n' def __str__(self): - enc = sys.stdin.encoding or sys.getdefaultencoding() - return self.value.encode(enc, "replace") + return py3compat.unicode_to_str(self.value) def __unicode__(self): return self.value diff --git a/IPython/core/magic.py b/IPython/core/magic.py index 650905f..1b77bf2 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -676,7 +676,7 @@ Currently the magic system has the following functions:\n""" %psearch -a _* list objects beginning with a single underscore""" try: - parameter_s = parameter_s.encode('ascii') + parameter_s.encode('ascii') except UnicodeEncodeError: print 'Python identifiers can only contain ascii characters.' return