1
# -*- coding: iso-8859-1 -*-
3
MoinMoin - group access via various backends.
5
The composite_groups is a backend that does not have direct storage,
6
but composes other backends to a new one, so group definitions are
7
retrieved from several backends. This allows to mix different
10
@copyright: 2009 DmitrijsMilajevs
11
@license: GPL, see COPYING for details
14
from MoinMoin.datastruct.backends import BaseGroupsBackend, GroupDoesNotExistError
17
class CompositeGroups(BaseGroupsBackend):
19
Manage several group backends.
22
def __init__(self, request, *backends):
24
@param backends: list of group backends which are used to get
25
access to the group definitions.
27
super(CompositeGroups, self).__init__(request)
28
self._backends = backends
30
def __getitem__(self, group_name):
32
Get a group by its name. First match counts.
34
for backend in self._backends:
36
return backend[group_name]
37
except GroupDoesNotExistError:
39
raise GroupDoesNotExistError(group_name)
43
Iterate over group names in all backends (filtering duplicates).
45
If a group with same name is defined in several backends, the
46
composite_groups backend yields only backend which is listed
47
earlier in self._backends.
49
yielded_groups = set()
51
for backend in self._backends:
52
for group_name in backend:
53
if group_name not in yielded_groups:
55
yielded_groups.add(group_name)
57
def __contains__(self, group_name):
59
Check if a group called group_name is available in any of the backends.
61
@param group_name: name of the group [unicode]
63
for backend in self._backends:
64
if group_name in backend:
69
return "<%s backends=%s>" % (self.__class__, self._backends)