#NEWLINE# @ register . filter #NEWLINE# def humanize_bytes( value , precision = 1 ) : #NEWLINE# #INDENT# '\n    Generate a humanized version of a file size.\n    :param value:\n    :param precision:\n    :return:\n    ' #NEWLINE# abbrevs = ( ( ( 1 << 50 ) , 'PB' ) , ( ( 1 << 40 ) , 'TB' ) , ( ( 1 << 30 ) , 'GB' ) , ( ( 1 << 20 ) , 'MB' ) , ( ( 1 << 10 ) , 'kB' ) , ( 1 , 'bytes' ) ) #NEWLINE# if ( value == 1 ) : #NEWLINE# #INDENT# return '1 byte' #NEWLINE# #UNINDENT# for ( factor , suffix ) in abbrevs : #NEWLINE# #INDENT# if ( value >= factor ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return ( '%.*f %s' % ( precision , ( value / factor ) , suffix ) )