From c610aba1ed57a30104a254ccd1f9fe07d02b1334 Mon Sep 17 00:00:00 2001 From: Nick Coghlan Date: Sun, 17 Nov 2013 15:59:51 +1000 Subject: Close #19282: Native context management in dbm --- Lib/dbm/dumb.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Lib/dbm/dumb.py') 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. -- cgit v1.2.1