moin-2.0 / build / lib / MoinMoin / datastruct / backends /

# Copyright: 2009 MoinMoin:DmitrijsMilajevs
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

MoinMoin - config groups backend

The config_groups backend enables one to define groups and their
members in a configuration file.

from MoinMoin.datastruct.backends import GreedyGroup, BaseGroupsBackend, GroupDoesNotExistError

class ConfigGroup(GreedyGroup):

class ConfigGroups(BaseGroupsBackend):

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

        self._groups = groups

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

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

    def __getitem__(self, group_name):
        return ConfigGroup(name=group_name, backend=self)

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