Back to index

moin  1.9.0~rc2
config_groups.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003 MoinMoin - config groups backend
00004 
00005 The config_groups backend enables one to define groups and their
00006 members in a configuration file.
00007 
00008 @copyright: 2009 MoinMoin:DmitrijsMilajevs
00009 @license: GPL, see COPYING for details
00010 """
00011 
00012 from MoinMoin.datastruct.backends import GreedyGroup, BaseGroupsBackend, GroupDoesNotExistError
00013 
00014 
00015 class ConfigGroup(GreedyGroup):
00016     pass
00017 
00018 
00019 class ConfigGroups(BaseGroupsBackend):
00020 
00021     def __init__(self, request, groups):
00022         """
00023         @param groups: Dictionary of groups where key is group name,
00024         and value is list of members of that group.
00025         """
00026         super(ConfigGroups, self).__init__(request)
00027 
00028         self._groups = groups
00029 
00030     def __contains__(self, group_name):
00031         return group_name in self._groups
00032 
00033     def __iter__(self):
00034         return self._groups.iterkeys()
00035 
00036     def __getitem__(self, group_name):
00037         return ConfigGroup(request=self.request, name=group_name, backend=self)
00038 
00039     def _retrieve_members(self, group_name):
00040         try:
00041             return self._groups[group_name]
00042         except KeyError:
00043             raise GroupDoesNotExistError(group_name)
00044