def human_file_size(size):
 if hasattr(size, u'unit'):
  from .. import units as u
  size = size.to(u.byte).value
 suffixes = u' kMGTPEZY'
 if (size == 0):
  num_scale = 0
 else:
  num_scale = int(math.floor((math.log(size) / math.log(1000))))
 if (num_scale > 7):
  suffix = u'?'
 else:
  suffix = suffixes[num_scale]
 num_scale = int(math.pow(1000, num_scale))
 value = (size / num_scale)
 str_value = str(value)
 if (suffix == u' '):
  str_value = str_value[:str_value.index(u'.')]
 elif (str_value[2] == u'.'):
  str_value = str_value[:2]
 else:
  str_value = str_value[:3]
 return u'{0:>3s}{1}'.format(str_value, suffix)

def human_file_size ( size ) : if hasattr ( size , u'unit' ) : from . . import units as u size = size . to ( u . byte ) . value suffixes = u' kMGTPEZY' if ( size == 0 ) : num_scale = 0 else : num_scale = int ( math . floor ( ( math . log ( size ) / math . log ( 1000 ) ) ) ) if ( num_scale > 7 ) : suffix = u'?' else : suffix = suffixes [ num_scale ] num_scale = int ( math . pow ( 1000 , num_scale ) ) value = ( size / num_scale ) str_value = str ( value ) if ( suffix == u' ' ) : str_value = str_value [ : str_value . index ( u'.' ) ] elif ( str_value [ 2 ] == u'.' ) : str_value = str_value [ : 2 ] else : str_value = str_value [ : 3 ] return u'{0:>3s}{1}' . format ( str_value , suffix )
returns a human-friendly string representing a file size that is 2-4 characters long .