Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b0caf329
Commit
b0caf329
authored
Aug 29, 2019
by
Ronald Oussoren
Committed by
Ned Deily
Aug 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-18378: Recognize "UTF-8" as a valid name in locale._parse_localename (GH-14736)
parent
fa220ec7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
0 deletions
+41
-0
Lib/locale.py
Lib/locale.py
+4
-0
Lib/test/test_locale.py
Lib/test/test_locale.py
+36
-0
Misc/NEWS.d/next/Library/2019-07-13-13-40-12.bpo-18378.NHcojp.rst
...S.d/next/Library/2019-07-13-13-40-12.bpo-18378.NHcojp.rst
+1
-0
No files found.
Lib/locale.py
View file @
b0caf329
...
...
@@ -492,6 +492,10 @@ def _parse_localename(localename):
return
tuple
(
code
.
split
(
'.'
)[:
2
])
elif
code
==
'C'
:
return
None
,
None
elif
code
==
'UTF-8'
:
# On macOS "LC_CTYPE=UTF-8" is a valid locale setting
# for getting UTF-8 handling for text.
return
None
,
'UTF-8'
raise
ValueError
(
'unknown locale: %s'
%
localename
)
def
_build_localename
(
localetuple
):
...
...
Lib/test/test_locale.py
View file @
b0caf329
...
...
@@ -493,6 +493,42 @@ class NormalizeTest(unittest.TestCase):
class
TestMiscellaneous
(
unittest
.
TestCase
):
def
test_defaults_UTF8
(
self
):
# Issue #18378: on (at least) macOS setting LC_CTYPE to "UTF-8" is
# valid. Futhermore LC_CTYPE=UTF is used by the UTF-8 locale coercing
# during interpreter startup (on macOS).
import
_locale
import
os
self
.
assertEqual
(
locale
.
_parse_localename
(
'UTF-8'
),
(
None
,
'UTF-8'
))
if
hasattr
(
_locale
,
'_getdefaultlocale'
):
orig_getlocale
=
_locale
.
_getdefaultlocale
del
_locale
.
_getdefaultlocale
else
:
orig_getlocale
=
None
orig_env
=
{}
try
:
for
key
in
(
'LC_ALL'
,
'LC_CTYPE'
,
'LANG'
,
'LANGUAGE'
):
if
key
in
os
.
environ
:
orig_env
[
key
]
=
os
.
environ
[
key
]
del
os
.
environ
[
key
]
os
.
environ
[
'LC_CTYPE'
]
=
'UTF-8'
self
.
assertEqual
(
locale
.
getdefaultlocale
(),
(
None
,
'UTF-8'
))
finally
:
for
k
in
orig_env
:
os
.
environ
[
k
]
=
orig_env
[
k
]
if
'LC_CTYPE'
not
in
orig_env
:
del
os
.
environ
[
'LC_CTYPE'
]
if
orig_getlocale
is
not
None
:
_locale
.
_getdefaultlocale
=
orig_getlocale
def
test_getpreferredencoding
(
self
):
# Invoke getpreferredencoding to make sure it does not cause exceptions.
enc
=
locale
.
getpreferredencoding
()
...
...
Misc/NEWS.d/next/Library/2019-07-13-13-40-12.bpo-18378.NHcojp.rst
0 → 100644
View file @
b0caf329
Recognize "UTF-8" as a valid value for LC_CTYPE in locale._parse_localename.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment