"Fossies" - the Fresh Open Source Software Archive

Member "roundup-2.0.0/roundup/cgi/PageTemplates/MultiMapping.py" (26 Aug 2019, 821 Bytes) of package /linux/www/roundup-2.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "MultiMapping.py": 1.6.1_vs_2.0.0.

    1 import operator
    2 
    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 key in store:
    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 key in store:
   15                 return store[key]
   16         if default is self._marker:
   17             raise KeyError(key)
   18         return default
   19     def __len__(self):
   20         return sum([len(x) for x in self.stores])
   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 + list(store.items())
   29         return l