removed sqlite addrs.dat, replacing it with a text file per network. should be much...
[p2pool.git] / p2pool / util / dicts.py
1 def update_dict(d, **replace):
2     d = d.copy()
3     for k, v in replace.iteritems():
4         if v is None:
5             del d[k]
6         else:
7             d[k] = v
8     return d
9
10 class frozendict(dict):
11     __slots__ = ['_hash']
12     
13     def __hash__(self):
14         rval = getattr(self, '_hash', None)
15         if rval is None:
16             rval = self._hash = hash(frozenset(self.iteritems()))
17         return rval
18
19 class frozenlist(list):
20     __slots__ = ['_hash']
21     
22     def __hash__(self):
23         rval = getattr(self, '_hash', None)
24         if rval is None:
25             rval = self._hash = hash(tuple(self))
26         return rval
27
28 def immutify(x):
29     if isinstance(x, list):
30         return frozenlist(immutify(y) for y in x)
31     elif isinstance(x, dict):
32         return frozendict((immutify(k), immutify(v)) for k, v in x.iteritems())
33     else:
34         hash(x) # will throw error if not immutable
35         return x