diff options
author | Raymond Hettinger <python@rcn.com> | 2008-07-25 18:43:33 +0000 |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-07-25 18:43:33 +0000 |
commit | 8c664e8628ace6a9f3b64980af262b67cd7f3e59 (patch) | |
tree | a020e103bacd0b2b9cc9f464f73454e23655abb8 /Lib/shelve.py | |
parent | 4982d5d04acff706cd43c77e757c0121a14a0c8d (diff) | |
download | cpython-git-8c664e8628ace6a9f3b64980af262b67cd7f3e59.tar.gz |
Issue 1592: Better error reporting for operations on closed shelves.
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 7a75445b0b..2a430f374b 100644 --- a/Lib/shelve.py +++ b/Lib/shelve.py @@ -73,6 +73,16 @@ import warnings __all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"] +class _ClosedDict(UserDict.DictMixin): + 'Marker for a closed dict. Access attempts raise a ValueError.' + + def closed(self, *args): + raise ValueError('invalid operation on closed shelf') + __getitem__ = __setitem__ = __delitem__ = keys = closed + + def __repr__(self): + return '<Closed Dictionary>' + class Shelf(UserDict.DictMixin): """Base class for shelf implementations. @@ -136,7 +146,7 @@ class Shelf(UserDict.DictMixin): self.dict.close() except AttributeError: pass - self.dict = 0 + self.dict = _ClosedDict() def __del__(self): if not hasattr(self, 'writeback'): |