コード例 #1
0
ファイル: __init__.py プロジェクト: zeuskingzb/sentry
    def extra_data(cls, user, uid, response, details=None):
        """Return access_token and extra defined names to store in
        extra_data field"""
        data = {"access_token": response.get("access_token", "")}
        name = cls.name.replace("-", "_").upper()
        names = (cls.EXTRA_DATA or []) + setting(name + "_EXTRA_DATA", [])

        for entry in names:
            if isinstance(entry, six.string_types):
                entry = (entry,)

            try:
                if len(entry) == 3:
                    name, alias, discard = entry
                elif len(entry) == 2:
                    (name, alias), discard = entry, False
                elif len(entry) == 1:
                    (name,), (alias,), discard = entry, entry, False
                else:
                    raise ValueError("invalid tuple for EXTRA_DATA entry" % entry)

                value = response.get(name)
                if discard and not value:
                    continue
                data[alias] = value

            except (TypeError, ValueError):
                raise BackendError("invalid entry: %s" % (entry,))

        return data
コード例 #2
0
    def extra_data(cls, user, uid, response, details=None):
        """Return access_token and extra defined names to store in
        extra_data field"""
        data = {'access_token': response.get('access_token', '')}
        name = cls.name.replace('-', '_').upper()
        names = (cls.EXTRA_DATA or []) + setting(name + '_EXTRA_DATA', [])

        for entry in names:
            if type(entry) is str:
                entry = (entry, )

            try:
                if len(entry) == 3:
                    name, alias, discard = entry
                elif len(entry) == 2:
                    (name, alias), discard = entry, False
                elif len(entry) == 1:
                    (name, ), (alias, ), discard = entry, entry, False
                else:
                    raise ValueError('invalid tuple for EXTRA_DATA entry' %
                                     entry)

                value = response.get(name)
                if discard and not value:
                    continue
                data[alias] = value

            except (TypeError, ValueError):
                raise BackendError('invalid entry: %s' % (entry, ))

        return data