diff options
Diffstat (limited to 'Lib/shelve.py')
-rw-r--r-- | Lib/shelve.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/shelve.py b/Lib/shelve.py index d651b9e..c8d9cf5 100644 --- a/Lib/shelve.py +++ b/Lib/shelve.py @@ -64,6 +64,16 @@ import warnings __all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"] +class _ClosedDict(collections.MutableMapping): + 'Marker for a closed dict. Access attempts raise a ValueError.' + + def closed(self, *args): + raise ValueError('invalid operation on closed shelf') + __iter__ = __len__ = __getitem__ = __setitem__ = __delitem__ = keys = closed + + def __repr__(self): + return '<Closed Dictionary>' + class Shelf(collections.MutableMapping): """Base class for shelf implementations. @@ -127,7 +137,7 @@ class Shelf(collections.MutableMapping): self.dict.close() except AttributeError: pass - self.dict = 0 + self.dict = _ClosedDict() def __del__(self): if not hasattr(self, 'writeback'): |