Skip to content

Commit

Permalink
bpo-30409: locale.getpreferredencoding doesn't return result (#1672)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmccully authored and vstinner committed May 21, 2017
1 parent e6a0b59 commit cef8b17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
23 changes: 10 additions & 13 deletions Lib/locale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ Arnaud Mazin
Pam McA'Nulty
Matt McClure
Rebecca McCreary
Sean McCully
Kirk McDonald
Chris McDonough
Greg McFarlane
Expand Down

0 comments on commit cef8b17

Please sign in to comment.