Skip to content

Commit

Permalink
Fix top level randomness in aiohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane committed May 9, 2024
1 parent ddfd76d commit 6418dc6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/pyodide/internal/topLevelEntropy/entropy_import_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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_"

Expand Down

0 comments on commit 6418dc6

Please sign in to comment.