Mercurial > moin > 1.9
annotate MoinMoin/groups/backends/__init__.py @ 4813:8ce584105581
Groups2009: BaseGroup._load_group is shortened by using difference.
author  Dmitrijs Milajevs <dimazest@gmail.com> 

date  Thu, 18 Jun 2009 15:09:54 +0200 
parents  3c0ce322472a 
children  7d8f51be2285 
rev  line source 

4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

1 # * coding: iso88591 * 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

2 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

3 MoinMoin  base classes for group backends. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

4 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

5 @copyright: 2009 MoinMoin:DmitrijsMilajevs 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

6 @license: GPL, see COPYING for details 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

7 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

8 
4803
167db6117bb4
Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4800
diff
changeset

9 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

10 class BaseGroup(object): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

11 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

12 def __init__(self, request, name, backend): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

13 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

14 Initialize a group. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

15 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

16 @param request 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

17 @param name: moin group name 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

18 @backend: backend object which created this object 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

19 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

20 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

21 self.request = request 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

22 self.name = name 
4799
fde7471cb2a3
Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4798
diff
changeset

23 self._backend = backend 
4809
415338464695
Groups2009: Group._load_group() returns members and member_groups. Minor code refinements.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4807
diff
changeset

24 self.members, self.member_groups = self._load_group() 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

25 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

26 def _load_group(self): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

27 """ 
4813
8ce584105581
Groups2009: BaseGroup._load_group is shortened by using difference.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4810
diff
changeset

28 Retrieve group data from the backend and filter it to members and group_members. 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

29 """ 
4813
8ce584105581
Groups2009: BaseGroup._load_group is shortened by using difference.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4810
diff
changeset

30 members_retrieved = set(self._backend._retrieve_members(self.name)) 
4807
ca8fcf330aa8
Groups2009: Backend's _retrieve_members and is_group methods were introduced. _load_group became method of a BaseGroup to avoid code repetition. Test for empty group was added.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4806
diff
changeset

31 
4813
8ce584105581
Groups2009: BaseGroup._load_group is shortened by using difference.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4810
diff
changeset

32 member_groups = set(member for member in members_retrieved if self._backend.is_group(member)) 
8ce584105581
Groups2009: BaseGroup._load_group is shortened by using difference.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4810
diff
changeset

33 members = members_retrieved  member_groups 
4807
ca8fcf330aa8
Groups2009: Backend's _retrieve_members and is_group methods were introduced. _load_group became method of a BaseGroup to avoid code repetition. Test for empty group was added.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4806
diff
changeset

34 
4813
8ce584105581
Groups2009: BaseGroup._load_group is shortened by using difference.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4810
diff
changeset

35 return members, member_groups 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

36 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

37 def _contains(self, member, processed_groups): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

38 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

39 First check if <member> is part of this group and then check 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

40 for every subgroup in this group. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

41 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

42 <processed_groups> is needed to avoid infinite recursion, if 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

43 groups are defined recursively. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

44 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

45 @param member: member name [unicode] 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

46 @param processed_groups: groups which were checked for containment before [set] 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

47 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

48 processed_groups.add(self.name) 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

49 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

50 if member in self.members: 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

51 return True 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

52 else: 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

53 groups = self.request.groups 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

54 for group_name in self.member_groups: 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

55 if group_name not in processed_groups and groups[group_name]._contains(member, processed_groups): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

56 return True 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

57 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

58 return False 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

59 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

60 def __contains__(self, member): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

61 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

62 Check if <member> is defined in this group. Checks also for subgroups. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

63 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

64 return self._contains(member, set()) 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

65 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

66 def _iter(self, yielded_members, processed_groups): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

67 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

68 Iterate first over members of this group, then over subgroups of this group. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

69 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

70 <yielded_members> and <processed_groups> are needed to avoid infinite recursion. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

71 This can happen if there are two groups like these: 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

72 OneGroup: Something, OtherGroup 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

73 OtherGroup: OneGroup, SomethingOther 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

74 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

75 @param yielded_members: members which have been already yielded before [set] 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

76 @param processed_groups: group names which have been iterated before [set] 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

77 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

78 processed_groups.add(self.name) 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

79 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

80 for member in self.members: 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

81 if member not in yielded_members: 
4803
167db6117bb4
Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4800
diff
changeset

82 yielded_members.add(member) 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

83 yield member 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

84 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

85 groups = self.request.groups 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

86 for group_name in self.member_groups: 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

87 if group_name not in processed_groups: 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

88 for member in groups[group_name]._iter(yielded_members, processed_groups): 
4803
167db6117bb4
Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4800
diff
changeset

89 yield member 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

90 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

91 def __iter__(self): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

92 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

93 Iterate over members of this group. Iterates also over subgroups if any. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

94 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

95 return self._iter(set(), set()) 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

96 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

97 def __repr__(self): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

98 return "<%s name=%s members=%s member_groups=%s>" % (self.__class__, 
4809
415338464695
Groups2009: Group._load_group() returns members and member_groups. Minor code refinements.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4807
diff
changeset

99 self.name, 
415338464695
Groups2009: Group._load_group() returns members and member_groups. Minor code refinements.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4807
diff
changeset

100 self.members, 
415338464695
Groups2009: Group._load_group() returns members and member_groups. Minor code refinements.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4807
diff
changeset

101 self.member_groups) 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

102 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

103 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

104 class BaseBackend(object): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

105 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

106 def __init__(self, request): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

107 self.request = request 
4799
fde7471cb2a3
Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4798
diff
changeset

108 self.page_group_regex = request.cfg.cache.page_group_regexact 
fde7471cb2a3
Groups2009: The config_group backend initial commit. By default, config groups are defined in config_groups in the config file.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4798
diff
changeset

109 
4807
ca8fcf330aa8
Groups2009: Backend's _retrieve_members and is_group methods were introduced. _load_group became method of a BaseGroup to avoid code repetition. Test for empty group was added.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4806
diff
changeset

110 def is_group(self, member): 
ca8fcf330aa8
Groups2009: Backend's _retrieve_members and is_group methods were introduced. _load_group became method of a BaseGroup to avoid code repetition. Test for empty group was added.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4806
diff
changeset

111 return self.page_group_regex.match(member) 
ca8fcf330aa8
Groups2009: Backend's _retrieve_members and is_group methods were introduced. _load_group became method of a BaseGroup to avoid code repetition. Test for empty group was added.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4806
diff
changeset

112 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

113 def __contains__(self, group_name): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

114 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

115 Check if a group called <group_name> is available in this backend. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

116 """ 
4797
4539a7956eac
Groups2009: BaseBackend _exists_group, _get_group and _get_group_names methods were removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4796
diff
changeset

117 raise NotImplementedError() 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

118 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

119 def __iter__(self): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

120 """ 
4797
4539a7956eac
Groups2009: BaseBackend _exists_group, _get_group and _get_group_names methods were removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4796
diff
changeset

121 Iterate over moin group names of the groups defined in this backend. 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

122 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

123 @return: moin group names 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

124 """ 
4797
4539a7956eac
Groups2009: BaseBackend _exists_group, _get_group and _get_group_names methods were removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4796
diff
changeset

125 raise NotImplementedError() 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

126 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

127 def __getitem__(self, group_name): 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

128 """ 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

129 Get a group by its moin group name. 
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

130 """ 
4797
4539a7956eac
Groups2009: BaseBackend _exists_group, _get_group and _get_group_names methods were removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4796
diff
changeset

131 raise NotImplementedError() 
4796
7dd5d15de911
Groups2009: BaseGroup and BaseBackend initial import. wiki_group.Group and wiki_group.Backend inherit from those classes. TestWikiGroupNameMapping is added to check group name mapping routines.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4776
diff
changeset

132 
4798
ed977dd981ce
Groups2009: repr for GroupManager and BaseBackend.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4797
diff
changeset

133 def __repr__(self): 
4803
167db6117bb4
Groups2009: pep8 fixes and typo elimination. BaseGroup._iter optimization. Test of group names mapping was removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4800
diff
changeset

134 return "<%s groups=%s>" % (self.__class__, [b for b in self]) 
4798
ed977dd981ce
Groups2009: repr for GroupManager and BaseBackend.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4797
diff
changeset

135 
4807
ca8fcf330aa8
Groups2009: Backend's _retrieve_members and is_group methods were introduced. _load_group became method of a BaseGroup to avoid code repetition. Test for empty group was added.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4806
diff
changeset

136 def _retrieve_members(self, group_name): 
ca8fcf330aa8
Groups2009: Backend's _retrieve_members and is_group methods were introduced. _load_group became method of a BaseGroup to avoid code repetition. Test for empty group was added.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4806
diff
changeset

137 raise NotImplementedError() 
ca8fcf330aa8
Groups2009: Backend's _retrieve_members and is_group methods were introduced. _load_group became method of a BaseGroup to avoid code repetition. Test for empty group was added.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4806
diff
changeset

138 
4810
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

139 def groups_with_member(self, member): 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

140 """ 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

141 List all group names of groups containing <member>. 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

142 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

143 @param member: member name [unicode] 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

144 @return: list of group names [unicode] 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

145 """ 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

146 for group_name in self: 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

147 try: 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

148 if member in self[group_name]: 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

149 yield group_name 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

150 except KeyError: 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

151 pass 
3c0ce322472a
Groups2009: BaseBackend.groups_with_member() method was added. Test.GroupManager.test_membergroups() removed.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4809
diff
changeset

152 