import functools


def authorized(method):
    """Decorate handler methods with this to require users to be authorized.
    Response status code 401 (Unauthorized) is sent for unauthorized users.
    """
    @functools.wraps(method)
    def wrapper(self, *args, **kwargs):
        if not self.current_user:
            self.send_error(401)
            return
        return method(self, *args, **kwargs)
    return wrapper