File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -1099,9 +1099,31 @@ def __init__(self):
1099
1099
self .date_dayfirst = False
1100
1100
self .date_yearfirst = False
1101
1101
self .multi_sparse = True
1102
- self .encoding = sys .getdefaultencoding ()
1103
- if self .encoding == 'ascii' :
1104
- self .encoding = 'UTF8'
1102
+ self .encoding = self .detect_encoding ()
1103
+
1104
+ def detect_encoding (self ):
1105
+ """
1106
+ Try to find the most capable encoding supported by the console.
1107
+ slighly modified from the way IPython handles the same issue.
1108
+ """
1109
+ import locale
1110
+
1111
+ encoding = None
1112
+ try :
1113
+ encoding = sys .stdin .encoding
1114
+ except AttributeError :
1115
+ pass
1116
+
1117
+ if not encoding or encoding == 'ascii' : # try again for something better
1118
+ try :
1119
+ encoding = locale .getpreferredencoding ()
1120
+ except Exception :
1121
+ pass
1122
+
1123
+ if not encoding : # when all else fails. this will usually be "ascii"
1124
+ encoding = sys .getdefaultencoding ()
1125
+
1126
+ return encoding
1105
1127
1106
1128
def reset (self ):
1107
1129
self .__init__ ()
You can’t perform that action at this time.
0 commit comments