mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Update encodings to 3.14.5 (#7859)
This commit is contained in:
1 parent
fb37b5ecc6
commit
9ee27526bc
2 files changed
+16
No files matched your search
Vendored
+5
@@ -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
|
||||
|
||||
Vendored
+11
@@ -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()
|
||||
Reference in new issue
Block a user