def _connect_oauth(self, username):
        # username should be an email address that has already been authorized
        # for gmail access
        try:
            from django_mailbox.google_utils import (
                get_google_access_token,
                fetch_user_info,
                AccessTokenNotFound,
            )
        except __HOLE__:
            raise ValueError(
                "Install python-social-auth to use oauth2 auth for gmail"
            )

        access_token = None
        while access_token is None:
            try:
                access_token = get_google_access_token(username)
                google_email_address = fetch_user_info(username)['email']
            except TypeError:
                # This means that the google process took too long
                # Trying again is the right thing to do
                pass
            except AccessTokenNotFound:
                raise ValueError(
                    "No Token available in python-social-auth for %s" % (
                        username
                    )
                )

        auth_string = 'user=%s\1auth=Bearer %s\1\1' % (
            google_email_address,
            access_token
        )
        self.server = self.transport(self.hostname, self.port)
        self.server.authenticate('XOAUTH2', lambda x: auth_string)
        self.server.select()
dataset/ETHPy150Open coddingtonbear/django-mailbox/django_mailbox/transports/gmail.py/GmailImapTransport._connect_oauth