#NEWLINE# def parse_size( size ) : #NEWLINE# #INDENT# size = str ( size ) #NEWLINE# if re . match ( '^\\d+$' , size ) : #NEWLINE# #INDENT# return int ( size ) #NEWLINE# #UNINDENT# m = re . match ( '^(\\d+(?:\\.\\d+)?)(K|M|G)B?$' , size , flags = re . I ) #NEWLINE# if ( not size ) : #NEWLINE# #INDENT# raise Exception ( ( 'Invalid size format: %s' % size ) ) #NEWLINE# #UNINDENT# return int ( ( float ( m . group ( 1 ) ) * { #NEWLINE# #INDENT# 'K' : 1000 , #NEWLINE# 'M' : ( 1000 * 1000 ) , #NEWLINE# 'G' : ( ( 1000 * 1000 ) * 1000 ) , #NEWLINE# #UNINDENT# } [ m . group ( 2 ) . upper ( ) ] ) )