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.
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