99import textwrap
1010
1111from bpython .test import unittest , TEST_CONFIG
12+ from bpython .config import getpreferredencoding
1213
1314try :
1415 from twisted .internet import reactor
@@ -57,6 +58,7 @@ def run_bpython(self, input):
5758 Returns bpython's output.
5859 """
5960 result = Deferred ()
61+ encoding = getpreferredencoding ()
6062
6163 class Protocol (ProcessProtocol ):
6264 STATES = (SEND_INPUT , COLLECT ) = range (2 )
@@ -68,7 +70,7 @@ def __init__(self):
6870 self .state = next (self .states )
6971
7072 def outReceived (self , data ):
71- self .data += data
73+ self .data += data . decode ( encoding )
7274 if self .delayed_call is not None :
7375 self .delayed_call .cancel ()
7476 self .delayed_call = reactor .callLater (0.5 , self .next )
@@ -79,7 +81,7 @@ def next(self):
7981 index = self .data .find (">>> " )
8082 if index >= 0 :
8183 self .data = self .data [index + 4 :]
82- self .transport .write (input )
84+ self .transport .write (input . encode ( encoding ) )
8385 self .state = next (self .states )
8486 else :
8587 self .transport .closeStdin ()
0 commit comments