From feb5246bb1ea316deb9a23336c34b96a2aadb91f Mon Sep 17 00:00:00 2001 From: jesko Date: Thu, 24 Oct 2024 21:24:03 +0200 Subject: [PATCH] adds backwards compatibility for randbytes --- refinery/lib/argformats.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/refinery/lib/argformats.py b/refinery/lib/argformats.py index 817ccb953..74f82cfd9 100644 --- a/refinery/lib/argformats.py +++ b/refinery/lib/argformats.py @@ -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: @@ -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(