changeset 24:eab8af30dfc7

get_free_slot no raises an exception instead of appending a slot to the container.
author KarstenBock@gmx.net
date Fri, 02 Sep 2011 12:54:43 +0200
parents 979fffc5af49
children d13924109572
files components/container.py
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/components/container.py	Fri Sep 02 12:29:55 2011 +0200
+++ b/components/container.py	Fri Sep 02 12:54:43 2011 +0200
@@ -32,7 +32,13 @@
     
     def __str__(self):
         return "Item would exceed the bulk limit of the container."
-        
+
+class NoFreeSlotError(Exception):
+    """Error that gets raised when the container has no free slots."""
+  
+    def __str__(self):
+        return "Container can't hold any more items."
+    
 def get_free_slot(container):
     """Returns the first slot of the container that is not occupied."""
     index = 0
@@ -40,8 +46,7 @@
         if not child:
             return index
         index += 1
-    container.children.append(None)
-    return index
+    raise NoFreeSlotError
 
 def get_total_bulk(container):
     """Returns the bulk of all items in the container."""