<s> """<STR_LIT>""" <EOL> from django . utils . functional import wraps <EOL> from django . core . cache import cache <EOL> from middleware import thread_namespace <EOL> from exceptions import LockedOut <EOL> from utils import generate_base_key <EOL> import settings <EOL> def enforce_lockout ( function ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( * args , ** kwargs ) : <EOL> request = getattr ( thread_namespace , '<STR_LIT>' , None ) <EOL> if request is None : <EOL> return function ( * args , ** kwargs ) <EOL> params = [ ] <EOL> ip = request . META . get ( '<STR_LIT>' , None ) <EOL> if ip : <EOL> ip = ip . split ( '<STR_LIT:U+002CU+0020>' ) [ <NUM_LIT:0> ] <EOL> else : <EOL> ip = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> params . append ( ip ) <EOL> if settings . USE_USER_AGENT : <EOL> useragent = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> params . append ( useragent ) <EOL> key = generate_base_key ( * params ) <EOL> attempts = cache . get ( key ) or <NUM_LIT:0> <EOL> if attempts >= settings . MAX_ATTEMPTS : <EOL> raise LockedOut ( ) <EOL> result = function ( * args , ** kwargs ) <EOL> if result is None : <EOL> try : <EOL> attempts = cache . incr ( key ) <EOL> except ValueError : <EOL> cache . set ( key , <NUM_LIT:1> , settings . ENFORCEMENT_WINDOW ) <EOL> if attempts >= settings . MAX_ATTEMPTS : <EOL> cache . set ( key , attempts , settings . LOCKOUT_TIME ) <EOL> return result <EOL> return wraps ( function ) ( wrapper ) </s>
