@@ -72,7 +72,7 @@ def log(x):
7272 f = open ('/tmp/bpython.log' , 'a' )
7373 f .write ('%s\n ' % (x ,))
7474
75-
75+ orig_stdout = sys . __stdout__
7676stdscr = None
7777
7878class Struct (object ):
@@ -1061,7 +1061,8 @@ def write(self, s):
10611061 t = s
10621062
10631063 if isinstance (t , unicode ):
1064- t = t .encode (getattr (sys .__stdout__ , 'encoding' ) or sys .getdefaultencoding ())
1064+ t = (t .encode (getattr (orig_stdout , 'encoding' , None ) or
1065+ sys .getdefaultencoding ()))
10651066
10661067 if not self .stdout_hist :
10671068 self .stdout_hist = t
@@ -1096,7 +1097,8 @@ def echo(self, s, redraw=True):
10961097 srings. It won't update the screen if it's reevaluating the code (as it
10971098 does with undo)."""
10981099 if isinstance (s , unicode ):
1099- s = s .encode (getattr (sys .__stdout__ , 'encoding' ) or sys .getdefaultencoding ())
1100+ s = (s .encode (getattr (orig_stdout , 'encoding' , None )
1101+ or sys .getdefaultencoding ()))
11001102
11011103 a = curses .color_pair (0 )
11021104 if '\x01 ' in s :
@@ -1712,7 +1714,7 @@ def gethw():
17121714
17131715 """
17141716 h , w = struct .unpack (
1715- "hhhh" , fcntl .ioctl (sys . __stdout__ , termios .TIOCGWINSZ , "\000 " * 8 ))[0 :2 ]
1717+ "hhhh" , fcntl .ioctl (orig_stdout , termios .TIOCGWINSZ , "\000 " * 8 ))[0 :2 ]
17161718 return h , w
17171719
17181720
@@ -1932,7 +1934,7 @@ def main(args=None):
19321934 curses .nocbreak ()
19331935 curses .endwin ()
19341936
1935- sys .stdout = sys . __stdout__
1937+ sys .stdout = orig_stdout
19361938 if tb :
19371939 print tb
19381940 sys .exit (1 )
0 commit comments