#NEWLINE# def to_bytes( text , default = 0 ) : #NEWLINE# #INDENT# 'Converts a string into an integer of bytes.\n\n    Looks at the last characters of the text to determine\n    what conversion is needed to turn the input text into a byte number.\n    Supports "B, K(B), M(B), G(B), and T(B)". (case insensitive)\n\n    :param text: String input for bytes size conversion.\n    :param default: Default return value when text is blank.\n\n    ' #NEWLINE# match = BYTE_REGEX . search ( text ) #NEWLINE# if match : #NEWLINE# #INDENT# magnitude = int ( match . group ( 1 ) ) #NEWLINE# mult_key_org = match . group ( 2 ) #NEWLINE# if ( not mult_key_org ) : #NEWLINE# #INDENT# return magnitude #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if text : #NEWLINE# #INDENT# msg = ( _ ( 'Invalid string format: %s' ) % text ) #NEWLINE# raise TypeError ( msg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return default #NEWLINE# #UNINDENT# #UNINDENT# mult_key = mult_key_org . lower ( ) . replace ( 'b' , '' , 1 ) #NEWLINE# multiplier = BYTE_MULTIPLIERS . get ( mult_key ) #NEWLINE# if ( multiplier is None ) : #NEWLINE# #INDENT# msg = ( _ ( 'Unknown byte multiplier: %s' ) % mult_key_org ) #NEWLINE# raise TypeError ( msg ) #NEWLINE# #UNINDENT# return ( magnitude * multiplier )