VMM/common: human_size() size argument can be also a string. v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Fri, 11 Feb 2011 18:22:37 +0000
branchv0.6.x
changeset 396 7f931c1ca059
parent 395 0a13849243f2
child 397 cf661a40266d
VMM/common: human_size() size argument can be also a string. Because the default value of misc.quota_bytes is '0', a string in order to accept also settings like '500M'.
VirtualMailManager/common.py
--- a/VirtualMailManager/common.py	Fri Feb 11 11:52:59 2011 +0000
+++ b/VirtualMailManager/common.py	Fri Feb 11 18:22:37 2011 +0000
@@ -69,8 +69,13 @@
 
 def human_size(size):
     """Converts the `size` in bytes in human readable format."""
-    if not isinstance(size, (long, int)) or size < 0:
-        raise TypeError("'size' must be a positive long or int.")
+    if not isinstance(size, (long, int)):
+        try:
+            size = long(size)
+        except ValueError:
+            raise TypeError("'size' must be a positive long or int.")
+    if size < 0:
+        raise ValueError("'size' must be a positive long or int.")
     if not size:
         return '0b'
     unit_limit = (('T', 1 << 40), ('G', 1 << 30), ('M', 1 << 20),