From f635516f0f77101d9577beeff4209f432278b7c1 2013-03-04 22:51:59 From: MinRK Date: 2013-03-04 22:51:59 Subject: [PATCH] Backport PR #2500: Add `encoding` attribute to `OutStream` class. This means that `sys.stdout.encoding` returns something useful instead of raising an AttributeError. Closes #2220. --- diff --git a/IPython/zmq/iostream.py b/IPython/zmq/iostream.py index 7fa896c..76c9d6e 100644 --- a/IPython/zmq/iostream.py +++ b/IPython/zmq/iostream.py @@ -4,7 +4,7 @@ from io import StringIO from session import extract_header, Message -from IPython.utils import io, text, encoding +from IPython.utils import io, text #----------------------------------------------------------------------------- # Globals @@ -22,6 +22,7 @@ class OutStream(object): topic=None def __init__(self, session, pub_socket, name): + self.encoding = 'UTF-8' self.session = session self.pub_socket = pub_socket self.name = name @@ -69,9 +70,8 @@ class OutStream(object): else: # Make sure that we're handling unicode if not isinstance(string, unicode): - enc = encoding.DEFAULT_ENCODING - string = string.decode(enc, 'replace') - + string = string.decode(self.encoding, 'replace') + self._buffer.write(string) current_time = time.time() if self._start <= 0: