Mercurial > moin > 1.9
annotate MoinMoin/datastruct/backends/__init__.py @ 4832:f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
author  Dmitrijs Milajevs <dimazest@gmail.com> 

date  Fri, 03 Jul 2009 16:36:47 +0100 
parents  MoinMoin/datastruct/groups/backends/__init__.py@069aac5ce3e4 
children  50732c861ac2 
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 """ 
4832
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

3 MoinMoin  base classes for datastruct backends. 
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

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 
4817
9a305dadab7a
Groups2009: pep8 fixes. Minor code refinements.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4816
diff
changeset

9 
4816
7d8f51be2285
Groups2009: GroupDoesNotExistError is raised instead of KeyError when a group name is not found in the backend.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4813
diff
changeset

10 class GroupDoesNotExistError(Exception): 
7d8f51be2285
Groups2009: GroupDoesNotExistError is raised instead of KeyError when a group name is not found in the backend.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4813
diff
changeset

11 """ 
7d8f51be2285
Groups2009: GroupDoesNotExistError is raised instead of KeyError when a group name is not found in the backend.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4813
diff
changeset

12 Raised when a group name is not found in the backend. 
7d8f51be2285
Groups2009: GroupDoesNotExistError is raised instead of KeyError when a group name is not found in the backend.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4813
diff
changeset

13 """ 
4817
9a305dadab7a
Groups2009: pep8 fixes. Minor code refinements.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4816
diff
changeset

14 
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

15 
4832
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

16 class DictDoesNotExistError(Exception): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

17 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

18 Raised when a dict name is not found in the backend. 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

19 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

20 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

21 
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

22 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

23 
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

24 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

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 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

27 
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

28 @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

29 @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

30 @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

31 
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

32 """ 
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

33 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

34 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

35 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

36 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

37 
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 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

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

40 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

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

42 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

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

44 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

45 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

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

47 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

48 
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 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

50 """ 
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 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

52 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

53 
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 <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

55 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

56 
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 @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

58 @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

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 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

61 
4820
17e9325712b3
Groups2009: Group __contains__ also checks if a group contains another group.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4817
diff
changeset

62 if member in self.members or member in 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

63 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

64 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

65 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

66 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

67 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

68 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

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 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

71 
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 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

73 """ 
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 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

75 """ 
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 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

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 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

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 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

81 
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

82 <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

83 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

84 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

85 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

86 
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 @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

88 @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

89 """ 
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 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

91 
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 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

93 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

94 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

95 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

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 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

98 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

99 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

100 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

101 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

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 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

104 """ 
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 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

106 """ 
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 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

108 
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

109 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

110 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

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

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

113 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

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 
4832
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

116 class BaseGroupBackend(object): 
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

117 
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 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

119 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

120 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

121 
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

122 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

123 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

124 
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

125 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

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 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

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

129 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

130 
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

131 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

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

133 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

134 
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

135 @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

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

137 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

138 
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

139 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

140 """ 
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

141 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

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

143 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

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

145 def __repr__(self): 
4817
9a305dadab7a
Groups2009: pep8 fixes. Minor code refinements.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4816
diff
changeset

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

147 
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

148 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

149 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

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

151 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

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

153 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

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

155 @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

156 @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

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

158 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

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

160 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

161 yield group_name 
4816
7d8f51be2285
Groups2009: GroupDoesNotExistError is raised instead of KeyError when a group name is not found in the backend.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4813
diff
changeset

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

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

164 
4827
fd6183cde452
Groups2009: groups.backends.BaseBackend now has get method, which works similar to dict.get().
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4820
diff
changeset

165 def get(self, key, default=None): 
fd6183cde452
Groups2009: groups.backends.BaseBackend now has get method, which works similar to dict.get().
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4820
diff
changeset

166 if key in self: 
fd6183cde452
Groups2009: groups.backends.BaseBackend now has get method, which works similar to dict.get().
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4820
diff
changeset

167 return self[key] 
fd6183cde452
Groups2009: groups.backends.BaseBackend now has get method, which works similar to dict.get().
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4820
diff
changeset

168 else: 
fd6183cde452
Groups2009: groups.backends.BaseBackend now has get method, which works similar to dict.get().
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4820
diff
changeset

169 return default 
fd6183cde452
Groups2009: groups.backends.BaseBackend now has get method, which works similar to dict.get().
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4820
diff
changeset

170 
4832
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

171 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

172 class BaseDict(object): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

173 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

174 def __init__(self, request, name, backend): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

175 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

176 Initialize a dict. 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

177 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

178 @param request 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

179 @param name: moin dict name 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

180 @backend: backend object which created this object 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

181 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

182 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

183 self.request = request 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

184 self.name = name 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

185 self._backend = backend 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

186 self._dict = self._load_dict() 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

187 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

188 def __iter__(self): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

189 return self._dict.__iter__() 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

190 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

191 def __len__(self): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

192 return self._dict.__len__() 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

193 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

194 def __getitem__(self, key): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

195 return self._dict[key] 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

196 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

197 def get(self, key, default=None): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

198 return self._dict.get(key, default) 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

199 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

200 def _load_dict(self): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

201 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

202 Retrieve dict data from the backend. 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

203 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

204 return self._backend._retrieve_members(self.name) 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

205 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

206 def __repr__(self): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

207 return "<%r name=%r items=%r>" % (self.__class__, self.name, self._dict.items()) 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

208 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

209 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

210 class BaseDictBackend(object): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

211 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

212 def __init__(self, request): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

213 self.request = request 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

214 self.page_dict_regex = request.cfg.cache.page_dict_regexact 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

215 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

216 def is_dict_name(self, name): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

217 return self.page_dict_regex.match(name) 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

218 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

219 def __contains__(self, dict_name): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

220 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

221 Check if a dict called <dict_name> is available in this backend. 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

222 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

223 raise NotImplementedError() 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

224 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

225 def __getitem__(self, dict_name): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

226 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

227 Get a dict by its moin dict name. 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

228 """ 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

229 raise NotImplementedError() 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

230 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

231 def _retrieve_members(self, dict_name): 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

232 raise NotImplementedError() 
f83b7b0b59c4
Groups2009: groups and dicts were merged inside of the datastruct module.
Dmitrijs Milajevs <dimazest@gmail.com>
parents:
4830
diff
changeset

233 