<s> from django import template <EOL> register = template . Library ( ) <EOL> @ register . filter <EOL> def humanreadablesize ( kbytes ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> kbytes = float ( kbytes ) <EOL> except ( TypeError , ValueError , UnicodeDecodeError ) : <EOL> return "<STR_LIT>" <EOL> units = [ ( "<STR_LIT>" , <NUM_LIT:2> ** <NUM_LIT:10> ) , ( "<STR_LIT>" , <NUM_LIT:2> ** <NUM_LIT:20> ) , ( "<STR_LIT>" , <NUM_LIT:2> ** <NUM_LIT:30> ) , ( "<STR_LIT>" , <NUM_LIT:2> ** <NUM_LIT> ) ] <EOL> for suffix , limit in units : <EOL> if kbytes > limit : <EOL> continue <EOL> else : <EOL> return str ( round ( kbytes / float ( limit / <NUM_LIT:2> ** <NUM_LIT:10> ) , <NUM_LIT:1> ) ) + suffix <EOL> humanreadablesize . is_safe = True </s>
