summaryrefslogtreecommitdiff
path: root/Lib/dbm
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-11-17 15:59:51 +1000
committerNick Coghlan <ncoghlan@gmail.com>2013-11-17 15:59:51 +1000
commitfdbc1773f23f2ab6b422a12496d7e82f17b16ee8 (patch)
tree30bce3b706ee8d1ac440856ad37ef1f12bf8ea6e /Lib/dbm
parent6b4336e84f67986d4bbc5b8e7c5ba5e97fd12eb5 (diff)
downloadcpython-fdbc1773f23f2ab6b422a12496d7e82f17b16ee8.tar.gz
Close #19282: Native context management in dbm
Diffstat (limited to 'Lib/dbm')
-rw-r--r--Lib/dbm/dumb.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/dbm/dumb.py b/Lib/dbm/dumb.py
index 9ac7852978..ba6a20d0c9 100644
--- a/Lib/dbm/dumb.py
+++ b/Lib/dbm/dumb.py
@@ -236,6 +236,12 @@ class _Database(collections.MutableMapping):
if hasattr(self._os, 'chmod'):
self._os.chmod(file, self._mode)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, *args):
+ self.close()
+
def open(file, flag=None, mode=0o666):
"""Open the database file, filename, and return corresponding object.