def _GetGroupMembersAndPermissions(self):
    """Returns a dict of users from settings.GROUPS with desired permissions.

    GROUPS is a dict of permission types, where each type contains a list of
    groups for that given type with a sequence of permissions members of that
    group should have. This function essentially expands the group membership
    and returns a dict of users and the various permissions they have as a
    result of being in one or more of the groups.

    Returns:
      dict like the following:
    {
      'user1@example.com': {'permission_type1': set(['read', 'write'])},
      'user2@example.com': {'permission_type1': set(['read', 'write'])},
      'user3@example.com': {'permission_type1': set(['read', 'write', 'list']),
                            'permission_type2': set(['read', 'write'])},
      }
    """
    group_users = {}

    # Loop over all permission types and all groups, expanding membership
    # and storing each group members permissions in a dict.
    for permission_type, groups in settings.GROUPS.iteritems():
      # Convert all permissions to sets to avoid duplicate permissions.
      groups = [(g, set(p)) for g, p in groups]

      for group, perms in groups:
        for user in self._GetGroupMembers(group):
          # To accomodate for users that exist in multiple groups, insert new
          # users with permissions and set or add permissions to existing users.
          if user not in group_users:
            group_users[user] = {permission_type: perms}
          elif permission_type not in group_users[user]:
            group_users[user][permission_type] = perms
          else:
            group_users[user][permission_type] = (
                group_users[user][permission_type].union(perms))
    return group_users

  # pylint: disable=g-bad-name
dataset/ETHPy150Open google/cauliflowervest/src/cauliflowervest/server/cron/group_sync.py/GroupSync._GetGroupMembersAndPermissions/original