view roundup/cgi/PageTemplates/MultiMapping.py @ 5973:fe334430ca07

issue2550919 - Anti-bot signup using 4 second delay Took the code by erik forsberg and massaged it into the core. So this is no longer needed in the tracker. Updated devel and responsive trackers to remove timestamp.py and update input field name. Docs, changes and tests complete. Hopefully these tracker changes won't cause an issue for other tests.
author John Rouillard <rouilj@ieee.org>
date Sat, 09 Nov 2019 00:30:37 -0500
parents 23b8e6067f7c
children
line wrap: on
line source

import operator

class MultiMapping:
    def __init__(self, *stores):
        self.stores = list(stores)
    def __getitem__(self, key):
        for store in self.stores:
            if key in store:
                return store[key]
        raise KeyError(key)
    _marker = []
    def get(self, key, default=_marker):
        for store in self.stores:
            if key in store:
                return store[key]
        if default is self._marker:
            raise KeyError(key)
        return default
    def __len__(self):
        return sum([len(x) for x in self.stores])
    def push(self, store):
        self.stores.append(store)
    def pop(self):
        return self.stores.pop()
    def items(self):
        l = []
        for store in self.stores:
            l = l + list(store.items())
        return l

Roundup Issue Tracker: http://roundup-tracker.org/