Project

General

Profile

« Previous | Next » 

Revision 6412

dicts.py: Added WrapDict, a dict that runs a function on each value retrieved

View differences:

lib/dicts.py
20 20
    
21 21
    def __delitem__(self, key): del self.inner[key]
22 22

  
23
class WrapDict(DictProxy):
24
    '''A dict that runs a function on each value retrieved.'''
25
    
26
    def __init__(self, wrap_func, inner=None):
27
        DictProxy.__init__(self, inner)
28
        
29
        self.wrap_func = wrap_func
30
    
31
    def __getitem__(self, key):
32
        return self.wrap_func(DictProxy.__getitem__(self, key))
33

  
23 34
class KeyExistsError(KeyError):
24 35
    def __init__(self, key):
25 36
        KeyError.__init__(self, key)

Also available in: Unified diff