'Authenticates the user.
The authentication process works as follows:
1) We get a username and password from the user
2) We use ClientLogin to obtain an AUTH token for the user
(see http://code.google.com/apis/accounts/AuthForInstalledApps.html).
3) We pass the auth token to /_ah/login on the server to obtain an
authentication cookie. If login was successful, it tries to redirect
us to the URL we provided.
If we attempt to access the upload API without first obtaining an
authentication cookie, it returns a 401 response and directs us to
authenticate ourselves with ClientLogin.'

def _Authenticate(self):

    for unused_i in range(self.auth_tries):
        credentials = self.auth_function()
        try:
            auth_token = self._GetAuthToken(credentials[0], credentials[1])
            if (os.getenv('APPENGINE_RPC_USE_SID', '0') == '1'):
                return
        except ClientLoginError as e:
            if (e.reason == 'CaptchaRequired'):
                print >>sys.stderr, 'Please    go    to\nhttps://www.google.com/accounts/DisplayUnlockCaptcha\nand    verify    you    are    a    human.        Then    try    again.'
                break
            if (e.reason == 'NotVerified'):
                print >>sys.stderr, 'Account    not    verified.'
                break
            if (e.reason == 'TermsNotAgreed'):
                print >>sys.stderr, 'User    has    not    agreed    to    TOS.'
                break
            if (e.reason == 'AccountDeleted'):
                print >>sys.stderr, 'The    user    account    has    been    deleted.'
                break
            if (e.reason == 'AccountDisabled'):
                print >>sys.stderr, 'The    user    account    has    been    disabled.'
                break
            if (e.reason == 'ServiceDisabled'):
                print >>sys.stderr, "The    user's    access    to    the    service    has    been    disabled."
                break
            if (e.reason == 'ServiceUnavailable'):
                print >>sys.stderr, 'The    service    is    not    available;    try    again    later.'
                break
            raise
        self._GetAuthCookie(auth_token)
        return
