def interpret_conf_limits(conf, name_prefix, info=None):
 conf_limits = []
 for conf_key in conf:
  if conf_key.startswith(name_prefix):
   cont_size = int(conf_key[len(name_prefix):])
   rate = float(conf[conf_key])
   conf_limits.append((cont_size, rate))
 conf_limits.sort()
 ratelimits = []
 conf_limits_info = list(conf_limits)
 while conf_limits:
  (cur_size, cur_rate) = conf_limits.pop(0)
  if conf_limits:
   (next_size, next_rate) = conf_limits[0]
   slope = ((float(next_rate) - float(cur_rate)) / (next_size - cur_size))
   def new_scope(cur_size, slope, cur_rate):
    return (lambda x: (((x - cur_size) * slope) + cur_rate))
   line_func = new_scope(cur_size, slope, cur_rate)
  else:
   line_func = (lambda x: cur_rate)
  ratelimits.append((cur_size, cur_rate, line_func))
 if (info is None):
  return ratelimits
 else:
  return (ratelimits, conf_limits_info)

def interpret_conf_limits ( conf , name_prefix , info = None ) : conf_limits = [ ] for conf_key in conf : if conf_key . startswith ( name_prefix ) : cont_size = int ( conf_key [ len ( name_prefix ) : ] ) rate = float ( conf [ conf_key ] ) conf_limits . append ( ( cont_size , rate ) ) conf_limits . sort ( ) ratelimits = [ ] conf_limits_info = list ( conf_limits ) while conf_limits : ( cur_size , cur_rate ) = conf_limits . pop ( 0 ) if conf_limits : ( next_size , next_rate ) = conf_limits [ 0 ] slope = ( ( float ( next_rate ) - float ( cur_rate ) ) / ( next_size - cur_size ) ) def new_scope ( cur_size , slope , cur_rate ) : return ( lambda x : ( ( ( x - cur_size ) * slope ) + cur_rate ) ) line_func = new_scope ( cur_size , slope , cur_rate ) else : line_func = ( lambda x : cur_rate ) ratelimits . append ( ( cur_size , cur_rate , line_func ) ) if ( info is None ) : return ratelimits else : return ( ratelimits , conf_limits_info )
parses general parms for rate limits looking for things that start with the provided name_prefix within the provided conf and returns lists for both internal use and for /info .