parameters: (size, expect='auto', rate=1000)
return_statement: return expect_size, expect
docstring: :param size: '100MB', '1G'
      :param expect: 'K, M, G, T
      :param rate: Default 1000, may be 1024
      :return:
docstring_summary: :param size: '100MB', '1G'
      :param expect: 'K, M, G, T
      :param rate: Default 1000, may be 1024
      :return:
docstring_tokens: : param size : 100MB 1G : param expect : K M G T : param rate : Default 1000 may be 1024 : return :
function: def capacity_convert(size, expect='auto', rate=1000):
      """
      :param size: '100MB', '1G'
      :param expect: 'K, M, G, T
      :param rate: Default 1000, may be 1024
      :return:
      """
      rate_mapping = (
          ('K', rate),
          ('KB', rate),
          ('M', rate**2),
          ('MB', rate**2),
          ('G', rate**3),
          ('GB', rate**3),
          ('T', rate**4),
          ('TB', rate**4),
      )
  
      rate_mapping = OrderedDict(rate_mapping)
  
      std_size = 0  # To KB
      for unit in rate_mapping:
          if size.endswith(unit):
              try:
                  std_size = float(size.strip(unit).strip()) * rate_mapping[unit]
              except ValueError:
                  pass
  
      if expect == 'auto':
          for unit, rate_ in rate_mapping.items():
              if rate > std_size/rate_ >= 1 or unit == "T":
                  expect = unit
                  break
  
      if expect not in rate_mapping:
          expect = 'K'
  
      expect_size = std_size / rate_mapping[expect]
      return expect_size, expect
function_tokens: def capacity_convert ( size , expect = 'auto' , rate = 1000 ) : rate_mapping = ( ( 'K' , rate ) , ( 'KB' , rate ) , ( 'M' , rate ** 2 ) , ( 'MB' , rate ** 2 ) , ( 'G' , rate ** 3 ) , ( 'GB' , rate ** 3 ) , ( 'T' , rate ** 4 ) , ( 'TB' , rate ** 4 ) , ) rate_mapping = OrderedDict ( rate_mapping ) std_size = 0 # To KB for unit in rate_mapping : if size . endswith ( unit ) : try : std_size = float ( size . strip ( unit ) . strip ( ) ) * rate_mapping [ unit ] except ValueError : pass if expect == 'auto' : for unit , rate_ in rate_mapping . items ( ) : if rate > std_size / rate_ >= 1 or unit == "T" : expect = unit break if expect not in rate_mapping : expect = 'K' expect_size = std_size / rate_mapping [ expect ] return expect_size , expect