From ef3358bc6e38958732ac54f1926858bc02f1c138 2011-09-07 11:18:47 From: Thomas Kluyver Date: 2011-09-07 11:18:47 Subject: [PATCH] More Python 3 compatibility fixes in core. --- diff --git a/IPython/core/formatters.py b/IPython/core/formatters.py index cdc3649..90e66e4 100644 --- a/IPython/core/formatters.py +++ b/IPython/core/formatters.py @@ -29,6 +29,7 @@ from StringIO import StringIO from IPython.config.configurable import Configurable from IPython.lib import pretty from IPython.utils.traitlets import Bool, Dict, Int, Unicode, CUnicode, ObjectName +from IPython.utils.py3compat import unicode_to_str #----------------------------------------------------------------------------- @@ -439,7 +440,7 @@ class PlainTextFormatter(BaseFormatter): # ensure that stream does not get a mix of unicode and bytestrings, # or it will cause trouble. printer = pretty.RepresentationPrinter(stream, self.verbose, - self.max_width, self.newline.encode(), + self.max_width, unicode_to_str(self.newline), singleton_pprinters=self.singleton_printers, type_pprinters=self.type_printers, deferred_pprinters=self.deferred_printers) diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index 0ea51ae..d836630 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -75,6 +75,7 @@ from StringIO import StringIO # IPython modules from IPython.utils.text import make_quoted_expr +from IPython.utils.py3compat import cast_unicode #----------------------------------------------------------------------------- # Globals @@ -837,8 +838,7 @@ class IPythonInputSplitter(InputSplitter): return super(IPythonInputSplitter, self).push(lines) # We must ensure all input is pure unicode - if type(lines)==str: - lines = lines.decode(self.encoding) + lines = cast_unicode(lines, self.encoding) lines_list = lines.splitlines()