Skip to content

Commit

Permalink
adds backwards compatibility for randbytes
Browse files Browse the repository at this point in the history
  • Loading branch information
huettenhain committed Oct 24, 2024
1 parent e0ccb76 commit feb5246
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions refinery/lib/argformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,13 @@ def prng(
"""
import random
import time

try:
randbytes = random.randbytes
except AttributeError:
def randbytes(n):
return bytearray(random.randint(0, 0xFF) for _ in range(n))

seed = time.time_ns if seed is None else PythonExpression.Lazy(seed)
size = PythonExpression.Lazy(size)
try:
Expand All @@ -1178,11 +1185,11 @@ def prng(
def finalize(data):
meta = dict(metavars(data))
random.seed(seed(meta))
return random.randbytes(size(meta))
return randbytes(size(meta))
return finalize
else:
random.seed(_seed)
return random.randbytes(_size)
return randbytes(_size)

@handler.register('accu', final=True)
def accu(
Expand Down

0 comments on commit feb5246

Please sign in to comment.