summaryrefslogtreecommitdiff
path: root/textutils.py
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2010-04-19 14:03:23 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2010-04-19 14:03:23 +0200
commitdabbdbbfef50aa30b8f214b4122229b349245d4c (patch)
treeb68d3e3c8619bb52e800d23c2336b7c80a25ebaa /textutils.py
parenta418deb6bff3c80444dd1dde71e0ea10b21186aa (diff)
downloadlogilab-common-dabbdbbfef50aa30b8f214b4122229b349245d4c.tar.gz
[textutils] case insensitive units
Diffstat (limited to 'textutils.py')
-rw-r--r--textutils.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/textutils.py b/textutils.py
index dd33a4d..fbaa69a 100644
--- a/textutils.py
+++ b/textutils.py
@@ -243,11 +243,11 @@ __UNITS_URE = r'[a-zA-Z]+'
_VALUE_RE = re.compile(r'(?P<value>%s)(?P<unit>%s)?'%(__VALUE_URE,__UNITS_URE))
BYTE_UNITS = {
- "B": 1,
- "KB": 1024,
- "MB": 1024 ** 2,
- "GB": 1024 ** 3,
- "TB": 1024 ** 4,
+ "b": 1,
+ "kb": 1024,
+ "mb": 1024 ** 2,
+ "gb": 1024 ** 3,
+ "tb": 1024 ** 4,
}
TIME_UNITS = {
@@ -290,7 +290,7 @@ def apply_units( string, units, inter=None, final=float, blank_reg=_BLANK_RE,
value = inter(lit)
if unit is not None:
try:
- value *= units[unit]
+ value *= units[unit.lower()]
except KeyError:
raise KeyError('invalid unit %s. valid units are %s' %
unit, units.keys())