VirtualMailManager/common.py
branchv0.6.x
changeset 395 0a13849243f2
parent 394 d3a3c6155879
child 396 7f931c1ca059
equal deleted inserted replaced
394:d3a3c6155879 395:0a13849243f2
    67     return binary
    67     return binary
    68 
    68 
    69 
    69 
    70 def human_size(size):
    70 def human_size(size):
    71     """Converts the `size` in bytes in human readable format."""
    71     """Converts the `size` in bytes in human readable format."""
    72     if not isinstance(size, (long, int)) or size < 1:
    72     if not isinstance(size, (long, int)) or size < 0:
    73         raise TypeError("'size' must be a long or int and greater than 0.")
    73         raise TypeError("'size' must be a positive long or int.")
       
    74     if not size:
       
    75         return '0b'
    74     unit_limit = (('T', 1 << 40), ('G', 1 << 30), ('M', 1 << 20),
    76     unit_limit = (('T', 1 << 40), ('G', 1 << 30), ('M', 1 << 20),
    75                   ('k', 1 << 10), ('b', 1))
    77                   ('k', 1 << 10), ('b', 1))
    76     for unit, limit in unit_limit:
    78     for unit, limit in unit_limit:
    77         if size >= limit:
    79         if size >= limit:
    78             if unit != 'b':
    80             if unit != 'b':