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
e08496b6
Commit
e08496b6
authored
Nov 27, 2015
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #25742: locale.setlocale() now accepts a Unicode string for its second
parameter.
parent
916c7c7a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
1 deletion
+18
-1
Lib/locale.py
Lib/locale.py
+5
-1
Lib/test/test_locale.py
Lib/test/test_locale.py
+10
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/locale.py
View file @
e08496b6
...
...
@@ -18,6 +18,10 @@ import re
import
operator
import
functools
# keep a copy of the builtin str type, because 'str' name is overriden
# in globals by a function below
_str
=
str
try
:
_unicode
=
unicode
except
NameError
:
...
...
@@ -573,7 +577,7 @@ def setlocale(category, locale=None):
category may be given as one of the LC_* values.
"""
if
locale
and
type
(
locale
)
is
not
type
(
""
):
if
locale
and
not
isinstance
(
locale
,
(
_str
,
_unicode
)
):
# convert to string
locale
=
normalize
(
_build_localename
(
locale
))
return
_setlocale
(
category
,
locale
)
...
...
Lib/test/test_locale.py
View file @
e08496b6
...
...
@@ -493,6 +493,16 @@ class TestMiscellaneous(unittest.TestCase):
# longer accept unicode strings.
self
.
assertEqual
(
locale
.
normalize
(
u'en_US'
),
'en_US.ISO8859-1'
)
def
test_setlocale_unicode
(
self
):
old_loc
=
locale
.
getlocale
(
locale
.
LC_ALL
)
try
:
user_locale
=
locale
.
setlocale
(
locale
.
LC_ALL
,
''
)
unicode_locale
=
user_locale
.
decode
(
'utf-8'
)
user_locale2
=
locale
.
setlocale
(
locale
.
LC_ALL
,
unicode_locale
)
self
.
assertEqual
(
user_locale
,
user_locale2
)
finally
:
locale
.
setlocale
(
locale
.
LC_ALL
,
old_loc
)
def
test_main
():
tests
=
[
...
...
Misc/NEWS
View file @
e08496b6
...
...
@@ -20,6 +20,9 @@ Core and Builtins
Library
-------
- Issue #25742: :func:`locale.setlocale` now accepts a Unicode string for
its second parameter.
- Issue #10131: Fixed deep copying of minidom documents. Based on patch
by Marian Ganisin.
...
...
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