Kaydet (Commit) e08496b6 authored tarafından Victor Stinner's avatar Victor Stinner

Closes #25742: locale.setlocale() now accepts a Unicode string for its second

parameter.
üst 916c7c7a
...@@ -18,6 +18,10 @@ import re ...@@ -18,6 +18,10 @@ import re
import operator import operator
import functools import functools
# keep a copy of the builtin str type, because 'str' name is overriden
# in globals by a function below
_str = str
try: try:
_unicode = unicode _unicode = unicode
except NameError: except NameError:
...@@ -573,7 +577,7 @@ def setlocale(category, locale=None): ...@@ -573,7 +577,7 @@ def setlocale(category, locale=None):
category may be given as one of the LC_* values. 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 # convert to string
locale = normalize(_build_localename(locale)) locale = normalize(_build_localename(locale))
return _setlocale(category, locale) return _setlocale(category, locale)
......
...@@ -493,6 +493,16 @@ class TestMiscellaneous(unittest.TestCase): ...@@ -493,6 +493,16 @@ class TestMiscellaneous(unittest.TestCase):
# longer accept unicode strings. # longer accept unicode strings.
self.assertEqual(locale.normalize(u'en_US'), 'en_US.ISO8859-1') 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(): def test_main():
tests = [ tests = [
......
...@@ -20,6 +20,9 @@ Core and Builtins ...@@ -20,6 +20,9 @@ Core and Builtins
Library 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 - Issue #10131: Fixed deep copying of minidom documents. Based on patch
by Marian Ganisin. by Marian Ganisin.
......
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