From e5c9d9673d6d92291b7911f4255cbbafebceed0e Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Wed, 12 Dec 2018 01:02:58 +0000 Subject: [PATCH] Fix ``size_to_bytes`` for some float values Values like `.01` and `1.` were broken in commit 26a6b1c83381d1c75131f330d8b8f4c23680f1dd . The new regexp allows also scientific notation like `1.2E2` . --- lib/galaxy/util/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 470a90d5491..d0e6dbe9822 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -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\d+(\.\d+)?)\s*(?P[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(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)\s*(?P[eptgmk]?(b|bytes?)?)?$') size_match = size_re.match(size.lower()) if size_match is None: raise ValueError("Could not parse string '%s'" % size)