File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -570,10 +570,22 @@ def getpreferredencoding(do_setlocale = True):
570
570
except Error :
571
571
pass
572
572
result = nl_langinfo (CODESET )
573
+ if not result and sys .platform == 'darwin' :
574
+ # nl_langinfo can return an empty string
575
+ # when the setting has an invalid value.
576
+ # Default to UTF-8 in that case because
577
+ # UTF-8 is the default charset on OSX and
578
+ # returning nothing will crash the
579
+ # interpreter.
580
+ result = 'UTF-8'
581
+
573
582
setlocale (LC_CTYPE , oldloc )
574
583
return result
575
584
else :
576
- return nl_langinfo (CODESET )
585
+ result = nl_langinfo (CODESET )
586
+ if not result and sys .platform == 'darwin' :
587
+ # See above for explanation
588
+ result = 'UTF-8'
577
589
578
590
579
591
### Database
You can’t perform that action at this time.
0 commit comments