1 import operator
3 class 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 stores], 0)
21 def push(self, store):
22 self.stores.append(store)
23 def pop(self):
24 return self.stores.pop()