mirror of
https://github.com/python/cpython.git
synced 2025-12-10 11:00:14 +00:00
#6045: provide at least get() and setdefault() for all dbm modules.
This commit is contained in:
parent
da72231c9f
commit
d9e833c70a
5 changed files with 63 additions and 5 deletions
|
|
@ -203,7 +203,7 @@ class _Database(collections.MutableMapping):
|
|||
# The blocks used by the associated value are lost.
|
||||
del self._index[key]
|
||||
# XXX It's unclear why we do a _commit() here (the code always
|
||||
# XXX has, so I'm not changing it). _setitem__ doesn't try to
|
||||
# XXX has, so I'm not changing it). __setitem__ doesn't try to
|
||||
# XXX keep the directory file in synch. Why should we? Or
|
||||
# XXX why shouldn't __setitem__?
|
||||
self._commit()
|
||||
|
|
@ -232,7 +232,7 @@ class _Database(collections.MutableMapping):
|
|||
|
||||
__del__ = close
|
||||
|
||||
def _chmod (self, file):
|
||||
def _chmod(self, file):
|
||||
if hasattr(self._os, 'chmod'):
|
||||
self._os.chmod(file, self._mode)
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ class TestGdbm(unittest.TestCase):
|
|||
key_set.remove(key)
|
||||
key = self.g.nextkey(key)
|
||||
self.assertRaises(KeyError, lambda: self.g['xxx'])
|
||||
# get() and setdefault() work as in the dict interface
|
||||
self.assertEqual(self.g.get(b'xxx', b'foo'), b'foo')
|
||||
self.assertEqual(self.g.setdefault(b'xxx', b'foo'), b'foo')
|
||||
self.assertEqual(self.g[b'xxx'], b'foo')
|
||||
|
||||
def test_error_conditions(self):
|
||||
# Try to open a non-existent database.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue