From 251d755362f16c417701dec21be65527c3ed854f 2010-07-30 17:32:38 From: epatters Date: 2010-07-30 17:32:38 Subject: [PATCH] Made blockbreakers' input encoding detection more robust to strange environments. --- diff --git a/IPython/core/blockbreaker.py b/IPython/core/blockbreaker.py index 39bc660..09fefe0 100644 --- a/IPython/core/blockbreaker.py +++ b/IPython/core/blockbreaker.py @@ -72,7 +72,13 @@ 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