Update encodings to 3.14.5 (#7859)

This commit is contained in:
Shahar Naveh authored and GitHub committed 2026-05-12 20:54:11 +09:00
1 parent fb37b5ecc6
commit 9ee27526bc
2 files changed
+16

No files matched your search

+5
View File
@@ -33,6 +33,7 @@ import sys
from . import aliases
_cache = {}
_MAXCACHE = 500
_unknown = '--unknown--'
_import_tail = ['*']
_aliases = aliases.aliases
@@ -115,6 +116,8 @@ def search_function(encoding):
if mod is None:
# Cache misses
if len(_cache) >= _MAXCACHE:
_cache.clear()
_cache[encoding] = None
return None
@@ -136,6 +139,8 @@ def search_function(encoding):
entry = codecs.CodecInfo(*entry)
# Cache the codec registry entry
if len(_cache) >= _MAXCACHE:
_cache.clear()
_cache[encoding] = entry
# Register its aliases (without overwriting previously registered
+11
View File
@@ -3921,5 +3921,16 @@ class CodecNameNormalizationTest(unittest.TestCase):
self.assertEqual(normalize('utf...8'), 'utf...8')
class CodecCacheTest(unittest.TestCase):
def test_cache_bounded(self):
for i in range(encodings._MAXCACHE + 1000):
try:
b'x'.decode(f'nonexist_{i}')
except LookupError:
pass
self.assertLessEqual(len(encodings._cache), encodings._MAXCACHE)
if __name__ == "__main__":
unittest.main()