Package buildbot :: Package util :: Module bbcollections
[frames] | no frames]

Source Code for Module buildbot.util.bbcollections

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  # this is here for compatibility 
17  from collections import defaultdict 
18  assert defaultdict 
19   
20 -class KeyedSets:
21 - def __init__(self):
22 self.d = dict()
23 - def add(self, key, value):
24 if key not in self.d: 25 self.d[key] = set() 26 self.d[key].add(value)
27 - def discard(self, key, value):
28 if key in self.d: 29 self.d[key].discard(value) 30 if not self.d[key]: 31 del self.d[key]
32 - def __contains__(self, key):
33 return key in self.d
34 - def __getitem__(self, key):
35 return self.d.get(key, set())
36 - def pop(self, key):
37 if key in self.d: 38 return self.d.pop(key) 39 return set()
40