def _throttle(session, maxlim=None, timeout=None, storage=_LATEST_FAILED_LOGINS):
 address = session.address
 if isinstance(address, tuple):
  address = address[0]
 now = time.time()
 if (maxlim and timeout):
  latest_fails = storage[address]
  if (latest_fails and (len(latest_fails) >= maxlim)):
   if ((now - latest_fails[(-1)]) < timeout):
    return True
   else:
    storage[address] = []
    return False
 else:
  storage[address].append(time.time())
  return False

def _throttle ( session , maxlim = None , timeout = None , storage = _LATEST_FAILED_LOGINS ) : address = session . address if isinstance ( address , tuple ) : address = address [ 0 ] now = time . time ( ) if ( maxlim and timeout ) : latest_fails = storage [ address ] if ( latest_fails and ( len ( latest_fails ) >= maxlim ) ) : if ( ( now - latest_fails [ ( - 1 ) ] ) < timeout ) : return True else : storage [ address ] = [ ] return False else : storage [ address ] . append ( time . time ( ) ) return False
this will check the sessions address against the _latest_logins dictionary to check they havent spammed too many fails recently .