Skip to content

Commit 2425738

Browse files
committed
Bohdan Vlasyuk patch applied to check beforehand if sys.__stdout__.encoding exists
It falls back to sys.getdefaultencoding() if the stdout object doesn't have an encoding attribute. committer: Bob Farrell <robertanthonyfarrell@gmail.com>
1 parent 745db43 commit 2425738

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Mark Florisson (eggy) gave me a patch that stops weird breakage when unicode
1616
objects get added into the output buffer - they now get encoded into the output
1717
encoding.
1818

19+
Bohdan Vlasyuk sent me a patch that fixes a problem with the above patch from
20+
Mark if sys.__stdout__.encoding didn't exist.
21+
1922
v0.7.1
2023
======
2124
Added support for a history file, defaults to ~/.pythonhist and 100 lines but

bpython/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ def write(self, s):
951951
t = s
952952

953953
if isinstance(t, unicode):
954-
t = t.encode(sys.__stdout__.encoding)
954+
t = t.encode(getattr(sys.__stdout__, 'encoding') or sys.getdefaultencoding())
955955

956956
if not self.stdout_hist:
957957
self.stdout_hist = t
@@ -986,7 +986,7 @@ def echo(self, s, redraw=True):
986986
srings. It won't update the screen if it's reevaluating the code (as it
987987
does with undo)."""
988988
if isinstance(s, unicode):
989-
s = s.encode(sys.__stdout__.encoding)
989+
s = s.encode(getattr(sys.__stdout__, 'encoding') or sys.getdefaultencoding())
990990

991991
a = curses.color_pair(0)
992992
if '\x01' in s:

0 commit comments

Comments
 (0)