]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Allow T (terabytes), P (petabytes), and E (exabytes), case-insensitive, in parse_abbr...
authorDavid-Sarah Hopwood <david-sarah@jacaranda.org>
Thu, 27 Dec 2012 20:08:00 +0000 (20:08 +0000)
committerDavid-Sarah Hopwood <david-sarah@jacaranda.org>
Thu, 27 Dec 2012 20:08:00 +0000 (20:08 +0000)
This also simplifies how case-insensitivity is handled, and fixes a corner case
where the wrong exception was raised when the size ends in "BB".
fixes #1812

Signed-off-by: David-Sarah Hopwood <davidsarah@mint>
src/allmydata/test/test_util.py
src/allmydata/util/abbreviate.py

index 0db1a89b52bc1b38367205c94584d3798f8f4f71..b2d9bbec3a2c2ac49957ada994b3a9eec3d84449 100644 (file)
@@ -775,9 +775,20 @@ class Abbreviate(unittest.TestCase):
         self.failUnlessEqual(p("10MiB"), 10*1024*1024)
         self.failUnlessEqual(p("5G"), 5*1000*1000*1000)
         self.failUnlessEqual(p("4GiB"), 4*1024*1024*1024)
-        e = self.failUnlessRaises(ValueError, p, "12 cubits")
-        self.failUnless("12 cubits" in str(e))
+        self.failUnlessEqual(p("3TB"), 3*1000*1000*1000*1000)
+        self.failUnlessEqual(p("3TiB"), 3*1024*1024*1024*1024)
+        self.failUnlessEqual(p("6PB"), 6*1000*1000*1000*1000*1000)
+        self.failUnlessEqual(p("6PiB"), 6*1024*1024*1024*1024*1024)
+        self.failUnlessEqual(p("9EB"), 9*1000*1000*1000*1000*1000*1000)
+        self.failUnlessEqual(p("9EiB"), 9*1024*1024*1024*1024*1024*1024)
 
+        e = self.failUnlessRaises(ValueError, p, "12 cubits")
+        self.failUnlessIn("12 cubits", str(e))
+        e = self.failUnlessRaises(ValueError, p, "1 BB")
+        self.failUnlessIn("1 BB", str(e))
+        e = self.failUnlessRaises(ValueError, p, "fhtagn")
+        self.failUnlessIn("fhtagn", str(e))
+        
 class Limiter(unittest.TestCase):
     timeout = 480 # This takes longer than 240 seconds on Francois's arm box.
 
index de0571e1da4c94d29085580cd9b46348997b52cf..46dda6c92397dc91396c984e908259373cbd60d0 100644 (file)
@@ -58,20 +58,25 @@ def abbreviate_space_both(s):
 def parse_abbreviated_size(s):
     if s is None or s == "":
         return None
-    m = re.match(r"^(\d+)([kKmMgG]?[iB]?[bB]?)$", s)
+    m = re.match(r"^(\d+)([KMGTPE]?[I]?[B]?)$", s.upper())
     if not m:
         raise ValueError("unparseable value %s" % s)
     number, suffix = m.groups()
-    suffix = suffix.upper()
     if suffix.endswith("B"):
         suffix = suffix[:-1]
-    multiplier = {"": 1,
-                  "I": 1,
-                  "K": 1000,
-                  "M": 1000 * 1000,
-                  "G": 1000 * 1000 * 1000,
+    multiplier = {"":   1,
+                  "I":  1,
+                  "K":  1000,
+                  "M":  1000 * 1000,
+                  "G":  1000 * 1000 * 1000,
+                  "T":  1000 * 1000 * 1000 * 1000,
+                  "P":  1000 * 1000 * 1000 * 1000 * 1000,
+                  "E":  1000 * 1000 * 1000 * 1000 * 1000 * 1000,
                   "KI": 1024,
-                  "MI": 1024*1024,
-                  "GI": 1024*1024*1024,
+                  "MI": 1024 * 1024,
+                  "GI": 1024 * 1024 * 1024,
+                  "TI": 1024 * 1024 * 1024 * 1024,
+                  "PI": 1024 * 1024 * 1024 * 1024 * 1024,
+                  "EI": 1024 * 1024 * 1024 * 1024 * 1024 * 1024,
                   }[suffix]
     return int(number) * multiplier