diff --git a/src/pyodide/internal/topLevelEntropy/entropy_import_context.py b/src/pyodide/internal/topLevelEntropy/entropy_import_context.py index fa6e42d0258..edcb89a83b9 100644 --- a/src/pyodide/internal/topLevelEntropy/entropy_import_context.py +++ b/src/pyodide/internal/topLevelEntropy/entropy_import_context.py @@ -20,7 +20,7 @@ import sys RUST_PACKAGES = ["pydantic_core", "tiktoken"] -MODULES_TO_PATCH = ["random", "numpy.random", "numpy.random.mtrand", "tempfile"] + RUST_PACKAGES +MODULES_TO_PATCH = ["random", "numpy.random", "numpy.random.mtrand", "tempfile", "aiohttp.http_websocket"] + RUST_PACKAGES # Control number of allowed entropy calls. @@ -133,6 +133,21 @@ def pydantic_core_context(module): pass +@contextmanager +def aiohttp_http_websocket_context(module): + import random + Random = random.Random + + def patched_Random(): + return random + + random.Random = patched_Random + try: + yield + finally: + random.Random = random + + class DeterministicRandomNameSequence: characters = "abcdefghijklmnopqrstuvwxyz0123456789_"