From 4f8a616674aa6a64680bd5c8c9ee4a5fdde6bd44 Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Mon, 26 Jan 2009 09:53:37 +0000 Subject: [PATCH] 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. --- CHANGELOG | 3 +++ bpython/cli.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f184add..05a7816 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,9 @@ Mark Florisson (eggy) gave me a patch that stops weird breakage when unicode objects get added into the output buffer - they now get encoded into the output encoding. +Bohdan Vlasyuk sent me a patch that fixes a problem with the above patch from +Mark if sys.__stdout__.encoding didn't exist. + v0.7.1 ====== Added support for a history file, defaults to ~/.pythonhist and 100 lines but diff --git a/bpython/cli.py b/bpython/cli.py index 1d9a26c..81975c5 100644 --- a/bpython/cli.py +++ b/bpython/cli.py @@ -951,7 +951,7 @@ class Repl(object): t = s if isinstance(t, unicode): - t = t.encode(sys.__stdout__.encoding) + t = t.encode(getattr(sys.__stdout__, 'encoding') or sys.getdefaultencoding()) if not self.stdout_hist: self.stdout_hist = t @@ -986,7 +986,7 @@ class Repl(object): srings. It won't update the screen if it's reevaluating the code (as it does with undo).""" if isinstance(s, unicode): - s = s.encode(sys.__stdout__.encoding) + s = s.encode(getattr(sys.__stdout__, 'encoding') or sys.getdefaultencoding()) a = curses.color_pair(0) if '\x01' in s: