From: richard Date: Tue, 30 Mar 2004 06:35:33 +0000 (+0000) Subject: fixed MultiMapping X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=babfb79ad5d6592346c12b601b156db449cc5a22;p=roundup.git fixed MultiMapping git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2232 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/CHANGES.txt b/CHANGES.txt index fed41ae..2d5748c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,8 @@ are given with the most recent entry first. 2004-??-?? 0.7.0 Fixed: - CSV export was busted +- MultiMapping deviated from the Zope C implementation in a number of + places (thanks Toby Sargeant) 2004-03-27 0.7.0b2 diff --git a/doc/index.txt b/doc/index.txt index 3095509..0860ac5 100644 --- a/doc/index.txt +++ b/doc/index.txt @@ -105,6 +105,7 @@ Bernhard Reiter, Roy Rapoport, John P. Rouillard, Ollie Rutherfurd, +Toby Sargeant, Florian Schulze, Dougal Scott, Stefan Seefeld, diff --git a/roundup/cgi/MultiMapping.py b/roundup/cgi/MultiMapping.py index b528288..583e2d7 100644 --- a/roundup/cgi/MultiMapping.py +++ b/roundup/cgi/MultiMapping.py @@ -1,14 +1,19 @@ -import operator - class MultiMapping: def __init__(self, *stores): self.stores = list(stores) + self.stores.reverse() + def __getitem__(self, key): for store in self.stores: if store.has_key(key): return store[key] raise KeyError, key + + def __setitem__(self, key, val): + self.stores[0][key] = val + _marker = [] + def get(self, key, default=_marker): for store in self.stores: if store.has_key(key): @@ -16,10 +21,43 @@ class MultiMapping: if default is self._marker: raise KeyError, key return default + def __len__(self): - return reduce(operator.add, [len(x) for x in stores], 0) + return len(self.items()) + + def has_key(self, key): + for store in self.stores: + if store.has_key(key): + return 1 + return 0 + def push(self, store): - self.stores.append(store) + self.stores = [store] + self.stores + def pop(self): - return self.stores.pop() + if not len(self.stores): + return None + store, self.stores = self.stores[0], self.stores[1:] + return store + + def keys(self): + return [ _[0] for _ in self.items() ] + + def values(self): + return [ _[1] for _ in self.items() ] + + def copy(self): + copy = MultiMapping() + copy.stores = [_.copy() for _ in self.stores] + return copy + + def items(self): + l = [] + seen = {} + for store in self.stores: + for k, v in store.items(): + if not seen.has_key(k): + l.append((k, v)) + seen[k] = 1 + return l