@@ -807,19 +807,17 @@ def filesizeformat(bytes):
807
807
except (TypeError ,ValueError ,UnicodeDecodeError ):
808
808
return u"0 bytes"
809
809
810
- BYTE_UNITS = (
811
- ('KB' , 1024 ),
812
- ('MB' , 1024 * 1024 ),
813
- ('GB' , 1024 * 1024 * 1024 ),
814
- ('TB' , 1024 * 1024 * 1024 * 1024 ),
815
- ('PB' , 1024 * 1024 * 1024 * 1024 * 1024 )
816
- )
817
-
818
- if bytes < BYTE_UNITS [0 ][1 ]:
810
+ if bytes < 1024 :
819
811
return ungettext ("%(size)d byte" , "%(size)d bytes" , bytes ) % {'size' : bytes }
820
- for index , (unit , unit_size ) in enumerate (BYTE_UNITS ):
821
- if bytes < unit_size * 1024 or index == len (BYTE_UNITS ) - 1 :
822
- return ugettext ("%.1f %s" ) % (bytes / unit_size , unit )
812
+ if bytes < 1024 * 1024 :
813
+ return ugettext ("%.1f KB" ) % (bytes / 1024 )
814
+ if bytes < 1024 * 1024 * 1024 :
815
+ return ugettext ("%.1f MB" ) % (bytes / (1024 * 1024 ))
816
+ if bytes < 1024 * 1024 * 1024 * 1024 :
817
+ return ugettext ("%.1f GB" ) % (bytes / (1024 * 1024 * 1024 ))
818
+ if bytes < 1024 * 1024 * 1024 * 1024 * 1024 :
819
+ return ugettext ("%.1f TB" ) % (bytes / (1024 * 1024 * 1024 * 1024 ))
820
+ return ugettext ("%.1f PB" ) % (bytes / (1024 * 1024 * 1024 * 1024 * 1024 ))
823
821
filesizeformat .is_safe = True
824
822
825
823
def pluralize (value , arg = u's' ):
0 commit comments