def user_or_ip(key_prefix):
 def _user_or_ip(request):
  if (hasattr(request, 'user') and request.user.is_authenticated()):
   key = str(request.user.pk)
  else:
   key = request.META.get('HTTP_X_CLUSTER_CLIENT_IP', request.META['REMOTE_ADDR'])
  return ('uip:%s:%s' % (key_prefix, key))
 return _user_or_ip

def user_or_ip ( key_prefix ) : def _user_or_ip ( request ) : if ( hasattr ( request , 'user' ) and request . user . is_authenticated ( ) ) : key = str ( request . user . pk ) else : key = request . META . get ( 'HTTP_X_CLUSTER_CLIENT_IP' , request . META [ 'REMOTE_ADDR' ] ) return ( 'uip:%s:%s' % ( key_prefix , key ) ) return _user_or_ip
used for generating rate limiting keys .