Mercurial > cpython-lru_cache-weakref
annotate Mac/Lib/dbmac.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 246d5422124f |
| children |
| rev | line source |
|---|---|
|
2100
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 """A slow but simple dbm clone for the Mac. |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 For database spam, spam.dir contains the index (a text file), |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 spam.bak *may* contain a backup of the index (also a text file), |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 while spam.dat contains the data (a binary file). |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 XXX TO DO: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 - reclaim free space (currently, space once occupied by deleted or expanded |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 items is never reused) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 - support concurrent access (currently, if two processes take turns making |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 updates, they can mess up the index) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 - support efficient access to large databases (currently, the whole index |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 is read when the database is opened, and some updates rewrite the whole index) |
|
3070
246d5422124f
add (dummy) mode arg to open()
Guido van Rossum <guido@python.org>
parents:
2666
diff
changeset
|
17 |
|
246d5422124f
add (dummy) mode arg to open()
Guido van Rossum <guido@python.org>
parents:
2666
diff
changeset
|
18 - support opening for read-only (flag = 'm') |
|
246d5422124f
add (dummy) mode arg to open()
Guido van Rossum <guido@python.org>
parents:
2666
diff
changeset
|
19 |
|
2100
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 """ |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 _os = __import__('os') |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 import __builtin__ |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 _open = __builtin__.open |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 _BLOCKSIZE = 512 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 class _Database: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 def __init__(self, file): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 self._dirfile = file + '.dir' |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 self._datfile = file + '.dat' |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 self._bakfile = file + '.bak' |
|
2666
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
35 # Mod by Jack: create data file if needed |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
36 try: |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
37 f = _open(self._datfile, 'r') |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
38 except IOError: |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
39 f = _open(self._datfile, 'w') |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
40 f.close() |
|
2100
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 self._update() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 def _update(self): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 self._index = {} |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 try: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 f = _open(self._dirfile) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 except IOError: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 pass |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 else: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 while 1: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 line = f.readline() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 if not line: break |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 key, (pos, siz) = eval(line) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 self._index[key] = (pos, siz) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 f.close() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 def _commit(self): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 try: _os.unlink(self._bakfile) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 except _os.error: pass |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 try: _os.rename(self._dirfile, self._bakfile) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 except _os.error: pass |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 f = _open(self._dirfile, 'w') |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 for key, (pos, siz) in self._index.items(): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 f.write("%s, (%s, %s)\n" % (`key`, `pos`, `siz`)) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 f.close() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 def __getitem__(self, key): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 pos, siz = self._index[key] # may raise KeyError |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 f = _open(self._datfile, 'rb') |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 f.seek(pos) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 dat = f.read(siz) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 f.close() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 return dat |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 def _addval(self, val): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 f = _open(self._datfile, 'rb+') |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 f.seek(0, 2) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 pos = f.tell() |
|
2666
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
79 ## Does not work under MW compiler |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
80 ## pos = ((pos + _BLOCKSIZE - 1) / _BLOCKSIZE) * _BLOCKSIZE |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
81 ## f.seek(pos) |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
82 npos = ((pos + _BLOCKSIZE - 1) / _BLOCKSIZE) * _BLOCKSIZE |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
83 f.write('\0'*(npos-pos)) |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
84 pos = npos |
|
49183938d07e
Removed seeks beyond eof (MW doesn't support them)
Jack Jansen <jack.jansen@cwi.nl>
parents:
2100
diff
changeset
|
85 |
|
2100
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 f.write(val) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 f.close() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 return (pos, len(val)) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 def _setval(self, pos, val): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 f = _open(self._datfile, 'rb+') |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 f.seek(pos) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 f.write(val) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 f.close() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 return pos, (val) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 def _addkey(self, key, (pos, siz)): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 self._index[key] = (pos, siz) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 f = _open(self._dirfile, 'a') |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 f.write("%s, (%s, %s)\n" % (`key`, `pos`, `siz`)) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 f.close() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 def __setitem__(self, key, val): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 if not type(key) == type('') == type(val): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 raise TypeError, "dbmac keys and values must be strings" |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 if not self._index.has_key(key): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 (pos, siz) = self._addval(val) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 self._addkey(key, (pos, siz)) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 else: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 pos, siz = self._index[key] |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 oldblocks = (siz + _BLOCKSIZE - 1) / _BLOCKSIZE |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 newblocks = (len(val) + _BLOCKSIZE - 1) / _BLOCKSIZE |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 if newblocks <= oldblocks: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 pos, siz = self._setval(pos, val) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 self._index[key] = pos, siz |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 else: |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 pos, siz = self._addval(val) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 self._index[key] = pos, siz |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 self._addkey(key, (pos, siz)) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 def __delitem__(self, key): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 del self._index[key] |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 self._commit() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 def keys(self): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 return self._index.keys() |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 def has_key(self, key): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 return self._index.has_key(key) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 def __len__(self): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 return len(self._index) |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 def close(self): |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 self._index = self._datfile = self._dirfile = self._bakfile = None |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 |
|
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 |
|
3070
246d5422124f
add (dummy) mode arg to open()
Guido van Rossum <guido@python.org>
parents:
2666
diff
changeset
|
138 def open(file, flag = None, mode = None): |
|
246d5422124f
add (dummy) mode arg to open()
Guido van Rossum <guido@python.org>
parents:
2666
diff
changeset
|
139 # flag, mode arguments are currently ignored |
|
2100
4574ed657cc9
shelve.py: database of persistent objects, on top of pickle.py and anydbm.py
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 return _Database(file) |
