Commit cef8b174 authored by Sean McCully's avatar Sean McCully Committed by Victor Stinner

bpo-30409: locale.getpreferredencoding doesn't return result (#1672)

parent e6a0b598
...@@ -617,22 +617,19 @@ else: ...@@ -617,22 +617,19 @@ else:
except Error: except Error:
pass pass
result = nl_langinfo(CODESET) 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) setlocale(LC_CTYPE, oldloc)
return result
else: else:
result = nl_langinfo(CODESET) result = nl_langinfo(CODESET)
if not result and sys.platform == 'darwin':
# See above for explanation if not result and sys.platform == 'darwin':
result = 'UTF-8' # 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 ### Database
......
...@@ -904,6 +904,7 @@ Arnaud Mazin ...@@ -904,6 +904,7 @@ Arnaud Mazin
Pam McA'Nulty Pam McA'Nulty
Matt McClure Matt McClure
Rebecca McCreary Rebecca McCreary
Sean McCully
Kirk McDonald Kirk McDonald
Chris McDonough Chris McDonough
Greg McFarlane Greg McFarlane
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment