view MoinMoin/groups/backends/config_groups.py @ 4818:66b7c4fe0265

Groups2009: Right exception handling for a group retrieval from the config_groups backend. If group does not exist GroupDoesNotExistError is raised. Test for acl added where in the acl definition not existing group is used.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Wed, 24 Jun 2009 20:03:29 +0200
parents 7d8f51be2285
children
line wrap: on
line source
# -*- coding: iso-8859-1 -*-
"""
MoinMoin - config group backend

The config group backend enables you to define groups in a configuration file.

@copyright: 2009 MoinMoin:DmitrijsMilajevs
@license: GPL, see COPYING for details
"""

from MoinMoin.groups.backends import BaseGroup, BaseBackend, GroupDoesNotExistError


class Group(BaseGroup):
    pass


class ConfigGroups(BaseBackend):

    def __init__(self, request, groups):
        """
        @param groups: Dictionary of groups where key is group name,
        and value is list of members of that group.
        """
        super(ConfigGroups, self).__init__(request)

        self._groups = groups

    def __contains__(self, group_name):
        return self.page_group_regex.match(group_name) and group_name in self._groups

    def __iter__(self):
        return self._groups.iterkeys()

    def __getitem__(self, group_name):
        return Group(request=self.request, name=group_name, backend=self)

    def _retrieve_members(self, group_name):
        try:
            return self._groups[group_name]
        except KeyError:
            raise GroupDoesNotExistError(group_name)