My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'''
from http://code.activestate.com/recipes/414283/
'''


from lingospot.once import once

# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

def blocked( *a, **kw ):
raise AttributeError( 'A frozendict cannot be modified.' )

# -----------------------------------------------------------------------------

class frozendict( dict ):

def __hash__( s ):
return hash( s.sorted_items )

@once
def sorted_items( s ):
return tuple(
sorted(
s.iteritems()
)
)

# ------------------------------------

__delitem__ = blocked
__setitem__ = blocked
clear = blocked
pop = blocked
popitem = blocked
setdefault = blocked
update = blocked

# ------------------------------------

def __repr__( s ):
return "frozendict(%s)" % dict.__repr__( s )

Change log

r2 by stevewedig on Apr 29, 2011   Diff
first checkin
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 924 bytes, 42 lines
Powered by Google Project Hosting