Revision 2817
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/dicts.py | ||
---|---|---|
3 | 3 |
import itertools |
4 | 4 |
import UserDict |
5 | 5 |
|
6 |
import util |
|
7 |
|
|
8 | 6 |
def is_dict(value): return hasattr(value, 'keys') |
9 | 7 |
|
10 | 8 |
class DictProxy(UserDict.DictMixin): |
... | ... | |
52 | 50 |
except KeyError: pass |
53 | 51 |
raise # reraise last KeyError |
54 | 52 |
|
55 |
|
|
56 | 53 |
class AttrsDictView: |
57 | 54 |
'''A dict view of an object's attributes |
58 | 55 |
@pre If you want __iter__() to work, value must have a __dict__ |
... | ... | |
64 | 61 |
|
65 | 62 |
def __getitem__(self, key): return getattr(self.value, key) |
66 | 63 |
|
64 |
import util |
|
65 |
|
|
67 | 66 |
def make_hashable(value): |
68 | 67 |
if isinstance(value, list): value = tuple(value) |
69 | 68 |
elif isinstance(value, dict): value = util.NamedTuple(**value) |
Also available in: Unified diff
dicts.py: Import util after items that util depends on have been defined, to avoid unsatisfied circular dependency