mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Fix `size_to_bytes` for some float values
Values like `.01` and `1.` were broken in commit
26a6b1c833 . The new regexp allows also
scientific notation like `1.2E2` .
This commit is contained in:
@@ -1359,8 +1359,15 @@ def size_to_bytes(size):
|
||||
4096
|
||||
>>> size_to_bytes('2.2 TB')
|
||||
2418925581107
|
||||
>>> size_to_bytes('.01 TB')
|
||||
10995116277
|
||||
>>> size_to_bytes('1.b')
|
||||
1
|
||||
>>> size_to_bytes('1.2E2k')
|
||||
122880
|
||||
"""
|
||||
size_re = re.compile(r'(?P<number>\d+(\.\d+)?)\s*(?P<multiple>[eptgmk]?(b|bytes?)?)?$')
|
||||
# The following number regexp is based on https://stackoverflow.com/questions/385558/extract-float-double-value/385597#385597
|
||||
size_re = re.compile(r'(?P<number>(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)\s*(?P<multiple>[eptgmk]?(b|bytes?)?)?$')
|
||||
size_match = size_re.match(size.lower())
|
||||
if size_match is None:
|
||||
raise ValueError("Could not parse string '%s'" % size)
|
||||
|
||||
Reference in New Issue
Block a user