Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39ad798

Browse files
committed
grab sys.__stdout__ on load and store it, then revert back to it on exit
1 parente949f13 commit39ad798

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

‎bpython/cli.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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__
7676
stdscr=None
7777

7878
classStruct(object):
@@ -1061,7 +1061,8 @@ def write(self, s):
10611061
t=s
10621062

10631063
ifisinstance(t,unicode):
1064-
t=t.encode(getattr(sys.__stdout__,'encoding')orsys.getdefaultencoding())
1064+
t= (t.encode(getattr(orig_stdout,'encoding',None)or
1065+
sys.getdefaultencoding()))
10651066

10661067
ifnotself.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
ifisinstance(s,unicode):
1099-
s=s.encode(getattr(sys.__stdout__,'encoding')orsys.getdefaultencoding())
1100+
s= (s.encode(getattr(orig_stdout,'encoding',None)
1101+
orsys.getdefaultencoding()))
11001102

11011103
a=curses.color_pair(0)
11021104
if'\x01'ins:
@@ -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
returnh,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
iftb:
19371939
printtb
19381940
sys.exit(1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp