def parse_storage_string(value):
 byte_multipliers = {u'K': 1024, u'M': 1048576, u'G': 1073741824, u'T': 1099511627776}
 if (not isinstance(value, types.StringTypes)):
  raise ValueError(u'Value must be string, got {type}.'.format(type=type(value).__name__))
 pattern = re.compile(u'^(\\d+\\.?\\d*)(K|M|G|T)?$', (re.I | re.U))
 parsed = pattern.match(value)
 if (not parsed):
  raise ValueError(u"Value '{value}' could not be parsed as a storage quantity.".format(value=value))
 (quantity, unit) = parsed.groups()
 quantity = float(quantity)
 if (unit is not None):
  unit = unit.upper()
  quantity = (quantity * byte_multipliers[unit])
 quantity = int(math.ceil(quantity))
 return quantity

def parse_storage_string ( value ) : byte_multipliers = { u'K' : 1024 , u'M' : 1048576 , u'G' : 1073741824 , u'T' : 1099511627776 } if ( not isinstance ( value , types . StringTypes ) ) : raise ValueError ( u'Value must be string, got {type}.' . format ( type = type ( value ) . __name__ ) ) pattern = re . compile ( u'^(\\d+\\.?\\d*)(K|M|G|T)?$' , ( re . I | re . U ) ) parsed = pattern . match ( value ) if ( not parsed ) : raise ValueError ( u"Value '{value}' could not be parsed as a storage quantity." . format ( value = value ) ) ( quantity , unit ) = parsed . groups ( ) quantity = float ( quantity ) if ( unit is not None ) : unit = unit . upper ( ) quantity = ( quantity * byte_multipliers [ unit ] ) quantity = int ( math . ceil ( quantity ) ) return quantity
converts a string representing a quantity and a unit identifier in to an integer value representing the number of bytes in that quantity .