Rename variables byte_value -> number, string -> unit_string.
This commit is contained in:
parent
46487d7a31
commit
430002f914
1 changed files with 9 additions and 9 deletions
|
@ -108,21 +108,21 @@ def parsebytes(string):
|
||||||
raise ValueError('No numbers found.')
|
raise ValueError('No numbers found.')
|
||||||
if len(matches) > 1:
|
if len(matches) > 1:
|
||||||
raise ValueError('Too many numbers found.')
|
raise ValueError('Too many numbers found.')
|
||||||
byte_value = matches[0]
|
number = matches[0]
|
||||||
|
|
||||||
if not string.startswith(byte_value):
|
if not string.startswith(number):
|
||||||
raise ValueError('Number is not at start of string.')
|
raise ValueError('Number is not at start of string.')
|
||||||
|
|
||||||
# if the string has no text besides the number, just return that int.
|
# if the string has no text besides the number, return that int of bytes.
|
||||||
string = string.replace(byte_value, '')
|
unit_string = string.replace(number, '')
|
||||||
byte_value = float(byte_value)
|
if unit_string == '':
|
||||||
if string == '':
|
return int(float(number))
|
||||||
return int(byte_value)
|
|
||||||
|
|
||||||
unit_string = normalize_unit_string(string)
|
number = float(number)
|
||||||
|
unit_string = normalize_unit_string(unit_string)
|
||||||
multiplier = REVERSED_UNIT_STRINGS[unit_string]
|
multiplier = REVERSED_UNIT_STRINGS[unit_string]
|
||||||
|
|
||||||
return int(byte_value * multiplier)
|
return int(number * multiplier)
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
for line in pipeable.go(args, strip=True, skip_blank=True):
|
for line in pipeable.go(args, strip=True, skip_blank=True):
|
||||||
|
|
Loading…
Reference in a new issue