OLD | NEW |
1 """A dumb and slow but simple dbm clone. | 1 """A dumb and slow but simple dbm clone. |
2 | 2 |
3 For database spam, spam.dir contains the index (a text file), | 3 For database spam, spam.dir contains the index (a text file), |
4 spam.bak *may* contain a backup of the index (also a text file), | 4 spam.bak *may* contain a backup of the index (also a text file), |
5 while spam.dat contains the data (a binary file). | 5 while spam.dat contains the data (a binary file). |
6 | 6 |
7 XXX TO DO: | 7 XXX TO DO: |
8 | 8 |
9 - seems to contain a bug when updating... | 9 - seems to contain a bug when updating... |
10 | 10 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 if isinstance(key, str): | 201 if isinstance(key, str): |
202 key = key.encode('utf-8') | 202 key = key.encode('utf-8') |
203 # The blocks used by the associated value are lost. | 203 # The blocks used by the associated value are lost. |
204 del self._index[key] | 204 del self._index[key] |
205 # XXX It's unclear why we do a _commit() here (the code always | 205 # XXX It's unclear why we do a _commit() here (the code always |
206 # XXX has, so I'm not changing it). __setitem__ doesn't try to | 206 # XXX has, so I'm not changing it). __setitem__ doesn't try to |
207 # XXX keep the directory file in synch. Why should we? Or | 207 # XXX keep the directory file in synch. Why should we? Or |
208 # XXX why shouldn't __setitem__? | 208 # XXX why shouldn't __setitem__? |
209 self._commit() | 209 self._commit() |
210 | 210 |
211 def keys(self): | |
212 return list(self._index.keys()) | |
213 | |
214 def items(self): | |
215 return [(key, self[key]) for key in self._index.keys()] | |
216 | |
217 def __contains__(self, key): | 211 def __contains__(self, key): |
218 if isinstance(key, str): | 212 if isinstance(key, str): |
219 key = key.encode('utf-8') | 213 key = key.encode('utf-8') |
220 return key in self._index | 214 return key in self._index |
221 | 215 |
222 def iterkeys(self): | 216 def iterkeys(self): |
223 return iter(self._index.keys()) | 217 return iter(self._index.keys()) |
224 __iter__ = iterkeys | 218 __iter__ = iterkeys |
225 | 219 |
226 def __len__(self): | 220 def __len__(self): |
(...skipping 29 matching lines...) Expand all Loading... |
256 try: | 250 try: |
257 um = _os.umask(0) | 251 um = _os.umask(0) |
258 _os.umask(um) | 252 _os.umask(um) |
259 except AttributeError: | 253 except AttributeError: |
260 pass | 254 pass |
261 else: | 255 else: |
262 # Turn off any bits that are set in the umask | 256 # Turn off any bits that are set in the umask |
263 mode = mode & (~um) | 257 mode = mode & (~um) |
264 | 258 |
265 return _Database(file, mode) | 259 return _Database(file, mode) |
OLD | NEW |