Permalink
Browse files

add OutStream.encoding attribute

Initial value is set from text.getdefaultencoding()
  • Loading branch information...
1 parent a00c1ca commit 01cc9d788f9e63e46f0685818d1107b669077659 @minrk minrk committed Sep 7, 2011
Showing with 7 additions and 3 deletions.
  1. +7 −3 IPython/zmq/iostream.py
View
@@ -1,10 +1,12 @@
+
+import locale
import sys
import time
from io import StringIO
from session import extract_header, Message
-from IPython.utils import io
+from IPython.utils import io, text
#-----------------------------------------------------------------------------
# Globals
@@ -20,13 +22,16 @@ class OutStream(object):
# The time interval between automatic flushes, in seconds.
flush_interval = 0.05
topic=None
+ encoding = None
def __init__(self, session, pub_socket, name):
self.session = session
self.pub_socket = pub_socket
self.name = name
self.parent_header = {}
self._new_buffer()
+ self.encoding = text.getdefaultencoding()
+
def set_parent(self, parent):
self.parent_header = extract_header(parent)
@@ -69,8 +74,7 @@ def write(self, string):
else:
# Make sure that we're handling unicode
if not isinstance(string, unicode):
- enc = sys.stdin.encoding or sys.getdefaultencoding()
- string = string.decode(enc, 'replace')
+ string = string.decode(self.encoding, 'replace')
self._buffer.write(string)
current_time = time.time()

0 comments on commit 01cc9d7

Please sign in to comment.