changeset 4816:7d8f51be2285

Groups2009: GroupDoesNotExistError is raised instead of KeyError when a group name is not found in the backend.
author Dmitrijs Milajevs <dimazest@gmail.com>
date Wed, 24 Jun 2009 17:56:46 +0200
parents d761238f67f9
children 9a305dadab7a
files MoinMoin/groups/__init__.py MoinMoin/groups/backends/__init__.py MoinMoin/groups/backends/_tests/__init__.py MoinMoin/groups/backends/_tests/test_composite_groups.py MoinMoin/groups/backends/composite_groups.py MoinMoin/groups/backends/config_groups.py MoinMoin/groups/backends/wiki_groups.py
diffstat 7 files changed, 20 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/groups/__init__.py	Wed Jun 24 15:26:05 2009 +0200
+++ b/MoinMoin/groups/__init__.py	Wed Jun 24 17:56:46 2009 +0200
@@ -9,4 +9,5 @@
 from MoinMoin.groups.backends.wiki_groups import WikiGroups
 from MoinMoin.groups.backends.config_groups import ConfigGroups
 from MoinMoin.groups.backends.composite_groups import CompositeGroups
+from MoinMoin.groups.backends import GroupDoesNotExistError
 
--- a/MoinMoin/groups/backends/__init__.py	Wed Jun 24 15:26:05 2009 +0200
+++ b/MoinMoin/groups/backends/__init__.py	Wed Jun 24 17:56:46 2009 +0200
@@ -6,6 +6,11 @@
 @license: GPL, see COPYING for details
 """
 
+class GroupDoesNotExistError(Exception):
+    """
+    Raised when a group name is not found in the backend.
+    """
+    pass
 
 class BaseGroup(object):
 
@@ -147,6 +152,6 @@
             try:
                 if member in self[group_name]:
                     yield group_name
-            except KeyError:
+            except GroupDoesNotExistError:
                 pass
 
--- a/MoinMoin/groups/backends/_tests/__init__.py	Wed Jun 24 15:26:05 2009 +0200
+++ b/MoinMoin/groups/backends/_tests/__init__.py	Wed Jun 24 17:56:46 2009 +0200
@@ -13,6 +13,7 @@
 from py.test import raises
 
 from MoinMoin import security
+from MoinMoin.groups import GroupDoesNotExistError
 
 
 class BackendTest(object):
@@ -46,7 +47,7 @@
             for member in members:
                 assert member in groups[group]
 
-        raises(KeyError, lambda: groups[u'NotExistingGroup'])
+        raises(GroupDoesNotExistError, lambda: groups[u'NotExistingGroup'])
 
     def test_iter(self):
         groups = self.request.groups
--- a/MoinMoin/groups/backends/_tests/test_composite_groups.py	Wed Jun 24 15:26:05 2009 +0200
+++ b/MoinMoin/groups/backends/_tests/test_composite_groups.py	Wed Jun 24 17:56:46 2009 +0200
@@ -11,7 +11,7 @@
 from py.test import raises
 
 from  MoinMoin.groups.backends._tests import BackendTest
-from MoinMoin.groups import ConfigGroups, CompositeGroups
+from MoinMoin.groups import ConfigGroups, CompositeGroups, GroupDoesNotExistError
 from MoinMoin._tests import wikiconfig
 from MoinMoin import security
 
@@ -59,7 +59,7 @@
         self.groups = self.request.groups
 
     def test_getitem(self):
-        raises(KeyError, lambda: self.groups[u'NotExistingGroup'])
+        raises(GroupDoesNotExistError, lambda: self.groups[u'NotExistingGroup'])
 
     def test_clashed_getitem(self):
         """
--- a/MoinMoin/groups/backends/composite_groups.py	Wed Jun 24 15:26:05 2009 +0200
+++ b/MoinMoin/groups/backends/composite_groups.py	Wed Jun 24 17:56:46 2009 +0200
@@ -6,7 +6,7 @@
 @license: GPL, see COPYING for details
 """
 
-from MoinMoin.groups.backends import BaseBackend
+from MoinMoin.groups.backends import BaseBackend, GroupDoesNotExistError
 
 
 class CompositeGroups(BaseBackend):
@@ -31,7 +31,7 @@
         for backend in self._backends:
             if group_name in backend:
                 return backend[group_name]
-        raise KeyError("There is no such group %s" % group_name)
+        raise GroupDoesNotExistError(group_name)
 
     def __iter__(self):
         """
--- a/MoinMoin/groups/backends/config_groups.py	Wed Jun 24 15:26:05 2009 +0200
+++ b/MoinMoin/groups/backends/config_groups.py	Wed Jun 24 17:56:46 2009 +0200
@@ -8,7 +8,7 @@
 @license: GPL, see COPYING for details
 """
 
-from MoinMoin.groups.backends import BaseGroup, BaseBackend
+from MoinMoin.groups.backends import BaseGroup, BaseBackend, GroupDoesNotExistError
 
 
 class Group(BaseGroup):
@@ -33,7 +33,10 @@
         return self._groups.iterkeys()
 
     def __getitem__(self, group_name):
-        return Group(request=self.request, name=group_name, backend=self)
+        try:
+            return Group(request=self.request, name=group_name, backend=self)
+        except KeyError:
+            raise GroupDoesNotExistError(group_name)
 
     def _retrieve_members(self, group_name):
         return self._groups[group_name]
--- a/MoinMoin/groups/backends/wiki_groups.py	Wed Jun 24 15:26:05 2009 +0200
+++ b/MoinMoin/groups/backends/wiki_groups.py	Wed Jun 24 17:56:46 2009 +0200
@@ -17,7 +17,7 @@
 
 from MoinMoin import caching, wikiutil
 from MoinMoin.Page import Page
-from MoinMoin.groups.backends import BaseGroup, BaseBackend
+from MoinMoin.groups.backends import BaseGroup, BaseBackend, GroupDoesNotExistError
 
 
 class Group(BaseGroup):
@@ -46,7 +46,7 @@
                 cache.update((members, member_groups))
                 return members, member_groups
         else:
-            raise KeyError("There is no such group page %s" % group_name)
+            raise GroupDoesNotExistError(group_name)
 
 
 class WikiGroups(BaseBackend):