mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Issue 1592: Better error reporting for operations on closed shelves.
This commit is contained in:
parent
4982d5d04a
commit
8c664e8628
3 changed files with 29 additions and 1 deletions
|
@ -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'):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue