mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-136702: Deprecate passing non-ascii *encoding* (str) to encodings.normalize_encoding (#140030)
Closes #136702
This commit is contained in:
parent
7ae440f262
commit
5ba0a1aa1f
8 changed files with 42 additions and 6 deletions
|
|
@ -3886,15 +3886,14 @@ def search_function(encoding):
|
|||
self.assertEqual(codecs.lookup('TEST.AAA 8'), ('test.aaa-8', 2, 3, 4))
|
||||
self.assertEqual(codecs.lookup('TEST.AAA---8'), ('test.aaa---8', 2, 3, 4))
|
||||
self.assertEqual(codecs.lookup('TEST.AAA 8'), ('test.aaa---8', 2, 3, 4))
|
||||
self.assertEqual(codecs.lookup('TEST.AAA\xe9\u20ac-8'), ('test.aaa\xe9\u20ac-8', 2, 3, 4))
|
||||
self.assertEqual(codecs.lookup('TEST.AAA.8'), ('test.aaa.8', 2, 3, 4))
|
||||
self.assertEqual(codecs.lookup('TEST.AAA...8'), ('test.aaa...8', 2, 3, 4))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
self.assertEqual(codecs.lookup('TEST.AAA\xe9\u20ac-8'), ('test.aaa\xe9\u20ac-8', 2, 3, 4))
|
||||
|
||||
def test_encodings_normalize_encoding(self):
|
||||
# encodings.normalize_encoding() ignores non-ASCII characters.
|
||||
normalize = encodings.normalize_encoding
|
||||
self.assertEqual(normalize('utf_8'), 'utf_8')
|
||||
self.assertEqual(normalize('utf\xE9\u20AC\U0010ffff-8'), 'utf_8')
|
||||
self.assertEqual(normalize('utf 8'), 'utf_8')
|
||||
# encodings.normalize_encoding() doesn't convert
|
||||
# characters to lower case.
|
||||
|
|
@ -3902,6 +3901,11 @@ def test_encodings_normalize_encoding(self):
|
|||
self.assertEqual(normalize('utf.8'), 'utf.8')
|
||||
self.assertEqual(normalize('utf...8'), 'utf...8')
|
||||
|
||||
# Non-ASCII *encoding* is deprecated.
|
||||
with self.assertWarnsRegex(DeprecationWarning,
|
||||
"Support for non-ascii encoding names will be removed in 3.17"):
|
||||
self.assertEqual(normalize('utf\xE9\u20AC\U0010ffff-8'), 'utf_8')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue