Erno Kuusela added the comment:
How about the following patch. With it, you get an IOError.
>>> s = shelve.open('/tmp/t', 'c')
>>> s.has_key('foo')
0
>>> s.close()
>>> s.has_key('foo')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "shelve.py", line 107, in has_key
return self.dict.has_key(key)
File "shelve.py", line 94, in getdict
raise IOError, 'shelf has been closed'
IOError: shelf has been closed
Added file: http://bugs.python.org/file8930/shelve.diff
__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1592>
__________________________________
--- shelve.py.orig 2007-12-12 12:27:07.000000000 +0200
+++ shelve.py 2007-12-12 12:44:15.000000000 +0200
@@ -73,6 +73,7 @@
__all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"]
+
class Shelf(UserDict.DictMixin):
"""Base class for shelf implementations.
@@ -81,13 +82,21 @@
"""
def __init__(self, dict, protocol=None, writeback=False):
- self.dict = dict
+ self._dict = dict
if protocol is None:
protocol = 0
self._protocol = protocol
self.writeback = writeback
self.cache = {}
+ def getdict(self):
+ if self._dict is None:
+ raise IOError, 'shelf has been closed'
+ else:
+ return self._dict
+
+ dict = property(getdict)
+
def keys(self):
return self.dict.keys()
@@ -136,7 +145,8 @@
self.dict.close()
except AttributeError:
pass
- self.dict = 0
+
+ self._dict = None
def __del__(self):
if not hasattr(self, 'writeback'):
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com