Assume bytes for bare numbers in string_to_bytes()
This commit is contained in:
parent
c4009517e4
commit
301c64be4c
1 changed files with 14 additions and 2 deletions
|
|
@ -1013,9 +1013,21 @@ def string_to_bytes(size, assume_binary=False):
|
||||||
LOG.debug('size: %s, assume_binary: %s', size, assume_binary)
|
LOG.debug('size: %s, assume_binary: %s', size, assume_binary)
|
||||||
scale = 1000
|
scale = 1000
|
||||||
size = str(size)
|
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:
|
if not tmp:
|
||||||
raise ValueError(f'Invalid size string: {size}')
|
raise ValueError(f'Invalid size string: {size}')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue