human
Complete this python program:
def http_auth_required(realm):
assistant
#Here is the Python code you requested.

    """Decorator that protects endpoints using Basic HTTP authentication.
    The username should be set to the user\s email address.
    :param realm: optional realm name
    """
    def decorator(fn):
        @wraps(fn)
        def wrapper(*args, **kwargs):
            if _check_http_auth():
                return fn(*args, **kwargs)
            if _security._unauthorized_callback:
                return _security._unauthorized_callback()
            else:
                r = (_security.default_http_auth_realm if callable(realm) else realm)
                h = {'WWW-Authenticate': ('Basic    realm="%s"' % r)}
                return _get_unauthorized_response(headers=h)
        return wrapper
    if callable(realm):
        return decorator(realm)
    return decorator