def str_to_bytes(size):
 units = ['', 'b', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb', 'zb', 'yb']
 curr_size = size
 try:
  if (size.lower() != 'infinity'):
   try:
    curr_item = size.strip().split(' ')
    curr_size = ''.join(curr_item)
    curr_size = int(curr_size)
   except ValueError:
    curr_item = size.strip().split(' ')
    curr_unit = curr_item[(-1)].strip().lower()
    curr_item = curr_item[0:(-1)]
    curr_size = ''.join(curr_item)
    try:
     curr_size = float(curr_size)
    except ValueError:
     error = ('Unable to convert size ' + str(size))
     raise MalformedYMLException(error)
   try:
    pos = units.index(curr_unit)
    for x in range(pos, 1, (-1)):
     curr_size *= 1024
   except ValueError:
    error = ('Unable to convert size ' + str(size))
    raise MalformedYMLException(error)
   except (UnboundLocalError, NameError):
    pass
  else:
   curr_size = (-1)
 except AttributeError:
  pass
 return curr_size

def str_to_bytes ( size ) : units = [ '' , 'b' , 'kb' , 'mb' , 'gb' , 'tb' , 'pb' , 'eb' , 'zb' , 'yb' ] curr_size = size try : if ( size . lower ( ) != 'infinity' ) : try : curr_item = size . strip ( ) . split ( ' ' ) curr_size = '' . join ( curr_item ) curr_size = int ( curr_size ) except ValueError : curr_item = size . strip ( ) . split ( ' ' ) curr_unit = curr_item [ ( - 1 ) ] . strip ( ) . lower ( ) curr_item = curr_item [ 0 : ( - 1 ) ] curr_size = '' . join ( curr_item ) try : curr_size = float ( curr_size ) except ValueError : error = ( 'Unable to convert size ' + str ( size ) ) raise MalformedYMLException ( error ) try : pos = units . index ( curr_unit ) for x in range ( pos , 1 , ( - 1 ) ) : curr_size *= 1024 except ValueError : error = ( 'Unable to convert size ' + str ( size ) ) raise MalformedYMLException ( error ) except ( UnboundLocalError , NameError ) : pass else : curr_size = ( - 1 ) except AttributeError : pass return curr_size
uses the bi convention: 1024 b = 1 kb since this method primarily has inputs of bytes for ram @type size: str .