#NEWLINE# def should_be_throttled( self , identifier , **kwargs ) : #NEWLINE# #INDENT# '\n        Returns whether or not the user has exceeded their throttle limit. If\n        throttled, can return either True, and int specifying the number of\n        seconds to wait, or a datetime object specifying when to retry the\n        request.\n\n        Maintains a list of timestamps when the user accessed the api within\n        the cache.\n\n        Returns ``False`` if the user should NOT be throttled or ``True`` if\n        the user should be throttled.\n        ' #NEWLINE# key = self . convert_identifier_to_key ( identifier ) #NEWLINE# now = int ( time . time ( ) ) #NEWLINE# timeframe = int ( self . timeframe ) #NEWLINE# throttle_at = int ( self . throttle_at ) #NEWLINE# minimum_time = ( now - timeframe ) #NEWLINE# times_accessed = [ access for access in cache . get ( key , [ ] ) if ( access >= minimum_time ) ] #NEWLINE# cache . set ( key , times_accessed , self . expiration ) #NEWLINE# if ( len ( times_accessed ) >= throttle_at ) : #NEWLINE# #INDENT# return ( timeframe - ( now - times_accessed [ ( - throttle_at ) ] ) ) #NEWLINE# #UNINDENT# return False