From 301c64be4c18448bd565b9debe788f9cf09d9d0d Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 24 May 2022 16:23:27 -0700 Subject: [PATCH] Assume bytes for bare numbers in string_to_bytes() --- scripts/wk/std.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/wk/std.py b/scripts/wk/std.py index c811bdc5..f86da901 100644 --- a/scripts/wk/std.py +++ b/scripts/wk/std.py @@ -1013,9 +1013,21 @@ def string_to_bytes(size, assume_binary=False): LOG.debug('size: %s, assume_binary: %s', size, assume_binary) scale = 1000 size = str(size) - tmp = REGEX_SIZE_STRING.search(size.upper()) - # Raise exception if string can't be parsed as a size + # Check if given a bare number (no units) + try: + tmp = float(size) + except ValueError: + # Ignore and try parsing below + pass + else: + # Return as int assuming input value was in bytes + size = int(tmp) + LOG.debug('bytes: %s', size) + return size + + # Parse string + tmp = REGEX_SIZE_STRING.search(size.upper()) if not tmp: raise ValueError(f'Invalid size string: {size}')