Correction crash
[auf_roundup.git] / build / lib / roundup / cgi / PageTemplates / MultiMapping.py
CommitLineData
c638d827
CR
1import operator
2
3class MultiMapping:
4 def __init__(self, *stores):
5 self.stores = list(stores)
6 def __getitem__(self, key):
7 for store in self.stores:
8 if store.has_key(key):
9 return store[key]
10 raise KeyError, key
11 _marker = []
12 def get(self, key, default=_marker):
13 for store in self.stores:
14 if store.has_key(key):
15 return store[key]
16 if default is self._marker:
17 raise KeyError, key
18 return default
19 def __len__(self):
20 return reduce(operator.add, [len(x) for x in self.stores], 0)
21 def push(self, store):
22 self.stores.append(store)
23 def pop(self):
24 return self.stores.pop()
25 def items(self):
26 l = []
27 for store in self.stores:
28 l = l + store.items()
29 return l