Revision 2651
Added by Aaron Marcuse-Kubitza over 12 years ago
dicts.py | ||
---|---|---|
1 | 1 |
# Dictionaries |
2 | 2 |
|
3 | 3 |
import itertools |
4 |
import UserDict |
|
4 | 5 |
|
5 | 6 |
import util |
6 | 7 |
|
7 | 8 |
def is_dict(value): return hasattr(value, '__getitem__') |
8 | 9 |
|
10 |
class DictProxy(UserDict.DictMixin): |
|
11 |
'''A proxy that forwards all accesses to an inner dict.''' |
|
12 |
|
|
13 |
def __init__(self, inner): self.inner = inner |
|
14 |
|
|
15 |
def keys(self): return self.inner.keys() |
|
16 |
|
|
17 |
def __getitem__(self, key): return self.inner[key] |
|
18 |
|
|
19 |
def __setitem__(self, key, value): self.inner[key] = value |
|
20 |
|
|
9 | 21 |
class IdDict(dict): |
10 | 22 |
'''A dict that stores objects by id()''' |
11 | 23 |
|
Also available in: Unified diff
dicts.py: Added DictProxy