Decorator for key authentication

def key_required(group=None, perm=None, keytype=None):
    """
    Decorator for key authentication
    """
    def decorator(f):
        def wrapper(request, *args, **kwargs):
            try:
                validate_key( request, group, perm, keytype )
                return f(request, *args, **kwargs)
            except AccessUnauthorized:
                return HttpResponse401( request )
            except AccessForbidden:
                return HttpResponse403( request )
        return wrapper 
    return decorator