From 14d07a7f47317a9b41a2e8acc6adc8a726d07f25 Mon Sep 17 00:00:00 2001 From: Sean McCully Date: Fri, 19 May 2017 23:36:31 -0400 Subject: [PATCH] bpo-30409: locale.getpreferredencoding doesn't return result --- Lib/locale.py | 23 ++++++++++------------- Misc/ACKS | 1 + 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Lib/locale.py b/Lib/locale.py index be34c5ddcd5893..62aad5ae7bf965 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -617,22 +617,19 @@ def getpreferredencoding(do_setlocale = True): except Error: pass result = nl_langinfo(CODESET) - if not result and sys.platform == 'darwin': - # nl_langinfo can return an empty string - # when the setting has an invalid value. - # Default to UTF-8 in that case because - # UTF-8 is the default charset on OSX and - # returning nothing will crash the - # interpreter. - result = 'UTF-8' - setlocale(LC_CTYPE, oldloc) - return result else: result = nl_langinfo(CODESET) - if not result and sys.platform == 'darwin': - # See above for explanation - result = 'UTF-8' + + if not result and sys.platform == 'darwin': + # nl_langinfo can return an empty string + # when the setting has an invalid value. + # Default to UTF-8 in that case because + # UTF-8 is the default charset on OSX and + # returning nothing will crash the + # interpreter. + result = 'UTF-8' + return result ### Database diff --git a/Misc/ACKS b/Misc/ACKS index 01bcd3b834f162..7e7f26c0ae19ab 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -903,6 +903,7 @@ Arnaud Mazin Pam McA'Nulty Matt McClure Rebecca McCreary +Sean McCully Kirk McDonald Chris McDonough Greg McFarlane