Package gozerbot :: Module limlist
[hide private]
[frames] | no frames]

Source Code for Module gozerbot.limlist

 1  # gozerbot/limlist.py 
 2  # 
 3  # 
 4   
 5  """ limited list """ 
 6   
 7  __copyright__ = 'this file is in the public domain' 
 8   
9 -class Limlist(list):
10 11 """ list with limited number of items """ 12
13 - def __init__(self, limit):
14 self.limit = limit 15 list.__init__(self)
16
17 - def insert(self, index, item):
18 """ insert item at index .. pop oldest item if limit is reached """ 19 if index > len(self): 20 return -1 21 if len(self) >= self.limit: 22 self.pop(len(self)-1) 23 list.insert(self, index, item)
24
25 - def append(self, item):
26 """ add item to list .. pop oldest item if limit is reached """ 27 if len(self) >= self.limit: 28 self.pop(0) 29 list.append(self, item)
30