1
from shelve import Shelf
6
class DbfilenameShelf(Shelf):
7
"""Shelf implementation using the "anydbm" generic dbm interface.
9
This is initialized with the filename for the dbm database.
10
See the module's __doc__ string for an overview of the interface.
13
def __init__(self, filename, flag='c'):
14
Shelf.__init__(self, dumbdbm_patched.open(filename, flag))
16
def __getitem__(self, key):
17
compressed = self.dict[key]
19
r = zlib.decompress(compressed)
22
return cPickle.loads(r)
24
def __setitem__(self, key, value):
25
s = cPickle.dumps(value,1)
26
self.dict[key] = zlib.compress(s)
28
def open(filename, flag='c'):
29
"""Open a persistent dictionary for reading and writing.
31
Argument is the filename for the dbm database.
32
See the module's __doc__ string for an overview of the interface.
35
return DbfilenameShelf(filename, flag)