utils.py
branchstable
changeset 7568 c5ee33fb6a3b
parent 7268 cd14e03124be
child 7569 02c338197322
equal deleted inserted replaced
7567:d6366de1d0dc 7568:c5ee33fb6a3b
   128         for subchild in transitive_closure_of(child, rtype, _seen):
   128         for subchild in transitive_closure_of(child, rtype, _seen):
   129             yield subchild
   129             yield subchild
   130 
   130 
   131 
   131 
   132 class SizeConstrainedList(list):
   132 class SizeConstrainedList(list):
   133     """simple list that makes sure the list does not get bigger
   133     """simple list that makes sure the list does not get bigger than a given
   134     than a given size.
   134     size.
   135 
   135 
   136     when the list is full and a new element is added, the first
   136     when the list is full and a new element is added, the first element of the
   137     element of the list is removed before appending the new one
   137     list is removed before appending the new one
   138 
   138 
   139     >>> l = SizeConstrainedList(2)
   139     >>> l = SizeConstrainedList(2)
   140     >>> l.append(1)
   140     >>> l.append(1)
   141     >>> l.append(2)
   141     >>> l.append(2)
   142     >>> l
   142     >>> l
   143     [1, 2]
   143     [1, 2]
   144     >>> l.append(3)
   144     >>> l.append(3)
       
   145     >>> l
   145     [2, 3]
   146     [2, 3]
   146     """
   147     """
   147     def __init__(self, maxsize):
   148     def __init__(self, maxsize):
   148         self.maxsize = maxsize
   149         self.maxsize = maxsize
   149 
   150