Throw an exception when registering an already registered right
authorSverre Rabbelier <srabbelier@gmail.com>
Fri, 18 Sep 2009 22:08:50 +0200
changeset 2962 05014496b8f9
parent 2961 34c6737e77a0
child 2963 e03e203130a6
Throw an exception when registering an already registered right
app/soc/modules/core.py
--- a/app/soc/modules/core.py	Fri Sep 18 21:50:54 2009 +0200
+++ b/app/soc/modules/core.py	Fri Sep 18 22:08:50 2009 +0200
@@ -93,6 +93,20 @@
     super(NonUniqueService, self).__init__(msg)
 
 
+class AlreadyRegisteredRight(Error):
+  """Error raised when a right is registrated a second time
+  """
+
+  ALREADY_REGISTERED_RIGHT_FMT = "Tried to register right '%s' a second time."
+
+  def __init__(self, right):
+    """Instantiates a new exception with a customized message.
+    """
+
+    msg = self.ALREADY_REGISTERED_RIGHT_FMT % right
+    super(AlreadyRegisteredRight, self).__init__(msg)
+
+
 class Core(object):
   """The core handler that controls the Melange API.
   """
@@ -327,4 +341,7 @@
     """Registers the specified right.
     """
 
+    if key in self.rights:
+      raise AlreadyRegisteredRight(key)
+
     self.rights[key] = value