def authenticator(function, challenges=()):
 challenges = (challenges or ('{} realm="simple"'.format(function.__name__),))
 def wrapper(verify_user):
  def authenticate(request, response, **kwargs):
   result = function(request, response, verify_user, **kwargs)
   if (result is None):
    raise HTTPUnauthorized('Authentication Required', 'Please provide valid {0} credentials'.format(function.__doc__.splitlines()[0]), challenges=challenges)
   if (result is False):
    raise HTTPUnauthorized('Invalid Authentication', 'Provided {0} credentials were invalid'.format(function.__doc__.splitlines()[0]), challenges=challenges)
   request.context['user'] = result
   return True
  authenticate.__doc__ = function.__doc__
  return authenticate
 return wrapper

def authenticator ( function , challenges = ( ) ) : challenges = ( challenges or ( '{} realm="simple"' . format ( function . __name__ ) , ) ) def wrapper ( verify_user ) : def authenticate ( request , response , ** kwargs ) : result = function ( request , response , verify_user , ** kwargs ) if ( result is None ) : raise HTTPUnauthorized ( 'Authentication Required' , 'Please provide valid {0} credentials' . format ( function . __doc__ . splitlines ( ) [ 0 ] ) , challenges = challenges ) if ( result is False ) : raise HTTPUnauthorized ( 'Invalid Authentication' , 'Provided {0} credentials were invalid' . format ( function . __doc__ . splitlines ( ) [ 0 ] ) , challenges = challenges ) request . context [ 'user' ] = result return True authenticate . __doc__ = function . __doc__ return authenticate return wrapper
wraps authentication logic .