def _shrink_cache(cache_dict, args_dict, locale_sensitive, max_length, divisor=5):
 cache_keys = tuple(cache_dict.keys())
 overage = (len(cache_keys) - max_length)
 if (overage < 0):
  return
 number_to_toss = ((max_length // divisor) + overage)
 import random
 if (not hasattr(random, 'sample')):
  return
 for doomed_key in random.sample(cache_keys, number_to_toss):
  try:
   del cache_dict[doomed_key]
  except KeyError:
   pass
 args_dict.clear()
 sensitivity_dict = {}
 for (pattern, pattern_type, flags, args, default_version, locale) in tuple(cache_dict):
  args_dict[(pattern, pattern_type, flags, default_version, locale)] = args
  try:
   sensitivity_dict[(pattern_type, pattern)] = locale_sensitive[(pattern_type, pattern)]
  except KeyError:
   pass
 locale_sensitive.clear()
 locale_sensitive.update(sensitivity_dict)

def _shrink_cache ( cache_dict , args_dict , locale_sensitive , max_length , divisor = 5 ) : cache_keys = tuple ( cache_dict . keys ( ) ) overage = ( len ( cache_keys ) - max_length ) if ( overage < 0 ) : return number_to_toss = ( ( max_length // divisor ) + overage ) import random if ( not hasattr ( random , 'sample' ) ) : return for doomed_key in random . sample ( cache_keys , number_to_toss ) : try : del cache_dict [ doomed_key ] except KeyError : pass args_dict . clear ( ) sensitivity_dict = { } for ( pattern , pattern_type , flags , args , default_version , locale ) in tuple ( cache_dict ) : args_dict [ ( pattern , pattern_type , flags , default_version , locale ) ] = args try : sensitivity_dict [ ( pattern_type , pattern ) ] = locale_sensitive [ ( pattern_type , pattern ) ] except KeyError : pass locale_sensitive . clear ( ) locale_sensitive . update ( sensitivity_dict )
make room in the given cache .