~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/datastruct/backends/config_groups.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: iso-8859-1 -*-
2
 
"""
3
 
MoinMoin - config groups backend
4
 
 
5
 
The config_groups backend enables one to define groups and their
6
 
members in a configuration file.
7
 
 
8
 
@copyright: 2009 MoinMoin:DmitrijsMilajevs
9
 
@license: GPL, see COPYING for details
10
 
"""
11
 
 
12
 
from MoinMoin.datastruct.backends import GreedyGroup, BaseGroupsBackend, GroupDoesNotExistError
13
 
 
14
 
 
15
 
class ConfigGroup(GreedyGroup):
16
 
    pass
17
 
 
18
 
 
19
 
class ConfigGroups(BaseGroupsBackend):
20
 
 
21
 
    def __init__(self, request, groups):
22
 
        """
23
 
        @param groups: Dictionary of groups where key is group name,
24
 
        and value is list of members of that group.
25
 
        """
26
 
        super(ConfigGroups, self).__init__(request)
27
 
 
28
 
        self._groups = groups
29
 
 
30
 
    def __contains__(self, group_name):
31
 
        return group_name in self._groups
32
 
 
33
 
    def __iter__(self):
34
 
        return self._groups.iterkeys()
35
 
 
36
 
    def __getitem__(self, group_name):
37
 
        return ConfigGroup(request=self.request, name=group_name, backend=self)
38
 
 
39
 
    def _retrieve_members(self, group_name):
40
 
        try:
41
 
            return self._groups[group_name]
42
 
        except KeyError:
43
 
            raise GroupDoesNotExistError(group_name)
44