human
Complete this python program:
def authenticated(allow_prospective=False):
assistant
#Here is the Python code you requested.

    """Wrap request handler methods with this decorator to require that the user be logged in.
    Raises an HTTP 401 error if not.
    This method is exactly the same as tornado.web.authenticated, except that 401 is raised
    instead of 403. This is important, because the clients will re-authenticate only if they
    receive a 401.
    If allow_prospective=False, then prospective user cookies are not authorized access.
    WARNING: Before changing allow_prospective to True, make certain to think through the
    permissions that a prospective user should have for that particular handler.
    """
    def _authenticated(method):
        @functools.wraps(method)
        def wrapper(self, *args, **kwargs):
            if (not self.current_user):
                if (self.request.method in ('GET', 'HEAD')):
                    url = self.get_login_url()
                    if ('?' not in url):
                        if urlparse.urlsplit(url).scheme:
                            next_url = self.request.full_url()
                        else:
                            next_url = self.request.uri
                        url += ('?' + urllib.urlencode(dict(next=next_url)))
                    self.redirect(url)
                    return
                raise web.HTTPError(401, 'You    are    not    logged    in.    Only    users    that    have    logged    in    can    access    this    page.')
            elif (isinstance(self.current_user, User) and (not allow_prospective) and (not self.current_user.IsRegistered())):
                raise web.HTTPError(403, 'You    are    not    a    registered    user.    Sign    up    for    Viewfinder    to    gain    access    to    this    page.')
            return method(self, *args, **kwargs)
        return wrapper
    return _authenticated