MoinMoin/datastruct/backends/config_lazy_groups.py
author Thomas Waldmann <tw AT waldmann-edv DOT de>
Fri, 07 Aug 2009 10:58:53 +0200
changeset 4936 1c8da2f463ee
parent 4852 65bef5bcec41
permissions -rw-r--r--
merged moin/1.8
     1 # -*- coding: iso-8859-1 -*-
     2 """
     3     MoinMoin - config group lazy backend.
     4 
     5     The config group backend allows one to define groups in a
     6     configuration file.
     7 
     8     NOTE that this is proof-of-concept implementation. LDAP backend
     9     should be based on this concept.
    10 
    11     @copyright: 2009 MoinMoin:DmitrijsMilajevs
    12     @license: GPL, see COPYING for details
    13 """
    14 
    15 from MoinMoin.datastruct.backends import LazyGroup, LazyGroupsBackend
    16 
    17 
    18 class ConfigLazyGroup(LazyGroup):
    19     pass
    20 
    21 
    22 class ConfigLazyGroups(LazyGroupsBackend):
    23 
    24     def __init__(self, request, groups):
    25         super(ConfigLazyGroups, self).__init__(request)
    26 
    27         self._groups = groups
    28 
    29     def __contains__(self, group_name):
    30         return group_name in self._groups
    31 
    32     def __iter__(self):
    33         return self._groups.iterkeys()
    34 
    35     def __getitem__(self, group_name):
    36         return ConfigLazyGroup(self.request, group_name, self)
    37 
    38     def _iter_group_members(self, group_name):
    39         if group_name in self:
    40             return self._groups[group_name].__iter__()
    41 
    42     def _group_has_member(self, group_name, member):
    43         return group_name in self and member in self._groups[group_name]