mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update locale from v3.14.3
This commit is contained in:
committed by
Jeong, YunWon
parent
04cf5dacca
commit
a27d812286
11
Lib/locale.py
vendored
11
Lib/locale.py
vendored
@@ -13,7 +13,6 @@ also includes default encodings for all supported locale names.
|
||||
import sys
|
||||
import encodings
|
||||
import encodings.aliases
|
||||
import re
|
||||
import _collections_abc
|
||||
from builtins import str as _builtin_str
|
||||
import functools
|
||||
@@ -177,8 +176,7 @@ def _strip_padding(s, amount):
|
||||
amount -= 1
|
||||
return s[lpos:rpos+1]
|
||||
|
||||
_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
|
||||
r'(?P<modifiers>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
|
||||
_percent_re = None
|
||||
|
||||
def _format(percent, value, grouping=False, monetary=False, *additional):
|
||||
if additional:
|
||||
@@ -217,6 +215,13 @@ def format_string(f, val, grouping=False, monetary=False):
|
||||
Grouping is applied if the third parameter is true.
|
||||
Conversion uses monetary thousands separator and grouping strings if
|
||||
forth parameter monetary is true."""
|
||||
global _percent_re
|
||||
if _percent_re is None:
|
||||
import re
|
||||
|
||||
_percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?(?P<modifiers'
|
||||
r'>[-#0-9 +*.hlL]*?)[eEfFgGdiouxXcrs%]')
|
||||
|
||||
percents = list(_percent_re.finditer(f))
|
||||
new_f = _percent_re.sub('%s', f)
|
||||
|
||||
|
||||
41
Lib/test/test_locale.py
vendored
41
Lib/test/test_locale.py
vendored
@@ -1,7 +1,7 @@
|
||||
from decimal import Decimal
|
||||
from test.support import verbose, is_android, is_emscripten, is_wasi
|
||||
from test.support import cpython_only, verbose, is_android, linked_to_musl, os_helper
|
||||
from test.support.warnings_helper import check_warnings
|
||||
from test.support.import_helper import import_fresh_module
|
||||
from test.support.import_helper import ensure_lazy_imports, import_fresh_module
|
||||
from unittest import mock
|
||||
import unittest
|
||||
import locale
|
||||
@@ -9,6 +9,11 @@ import os
|
||||
import sys
|
||||
import codecs
|
||||
|
||||
class LazyImportTest(unittest.TestCase):
|
||||
@cpython_only
|
||||
def test_lazy_import(self):
|
||||
ensure_lazy_imports("locale", {"re", "warnings"})
|
||||
|
||||
|
||||
class BaseLocalizedTest(unittest.TestCase):
|
||||
#
|
||||
@@ -351,10 +356,7 @@ class TestEnUSCollation(BaseLocalizedTest, TestCollation):
|
||||
|
||||
@unittest.skipIf(sys.platform.startswith('aix'),
|
||||
'bpo-29972: broken test on AIX')
|
||||
@unittest.skipIf(
|
||||
is_emscripten or is_wasi,
|
||||
"musl libc issue on Emscripten/WASI, bpo-46390"
|
||||
)
|
||||
@unittest.skipIf(linked_to_musl(), "musl libc issue, bpo-46390")
|
||||
@unittest.skipIf(sys.platform.startswith("netbsd"),
|
||||
"gh-124108: NetBSD doesn't support UTF-8 for LC_COLLATE")
|
||||
def test_strcoll_with_diacritic(self):
|
||||
@@ -362,10 +364,7 @@ class TestEnUSCollation(BaseLocalizedTest, TestCollation):
|
||||
|
||||
@unittest.skipIf(sys.platform.startswith('aix'),
|
||||
'bpo-29972: broken test on AIX')
|
||||
@unittest.skipIf(
|
||||
is_emscripten or is_wasi,
|
||||
"musl libc issue on Emscripten/WASI, bpo-46390"
|
||||
)
|
||||
@unittest.skipIf(linked_to_musl(), "musl libc issue, bpo-46390")
|
||||
@unittest.skipIf(sys.platform.startswith("netbsd"),
|
||||
"gh-124108: NetBSD doesn't support UTF-8 for LC_COLLATE")
|
||||
def test_strxfrm_with_diacritic(self):
|
||||
@@ -541,7 +540,6 @@ class TestMiscellaneous(unittest.TestCase):
|
||||
# valid. Furthermore 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'))
|
||||
|
||||
@@ -551,25 +549,14 @@ class TestMiscellaneous(unittest.TestCase):
|
||||
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'
|
||||
|
||||
with check_warnings(('', DeprecationWarning)):
|
||||
self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8'))
|
||||
with os_helper.EnvironmentVarGuard() as env:
|
||||
env.unset('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')
|
||||
env.set('LC_CTYPE', 'UTF-8')
|
||||
|
||||
with check_warnings(('', DeprecationWarning)):
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user