当前位置: 首页>>代码示例>>Python>>正文


Python gmail.GmailAccount类代码示例

本文整理汇总了Python中inbox.models.backends.gmail.GmailAccount的典型用法代码示例。如果您正苦于以下问题:Python GmailAccount类的具体用法?Python GmailAccount怎么用?Python GmailAccount使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了GmailAccount类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_default_account

def make_default_account(db, config):
    import platform
    from inbox.models.backends.gmail import GmailAccount
    from inbox.models.backends.gmail import GmailAuthCredentials
    from inbox.auth.gmail import OAUTH_SCOPE
    from inbox.models import Namespace

    ns = Namespace()
    account = GmailAccount(
        sync_host='{}:{}'.format(platform.node(), 0),
        email_address='[email protected]')
    account.namespace = ns
    account.create_emailed_events_calendar()
    account.refresh_token = 'faketoken'

    auth_creds = GmailAuthCredentials()
    auth_creds.client_id = config.get_required('GOOGLE_OAUTH_CLIENT_ID')
    auth_creds.client_secret = \
        config.get_required('GOOGLE_OAUTH_CLIENT_SECRET')
    auth_creds.refresh_token = 'faketoken'
    auth_creds.g_id_token = 'foo'
    auth_creds.created_at = datetime.utcnow()
    auth_creds.updated_at = datetime.utcnow()
    auth_creds.gmailaccount = account
    auth_creds.scopes = OAUTH_SCOPE

    db.session.add(account)
    db.session.add(auth_creds)
    db.session.commit()
    return account
开发者ID:gisho,项目名称:sync-engine,代码行数:30,代码来源:base.py

示例2: create_account

 def create_account(self, email_address, response):
     # This method assumes that the existence of an account for the
     # provider and email_address has been checked by the caller;
     # callers may have different methods of performing the check
     # (redwood auth versus bin/inbox-auth)
     namespace = Namespace()
     account = GmailAccount(namespace=namespace)
     account.create_emailed_events_calendar()
     return self.update_account(account, response)
开发者ID:aabde,项目名称:sync-engine,代码行数:9,代码来源:gmail.py

示例3: add_fake_gmail_account

def add_fake_gmail_account(
    db_session, email_address="[email protected]", refresh_token="tearsofgold", password="COyPtHmj9E9bvGdN"
):
    from inbox.models import Namespace
    from inbox.models.backends.gmail import GmailAccount
    import platform

    with db_session.no_autoflush:
        namespace = Namespace()

        account = GmailAccount(
            email_address=email_address, refresh_token=refresh_token, sync_host=platform.node(), namespace=namespace
        )
        account.password = password

        db_session.add(account)
        db_session.commit()
        return account
开发者ID:nohobby,项目名称:sync-engine,代码行数:18,代码来源:base.py

示例4: gmail_account

def gmail_account(db):
    import platform
    from inbox.models import Namespace
    from inbox.models.backends.gmail import GmailAccount

    account = db.session.query(GmailAccount).first()
    if account is None:
        with db.session.no_autoflush:
            namespace = Namespace()
            account = GmailAccount(
                email_address='[email protected]',
                refresh_token='tearsofgold',
                sync_host=platform.node(),
                namespace=namespace)
            account.password = 'COyPtHmj9E9bvGdN'
            db.session.add(account)
    db.session.commit()

    return account
开发者ID:steffenmllr,项目名称:sync-engine,代码行数:19,代码来源:base.py

示例5: create_account

    def create_account(self, db_session, email_address, response):
        # Override create_account to persist the 'login hint' email_address
        # rather than the canonical email that is contained in response.
        # This allows us to trigger errors by authing with addresses of the
        # format:
        #    [email protected]

        # Since verify_config throws an Exception if no specific case is
        # triggered, this account is never committed.
        namespace = Namespace()
        account = GmailAccount(namespace=namespace)
        account.email_address = email_address

        try:
            self.verify_config(account)
        except GmailSettingError as e:
            print e
            raise UserRecoverableConfigError(e)

        return account
开发者ID:rf-,项目名称:sync-engine,代码行数:20,代码来源:mock_gmail.py

示例6: default_account

def default_account(db):
    import platform
    from inbox.models.backends.gmail import GmailAccount
    from inbox.models import Namespace, Folder
    ns = Namespace()
    account = GmailAccount(
        sync_host=platform.node(),
        email_address='[email protected]')
    account.namespace = ns
    account.create_emailed_events_calendar()
    account.refresh_token = 'faketoken'
    account.inbox_folder = Folder(canonical_name='inbox', name='Inbox',
                                  account=account)
    account.sent_folder = Folder(canonical_name='sent', name='[Gmail]/Sent',
                                 account=account)
    account.drafts_folder = Folder(canonical_name='drafts',
                                   name='[Gmail]/Drafts',
                                   account=account)
    db.session.add(account)
    db.session.commit()
    return account
开发者ID:raghuveerkancherla,项目名称:sync-engine,代码行数:21,代码来源:base.py

示例7: create_account

    def create_account(self, db_session, email_address, response):
        email_address = response.get('email')
        # See if the account exists in db, otherwise create it
        try:
            account = db_session.query(GmailAccount) \
                .filter_by(email_address=email_address).one()
        except NoResultFound:
            namespace = Namespace()
            account = GmailAccount(namespace=namespace)

        # We only get refresh tokens on initial login (or failed credentials)
        # otherwise, we don't force the login screen and therefore don't get a
        # refresh token back from google.
        new_refresh_token = response.get('refresh_token')
        if new_refresh_token:
            account.refresh_token = new_refresh_token
        else:
            if not account.refresh_token or account.sync_state == 'invalid':
                # We got a new auth without a refresh token, so we need to back
                # out and force the auth flow, since we don't already have
                # a refresh (or the one we have doesn't work.)
                raise OAuthError("Missing refresh token")

        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.family_name = response.get('family_name')
        account.given_name = response.get('given_name')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.g_id = response.get('id')
        account.g_user_id = response.get('user_id')
        account.g_id_token = response.get('id_token')
        account.link = response.get('link')
        account.locale = response.get('locale')
        account.picture = response.get('picture')
        account.home_domain = response.get('hd')
        account.client_id = response.get('client_id')
        account.client_secret = response.get('client_secret')
        account.sync_contacts = response.get('contacts', True)
        account.sync_events = response.get('events', True)

        try:
            self.verify_config(account)
        except GmailSettingError as e:
            raise UserRecoverableConfigError(e)

        # Hack to ensure that account syncs get restarted if they were stopped
        # because of e.g. invalid credentials and the user re-auths.
        # TODO(emfree): remove after status overhaul.
        if account.sync_state != 'running':
            account.sync_state = None

        return account
开发者ID:apolmig,项目名称:inbox,代码行数:56,代码来源:gmail.py

示例8: create_account

    def create_account(self, db_session, email_address, response):
        email_address = response.get('email')
        # See if the account exists in db, otherwise create it
        try:
            account = db_session.query(GmailAccount) \
                .filter_by(email_address=email_address).one()
        except NoResultFound:
            namespace = Namespace()
            account = GmailAccount(namespace=namespace)

        # We only get refresh tokens on initial login (or failed credentials)
        # otherwise, we don't force the login screen and therefore don't get a
        # refresh token back from google.
        new_refresh_token = response.get('refresh_token')
        if new_refresh_token:
            account.refresh_token = new_refresh_token
        else:
            if (len(account.valid_auth_credentials) == 0 or
                    account.sync_state == 'invalid'):
                # We got a new auth without a refresh token, so we need to back
                # out and force the auth flow, since we don't already have
                # a refresh (or the ones we have don't work.)
                raise OAuthError("No valid refresh tokens")

        account.email_address = email_address
        account.family_name = response.get('family_name')
        account.given_name = response.get('given_name')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.g_id = response.get('id')
        account.g_user_id = response.get('user_id')
        account.link = response.get('link')
        account.locale = response.get('locale')
        account.picture = response.get('picture')
        account.home_domain = response.get('hd')
        account.sync_email = (account.sync_email or
                              response.get('sync_email', True))
        account.sync_contacts = (account.sync_contacts or
                                 response.get('contacts', True))
        account.sync_events = (account.sync_events or
                               response.get('events', True))

        # These values are deprecated and should not be used, along
        # with the account's refresh_token. Access all these values
        # through the GmailAuthCredentials objects instead.
        account.client_id = response.get('client_id')
        account.client_secret = response.get('client_secret')
        account.scope = response.get('scope')
        account.g_id_token = response.get('id_token')

        # Don't need to actually save these now
        # tok = response.get('access_token')
        # expires_in = response.get('expires_in')

        client_id = response.get('client_id') or OAUTH_CLIENT_ID
        client_secret = response.get('client_secret') or OAUTH_CLIENT_SECRET

        if new_refresh_token:
            # See if we already have credentials for this client_id/secret
            # pair. If those don't exist, make a new GmailAuthCredentials
            auth_creds = next(
                (auth_creds for auth_creds in account.auth_credentials
                 if (auth_creds.client_id == client_id and
                     auth_creds.client_secret == client_secret)),
                GmailAuthCredentials())

            auth_creds.gmailaccount = account
            auth_creds.scopes = response.get('scope')
            auth_creds.g_id_token = response.get('id_token')
            auth_creds.client_id = client_id
            auth_creds.client_secret = client_secret
            auth_creds.refresh_token = new_refresh_token
            auth_creds.is_valid = True

        try:
            self.verify_config(account)
        except ImapSupportDisabledError:
            if account.sync_email:
                raise

        # Ensure account has sync enabled.
        account.enable_sync()

        return account
开发者ID:rf-,项目名称:sync-engine,代码行数:84,代码来源:gmail.py

示例9: create_account

    def create_account(self, db_session, email_address, response):
        email_address = response.get('email')
        # See if the account exists in db, otherwise create it
        try:
            account = db_session.query(GmailAccount) \
                .filter_by(email_address=email_address).one()
        except NoResultFound:
            namespace = Namespace()
            account = GmailAccount(namespace=namespace)

        # We only get refresh tokens on initial login (or failed credentials)
        # otherwise, we don't force the login screen and therefore don't get a
        # refresh token back from google.
        new_refresh_token = response.get('refresh_token')
        if new_refresh_token:
            account.refresh_token = new_refresh_token
        else:
            if not account.refresh_token or account.sync_state == 'invalid':
                # We got a new auth without a refresh token, so we need to back
                # out and force the auth flow, since we don't already have
                # a refresh (or the one we have doesn't work.)
                raise OAuthError("Missing refresh token")

        tok = response.get('access_token')
        expires_in = response.get('expires_in')
        token_manager.cache_token(account, tok, expires_in)
        account.scope = response.get('scope')
        account.email_address = email_address
        account.family_name = response.get('family_name')
        account.given_name = response.get('given_name')
        account.name = response.get('name')
        account.gender = response.get('gender')
        account.g_id = response.get('id')
        account.g_user_id = response.get('user_id')
        account.g_id_token = response.get('id_token')
        account.link = response.get('link')
        account.locale = response.get('locale')
        account.picture = response.get('picture')
        account.home_domain = response.get('hd')
        account.client_id = response.get('client_id')
        account.client_secret = response.get('client_secret')
        account.sync_contacts = response.get('contacts', True)
        account.sync_events = response.get('events', True)

        try:
            self.verify_config(account)
        except GmailSettingError as e:
            raise UserRecoverableConfigError(e)

        # Ensure account has sync enabled.
        account.enable_sync()

        # See if we've already stored this refresh token
        match = [auth_creds for auth_creds in account.auth_credentials
                 if auth_creds.refresh_token == new_refresh_token]

        # For new refresh_tokens, create new GmailAuthCredentials entry
        if new_refresh_token and len(match) == 0:
            auth_creds = GmailAuthCredentials()
            auth_creds.gmailaccount = account
            auth_creds.scopes = response.get('scope')
            auth_creds.g_id_token = response.get('id_token')
            auth_creds.client_id = response.get('client_id')
            auth_creds.client_secret = response.get('client_secret')
            auth_creds.refresh_token = new_refresh_token

        return account
开发者ID:raghuveerkancherla,项目名称:sync-engine,代码行数:67,代码来源:gmail.py

示例10: create_account

def create_account(db_session, email_address, response):
    # See if the account exists in db, otherwise create it
    try:
        account = db_session.query(GmailAccount) \
            .filter_by(email_address=email_address).one()
    except NoResultFound:
        namespace = Namespace()
        account = GmailAccount(namespace=namespace)

    tok = response.get('access_token')
    expires_in = response.get('expires_in')
    account.set_access_token(tok, expires_in)
    account.refresh_token = response.get('refresh_token')
    account.scope = response.get('scope')
    account.email_address = response.get('email')
    account.family_name = response.get('family_name')
    account.given_name = response.get('given_name')
    account.name = response.get('name')
    account.gender = response.get('gender')
    account.g_id = response.get('id')
    account.g_user_id = response.get('user_id')
    account.g_id_token = response.get('id_token')
    account.link = response.get('link')
    account.locale = response.get('locale')
    account.picture = response.get('picture')
    account.home_domain = response.get('hd')
    account.client_id = response.get('client_id')
    account.client_secret = response.get('client_secret')

    return account
开发者ID:chengjunjian,项目名称:inbox,代码行数:30,代码来源:gmail.py

示例11: create_account

def create_account(db_session, response):
    email_address = response.get('email')
    # See if the account exists in db, otherwise create it
    try:
        account = db_session.query(GmailAccount) \
            .filter_by(email_address=email_address).one()
    except NoResultFound:
        namespace = Namespace()
        account = GmailAccount(namespace=namespace)

    # We only get refresh tokens on initial login (or failed credentials)
    # otherwise, we don't force the login screen and therefore don't get a
    # refresh token back from google.
    new_refresh_token = response.get('refresh_token')
    if new_refresh_token:
        account.refresh_token = new_refresh_token

    tok = response.get('access_token')
    expires_in = response.get('expires_in')
    account.set_access_token(tok, expires_in)
    account.scope = response.get('scope')
    account.email_address = email_address
    account.family_name = response.get('family_name')
    account.given_name = response.get('given_name')
    account.name = response.get('name')
    account.gender = response.get('gender')
    account.g_id = response.get('id')
    account.g_user_id = response.get('user_id')
    account.g_id_token = response.get('id_token')
    account.link = response.get('link')
    account.locale = response.get('locale')
    account.picture = response.get('picture')
    account.home_domain = response.get('hd')
    account.client_id = response.get('client_id')
    account.client_secret = response.get('client_secret')

    return account
开发者ID:Dracophoenix1,项目名称:inbox,代码行数:37,代码来源:gmail.py


注:本文中的inbox.models.backends.gmail.GmailAccount类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。