From ee5ae0cb3d17808e98116693bad603aa936c3dd1 2010-07-31 19:29:05 From: epatters Date: 2010-07-31 19:29:05 Subject: [PATCH] Made blockbreakers' input encoding detection more robust to strange environments. Note: this was commit 251d755362f16c41770 by Evan but I couldn't cherry-pick it because filenames were changed. Applied manually. --- diff --git a/IPython/core/inputsplitter.py b/IPython/core/inputsplitter.py index f775364..a14bf9a 100644 --- a/IPython/core/inputsplitter.py +++ b/IPython/core/inputsplitter.py @@ -75,7 +75,12 @@ def remove_comments(src): def get_input_encoding(): """Return the default standard input encoding.""" - return getattr(sys.stdin, 'encoding', 'ascii') + # There are strange environments for which sys.stdin.encoding is None. We + # ensure that a valid encoding is returned. + encoding = getattr(sys.stdin, 'encoding', None) + if encoding is None: + encoding = 'ascii' + return encoding #----------------------------------------------------------------------------- # Classes and functions